mirror of
https://github.com/EnderIce2/rpc-bridge.git
synced 2025-05-25 22:14:38 +00:00
Merge pull request #3 from OrigamingWasTaken/master
Add support for the windows service on MacOS
This commit is contained in:
commit
da2a006ffb
15
README.md
15
README.md
@ -1,3 +1,4 @@
|
|||||||
|
# Beta macos fix
|
||||||
# Discord RPC Bridge for Wine
|
# Discord RPC Bridge for Wine
|
||||||
|
|
||||||

|

|
||||||
@ -25,6 +26,8 @@ Logs are stored in `C:\windows\logs\bridge.log`.
|
|||||||
- 
|
- 
|
||||||
- To remove, the same process can be followed, but click `Remove` instead.
|
- 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
|
##### Lutris
|
||||||
|
|
||||||
- Click on a game and select `Run EXE inside Wine prefix`.
|
- 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
|
- Globally
|
||||||
- `flatpak override --user --filesystem=xdg-run/discord-ipc-0`
|
- `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
|
## Compiling from source
|
||||||
|
|
||||||
|
40
bridge.c
40
bridge.c
@ -250,22 +250,32 @@ char *native_getenv(const char *name)
|
|||||||
void ConnectToSocket(int fd)
|
void ConnectToSocket(int fd)
|
||||||
{
|
{
|
||||||
print("Connecting to socket\n");
|
print("Connecting to socket\n");
|
||||||
const char *runtime;
|
const char *runtime;
|
||||||
if (IsLinux)
|
if (IsLinux)
|
||||||
runtime = native_getenv("XDG_RUNTIME_DIR");
|
runtime = native_getenv("XDG_RUNTIME_DIR");
|
||||||
else
|
else
|
||||||
runtime = native_getenv("TMPDIR");
|
runtime = native_getenv("TMPDIR");
|
||||||
if (runtime == NULL)
|
if (runtime == NULL)
|
||||||
{
|
{
|
||||||
print("IPC directory not set\n");
|
runtime = "/tmp/rpc-bridge/tmpdir";
|
||||||
if (!RunningAsService)
|
print("IPC directory not set, fallback to /tmp/rpc-bridge/tmpdir\n");
|
||||||
MessageBox(NULL, "IPC directory not set",
|
|
||||||
"Environment variable not set",
|
|
||||||
MB_OK | MB_ICONSTOP);
|
|
||||||
ExitProcess(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
/* TODO: check for multiple discord instances and create a pipe for each */
|
||||||
const char *discordUnixPipes[] = {
|
const char *discordUnixPipes[] = {
|
||||||
|
84
build/launchd.sh
Executable file
84
build/launchd.sh
Executable file
@ -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 "<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST File Format//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>com.enderice2.rpc-bridge</string>
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>$SCRIPT</string>
|
||||||
|
</array>
|
||||||
|
<key>RunAtLoad</key>
|
||||||
|
<true />
|
||||||
|
</dict>
|
||||||
|
</plist>" > "$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
|
12
gui.c
12
gui.c
@ -182,12 +182,12 @@ VOID SetButtonStyles(INT *btnStartStyle, INT *btnRemoveStyle, INT *btnInstallSty
|
|||||||
*btnRemoveStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
|
*btnRemoveStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
|
||||||
*btnInstallStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
|
*btnInstallStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
|
||||||
|
|
||||||
if (!IsLinux)
|
// if (!IsLinux)
|
||||||
{
|
// {
|
||||||
*btnInstallStyle |= WS_DISABLED;
|
// *btnInstallStyle |= WS_DISABLED;
|
||||||
*btnRemoveStyle |= WS_DISABLED;
|
// *btnRemoveStyle |= WS_DISABLED;
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
SC_HANDLE schService = OpenService(hSCManager, "rpc-bridge", SERVICE_START | SERVICE_QUERY_STATUS);
|
SC_HANDLE schService = OpenService(hSCManager, "rpc-bridge", SERVICE_START | SERVICE_QUERY_STATUS);
|
||||||
|
14
service.c
14
service.c
@ -88,13 +88,13 @@ void InstallService(int ServiceStartType, LPCSTR Path)
|
|||||||
{
|
{
|
||||||
print("Registering service\n");
|
print("Registering service\n");
|
||||||
|
|
||||||
if (IsLinux == FALSE)
|
// if (IsLinux == FALSE)
|
||||||
{
|
// {
|
||||||
/* FIXME: I don't know how to get the TMPDIR without getenv */
|
// /* 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.",
|
// MessageBox(NULL, "Registering as a service is not supported on macOS at the moment.",
|
||||||
"Unsupported", MB_OK | MB_ICONINFORMATION);
|
// "Unsupported", MB_OK | MB_ICONINFORMATION);
|
||||||
ExitProcess(1);
|
// ExitProcess(1);
|
||||||
}
|
// }
|
||||||
|
|
||||||
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
|
||||||
if (schSCManager == NULL)
|
if (schSCManager == NULL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user