diff --git a/README.md b/README.md index 7857044..2acef0e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# Beta macos fix # Discord RPC Bridge for Wine ![GitHub License](https://img.shields.io/github/license/EnderIce2/rpc-bridge?style=for-the-badge) @@ -25,6 +26,8 @@ Logs are stored in `C:\windows\logs\bridge.log`. - ![gui](docs/assets/gui.png) - To remove, the same process can be followed, but click `Remove` instead. +*Note, an [extra step](https://github.com/EnderIce2/rpc-bridge?tab=readme-ov-file#macos) is needed on MacOS* + ##### Lutris - Click on a game and select `Run EXE inside Wine prefix`. @@ -50,9 +53,17 @@ Logs are stored in `C:\windows\logs\bridge.log`. - Globally - `flatpak override --user --filesystem=xdg-run/discord-ipc-0` -## macOS +##### MacOS -On macOS, follow [these instructions](https://enderice2.github.io/rpc-bridge/installation.html#macos). +The steps for MacOS are almost the same, but due to the way `$TMPDIR` works, you will have to install a **LaunchAgent**. + +- Download the latest build from the [releases](https://github.com/EnderIce2/rpc-bridge/releases) +- Open the archive and make the `launchd.sh` script executable by doing: `chmod +x launchd.sh` +- To **install** the LaunchAgent, run `./launchd install` and to **remove** it simply run `./launchd remove`. + +The script will add a LaunchAgent to your user, that will symlink the `$TMPDIR` directory to `/tmp/rpc-bridge/tmpdir`. + +*Note: You will need to launch the `bridge.exe` file manually in Wine atleast one time for it to register and launch automatically the next times.* ## Compiling from source diff --git a/bridge.c b/bridge.c index dc5ef84..21b8aca 100644 --- a/bridge.c +++ b/bridge.c @@ -250,22 +250,32 @@ char *native_getenv(const char *name) void ConnectToSocket(int fd) { print("Connecting to socket\n"); - const char *runtime; - if (IsLinux) - runtime = native_getenv("XDG_RUNTIME_DIR"); - else - runtime = native_getenv("TMPDIR"); - if (runtime == NULL) - { - print("IPC directory not set\n"); - if (!RunningAsService) - MessageBox(NULL, "IPC directory not set", - "Environment variable not set", - MB_OK | MB_ICONSTOP); - ExitProcess(1); - } + const char *runtime; + if (IsLinux) + runtime = native_getenv("XDG_RUNTIME_DIR"); + else + runtime = native_getenv("TMPDIR"); + if (runtime == NULL) + { + runtime = "/tmp/rpc-bridge/tmpdir"; + print("IPC directory not set, fallback to /tmp/rpc-bridge/tmpdir\n"); - print("IPC directory: %s\n", runtime); + // Check if the directory exists + DWORD dwAttrib = GetFileAttributes(runtime); + if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) + { + print("IPC directory does not exist: %s. If you're on MacOS, see the github guide on how to install the launchd service.\n", runtime); + // Handle the case where the directory doesn't exist + // For example, create the directory + if (!RunningAsService) + MessageBox(NULL, "IPC directory does not exist", + "Directory not found", + MB_OK | MB_ICONSTOP); + ExitProcess(1); + } + } + + print("IPC directory: %s\n", runtime); /* TODO: check for multiple discord instances and create a pipe for each */ const char *discordUnixPipes[] = { diff --git a/build/launchd.sh b/build/launchd.sh new file mode 100755 index 0000000..eeabea0 --- /dev/null +++ b/build/launchd.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# This script is used to create a LaunchAgent on MacOS, to support the service functionnality. +# Usage: ./launchd.sh (install|remove) + +SYMLINK=/tmp/rpc-bridge/tmpdir +LOCATION=~/Library/Application\ Support/rpc-bridge +SCRIPT=$LOCATION/rpc-bridge +AGENT=~/Library/LaunchAgents/com.enderice2.rpc-bridge.plist + +function install() { + # Directories + if [ ! -d "$SYMLINK" ]; then + mkdir -p "$SYMLINK" + fi + if [ ! -d "$LOCATION" ]; then + mkdir -p "$LOCATION" + fi + + # Link script + if [ -f "$SCRIPT" ]; then + rm -f "$SCRIPT" + fi + echo "#!/bin/bash +TARGET_DIR=/tmp/rpc-bridge/tmpdir +if [ ! -d "\$TARGET_DIR" ]; then + mkdir -p "\$TARGET_DIR" +fi +rm -rf "\$TARGET_DIR" + ln -s "\$TMPDIR" "\$TARGET_DIR"" > "$SCRIPT" + chmod +x "$SCRIPT" + + # LaunchAgent + if [ -f "$AGENT" ]; then + rm -f "$AGENT" + fi + echo " + + + + Label + com.enderice2.rpc-bridge + ProgramArguments + + $SCRIPT + + RunAtLoad + + +" > "$AGENT" + launchctl load "$AGENT" + echo "LaunchAgent has been installed." + +} + +function remove() { + rm -rf "$SYMLINK" + rm -rf "$LOCATION" + rm -f "$SCRIPT" + if [ -f "$AGENT" ]; then + launchctl unload "$AGENT" + fi + rm -f "$AGENT" + echo "LaunchAgent has been removed." +} + +# CLI +if [ $# -eq 0 ]; then + echo "Usage: $0 (install|remove)" + exit 1 +fi + +case $1 in + install) + install + ;; + remove) + remove + ;; + *) + echo "Invalid argument. Please use 'install' or 'remove'." + exit 1 + ;; +esac \ No newline at end of file diff --git a/gui.c b/gui.c index 837cdd0..aba7373 100644 --- a/gui.c +++ b/gui.c @@ -182,12 +182,12 @@ VOID SetButtonStyles(INT *btnStartStyle, INT *btnRemoveStyle, INT *btnInstallSty *btnRemoveStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; *btnInstallStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; - if (!IsLinux) - { - *btnInstallStyle |= WS_DISABLED; - *btnRemoveStyle |= WS_DISABLED; - return; - } + // if (!IsLinux) + // { + // *btnInstallStyle |= WS_DISABLED; + // *btnRemoveStyle |= WS_DISABLED; + // return; + // } SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); SC_HANDLE schService = OpenService(hSCManager, "rpc-bridge", SERVICE_START | SERVICE_QUERY_STATUS); diff --git a/service.c b/service.c index 6ba5edb..c38f7b6 100644 --- a/service.c +++ b/service.c @@ -88,13 +88,13 @@ void InstallService(int ServiceStartType, LPCSTR Path) { print("Registering service\n"); - if (IsLinux == FALSE) - { - /* FIXME: I don't know how to get the TMPDIR without getenv */ - MessageBox(NULL, "Registering as a service is not supported on macOS at the moment.", - "Unsupported", MB_OK | MB_ICONINFORMATION); - ExitProcess(1); - } + // if (IsLinux == FALSE) + // { + // /* FIXME: I don't know how to get the TMPDIR without getenv */ + // MessageBox(NULL, "Registering as a service is not supported on macOS at the moment.", + // "Unsupported", MB_OK | MB_ICONINFORMATION); + // ExitProcess(1); + // } SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (schSCManager == NULL)