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] 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)