diff --git a/.gitignore b/.gitignore index 99e4b84..279fa57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ -build \ No newline at end of file +build +vrc-discord-osc.config.json \ No newline at end of file diff --git a/README.md b/README.md index 71e4db0..f574a29 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ A python application for VRChat players to receive discord notifications on thei - [Installation](#installation) - [Contributing](#contributing) +- [Setting a different port number](#setting-a-different-port-number) - [Setting up your avatar](#setting-up-your-avatar) ## Installation @@ -57,7 +58,23 @@ Head over to the [Releases](https://github.com/uzair-ashraf/vrc-osc-discord-band This repository is setup with a Github action to compile the standalone executable. If you would like to compile it on your local machine you can read the action for the command via `pyinstaller` [here](./.github/workflows/release.yml). -### Setting up your avatar +## Setting a different port number + +--- + +In the same directory your executable is located in, create a file named `vrc-discord-osc.config.json` + +In the file add the following contents, and change `9000` to the port you'd like to send your OSC data to. + +```json +{ + "port": 9000 +} +``` + +If you did it properly the next time you run your application, the terminal window should state the port number you set. + +## Setting up your avatar --- diff --git a/config.py b/config.py new file mode 100644 index 0000000..2154437 --- /dev/null +++ b/config.py @@ -0,0 +1,19 @@ +import json + + +def get_port_number() -> int: + port = 9000 + try: + f = open('./vrc-discord-osc.config.json') + data = json.load(f) + f.close() + if ("port" in data): + if type(data['port']) is int: + print(f"Using port {data['port']}.") + port = data['port'] + except: + print("Config file not found...") + finally: + if port == 9000: + print("Defaulting to port 9000.") + return port diff --git a/discord_band.py b/discord_band.py index 94b0b07..f93e93d 100644 --- a/discord_band.py +++ b/discord_band.py @@ -6,8 +6,8 @@ class DiscordBand: - def __init__(self): - self.osc_client = SimpleUDPClient("127.0.0.1", 9000) + def __init__(self, port: int): + self.osc_client = SimpleUDPClient("127.0.0.1", port or 9000) self.is_enabled = False self.is_disposing = False self.disable_timer = 0 diff --git a/main.py b/main.py index ae3f380..774d3d6 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import asyncio +import config from discord_band import DiscordBand from windows import Windows from winsdk.windows.ui.notifications import UserNotification @@ -20,10 +21,11 @@ async def init(discord_band: DiscordBand, windows: Windows): windows.add_notification_listener(handler(discord_band)) await windows.run() - -discord_band = DiscordBand() +discord_band = None try: print("Starting VRC Discord Notifications...") + port = config.get_port_number() + discord_band = DiscordBand(port) windows = Windows() asyncio.run(init(discord_band, windows)) except KeyboardInterrupt: @@ -32,4 +34,5 @@ async def init(discord_band: DiscordBand, windows: Windows): print(e) input("Caught issue with Windows\n") finally: - discord_band.dispose() + if discord_band != None: + discord_band.dispose()