From 8dd5952a64e3216166b8009ed252591ceea71df1 Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Tue, 21 May 2024 23:39:51 +0200
Subject: [PATCH 1/7] MacOS Fix
---
bridge.c | 40 +++++++++++++++++++++++++---------------
gui.c | 12 ++++++------
service.c | 14 +++++++-------
3 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/bridge.c b/bridge.c
index 56086da..cbcd818 100644
--- a/bridge.c
+++ b/bridge.c
@@ -248,22 +248,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\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/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)
From dcd9cf520e60b54473cc713fba810fce6c6b48cf Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Tue, 21 May 2024 23:46:19 +0200
Subject: [PATCH 2/7] Modified README and added warning in bridge.c
---
README.md | 3 +-
bridge.c | 2 +-
macos.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+), 2 deletions(-)
create mode 100644 macos.sh
diff --git a/README.md b/README.md
index 7857044..62f01e6 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,8 @@ Logs are stored in `C:\windows\logs\bridge.log`.
## macOS
-On macOS, follow [these instructions](https://enderice2.github.io/rpc-bridge/installation.html#macos).
+The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](macos.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`).
+To do so, download it, make it executable (`chmod +x macos.sh`) and run `./macos.sh install`. You can uninstall the agent by running `./macos.sh uninstall`.
## Compiling from source
diff --git a/bridge.c b/bridge.c
index cbcd818..07a5dbb 100644
--- a/bridge.c
+++ b/bridge.c
@@ -262,7 +262,7 @@ void ConnectToSocket(int fd)
DWORD dwAttrib = GetFileAttributes(runtime);
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
{
- print("IPC directory does not exist: %s\n", runtime);
+ 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)
diff --git a/macos.sh b/macos.sh
new file mode 100644
index 0000000..5748c9a
--- /dev/null
+++ b/macos.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+# Define target directory
+TARGET_DIR=/tmp/rpc-bridge/tmpdir
+P_DIR=$(dirname "$TARGET_DIR")
+FILE_PATH=$P_DIR/link
+
+# Function to create the symlink and launch agent
+function install_link() {
+
+ if [ ! -d "$P_DIR" ]; then
+ mkdir -p "$P_DIR"
+ fi
+
+ cat << EOF > "$FILE_PATH"
+#!/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"
+EOF
+
+ chmod +x "$FILE_PATH"
+
+ # Launch agent plist file path
+ PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist
+
+ # Create the launch agent plist with escaped variable
+ cat << EOF > "$PLIST_FILE"
+
+
+
+
+ Label
+ com.rpc-bridge.tmp-symlink
+ ProgramArguments
+
+ $FILE_PATH
+
+ RunAtLoad
+
+
+
+EOF
+
+ # Load the launch agent
+ launchctl load "$PLIST_FILE"
+ echo "Symlink created and launch agent installed."
+}
+
+# Function to remove the symlink and launch agent (unchanged)
+function remove_link() {
+ # Remove the symlink
+ rm -rf "$TARGET_DIR"
+
+ # Launch agent plist file path
+ PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist
+
+ # Unload the launch agent
+ launchctl unload "$PLIST_FILE"
+
+ # Remove the files
+ rm -f "$PLIST_FILE"
+ rm -f "$FILE_PATH"
+ echo "Symlink removed and launch agent uninstalled."
+}
+
+# Check for user input
+if [ $# -eq 0 ]; then
+ echo "Usage: $0 (install|remove)"
+ exit 1
+fi
+
+# Action based on user input
+case $1 in
+ install)
+ install_link
+ ;;
+ remove)
+ remove_link
+ ;;
+ *)
+ echo "Invalid argument. Please use 'install' or 'remove'."
+ exit 1
+ ;;
+esac
\ No newline at end of file
From 66f3bc53f1382e13d0e954fc8f9bf548121540f3 Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Tue, 21 May 2024 23:48:12 +0200
Subject: [PATCH 3/7] readme
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 62f01e6..5b4cea7 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+# Beta macos fix
# Discord RPC Bridge for Wine

From 14226489d71c9b89ffa5c9fa2ecf40499c7377fe Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Wed, 22 May 2024 16:41:15 +0200
Subject: [PATCH 4/7] Modified readme and script
---
README.md | 4 +--
build/launchd.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++
macos.sh | 88 ------------------------------------------------
3 files changed, 86 insertions(+), 90 deletions(-)
create mode 100755 build/launchd.sh
delete mode 100644 macos.sh
diff --git a/README.md b/README.md
index 5b4cea7..05fb0a6 100644
--- a/README.md
+++ b/README.md
@@ -53,8 +53,8 @@ Logs are stored in `C:\windows\logs\bridge.log`.
## macOS
-The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](macos.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`).
-To do so, download it, make it executable (`chmod +x macos.sh`) and run `./macos.sh install`. You can uninstall the agent by running `./macos.sh uninstall`.
+The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](build/launchd.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`).
+To do so, download it, make it executable (`chmod +x launchd.sh`) and run `./launchd.sh install`. You can uninstall the agent by running `./launchd.sh uninstall`.
## Compiling from source
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/macos.sh b/macos.sh
deleted file mode 100644
index 5748c9a..0000000
--- a/macos.sh
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/bash
-
-# Define target directory
-TARGET_DIR=/tmp/rpc-bridge/tmpdir
-P_DIR=$(dirname "$TARGET_DIR")
-FILE_PATH=$P_DIR/link
-
-# Function to create the symlink and launch agent
-function install_link() {
-
- if [ ! -d "$P_DIR" ]; then
- mkdir -p "$P_DIR"
- fi
-
- cat << EOF > "$FILE_PATH"
-#!/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"
-EOF
-
- chmod +x "$FILE_PATH"
-
- # Launch agent plist file path
- PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist
-
- # Create the launch agent plist with escaped variable
- cat << EOF > "$PLIST_FILE"
-
-
-
-
- Label
- com.rpc-bridge.tmp-symlink
- ProgramArguments
-
- $FILE_PATH
-
- RunAtLoad
-
-
-
-EOF
-
- # Load the launch agent
- launchctl load "$PLIST_FILE"
- echo "Symlink created and launch agent installed."
-}
-
-# Function to remove the symlink and launch agent (unchanged)
-function remove_link() {
- # Remove the symlink
- rm -rf "$TARGET_DIR"
-
- # Launch agent plist file path
- PLIST_FILE=~/Library/LaunchAgents/com.rpc-bridge.tmp-symlink.plist
-
- # Unload the launch agent
- launchctl unload "$PLIST_FILE"
-
- # Remove the files
- rm -f "$PLIST_FILE"
- rm -f "$FILE_PATH"
- echo "Symlink removed and launch agent uninstalled."
-}
-
-# Check for user input
-if [ $# -eq 0 ]; then
- echo "Usage: $0 (install|remove)"
- exit 1
-fi
-
-# Action based on user input
-case $1 in
- install)
- install_link
- ;;
- remove)
- remove_link
- ;;
- *)
- echo "Invalid argument. Please use 'install' or 'remove'."
- exit 1
- ;;
-esac
\ No newline at end of file
From 2fe1dd5ece55dc5e11f0672eaf94207da30fdab7 Mon Sep 17 00:00:00 2001
From: Origaming <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Mon, 27 May 2024 22:13:16 +0200
Subject: [PATCH 5/7] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 05fb0a6..6675982 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Logs are stored in `C:\windows\logs\bridge.log`.
## macOS
The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](build/launchd.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`).
-To do so, download it, make it executable (`chmod +x launchd.sh`) and run `./launchd.sh install`. You can uninstall the agent by running `./launchd.sh uninstall`.
+To do so, download it, make it executable (`chmod +x launchd.sh`) and run `./launchd.sh install`. You can uninstall the agent by running `./launchd.sh remove`.
## Compiling from source
From 2dce9760380e69f05b3ecc22b6aabf593b1d96e8 Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Wed, 29 May 2024 17:00:16 +0200
Subject: [PATCH 6/7] Clearer instructions (pt1)
---
README.md | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 6675982..004848c 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ Logs are stored in `C:\windows\logs\bridge.log`.
- 
- To remove, the same process can be followed, but click `Remove` instead.
+*Note, an [extra step]() is needed on MacOS*
+
##### Lutris
- Click on a game and select `Run EXE inside Wine prefix`.
@@ -51,10 +53,17 @@ Logs are stored in `C:\windows\logs\bridge.log`.
- Globally
- `flatpak override --user --filesystem=xdg-run/discord-ipc-0`
-## macOS
+##### MacOS
-The steps to install are almost the same. The only difference is that if you want the service to work, you will have to use [this script](build/launchd.sh) to install a launch agent that will symlink the `$TMPDIR` to a static path (`/tmp/rpc-bridge/tmpdir`).
-To do so, download it, make it executable (`chmod +x launchd.sh`) and run `./launchd.sh install`. You can uninstall the agent by running `./launchd.sh remove`.
+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
From e61fbf556e292b03334c7a2b4ef7e0212eee94f5 Mon Sep 17 00:00:00 2001
From: OrigamingWasTaken <74014262+OrigamingWasTaken@users.noreply.github.com>
Date: Wed, 29 May 2024 17:04:26 +0200
Subject: [PATCH 7/7] Added github markdown link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 004848c..2acef0e 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ Logs are stored in `C:\windows\logs\bridge.log`.
- 
- To remove, the same process can be followed, but click `Remove` instead.
-*Note, an [extra step]() is needed on MacOS*
+*Note, an [extra step](https://github.com/EnderIce2/rpc-bridge?tab=readme-ov-file#macos) is needed on MacOS*
##### Lutris