From 6d86b58ed77e94918d5f792f7033dd225e18dff6 Mon Sep 17 00:00:00 2001 From: gxalpha Date: Mon, 28 Feb 2022 22:43:06 +0100 Subject: [PATCH] UI: Simplify multi-instance check --- UI/obs-app.cpp | 11 +++-------- UI/platform-osx.mm | 4 ++-- UI/platform-windows.cpp | 2 +- UI/platform-x11.cpp | 4 ++-- UI/platform.hpp | 16 ++++++++-------- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 4ba4e10f0..74cccaa45 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -2099,15 +2099,10 @@ static int run_program(fstream &logFile, int argc, char *argv[]) bool cancel_launch = false; bool already_running = false; -#if defined(_WIN32) - RunOnceMutex rom = GetRunOnceMutex(already_running); -#elif defined(__APPLE__) - CheckAppWithSameBundleID(already_running); -#elif defined(__linux__) - RunningInstanceCheck(already_running); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - PIDFileCheck(already_running); +#ifdef _WIN32 + RunOnceMutex rom = #endif + CheckIfAlreadyRunning(already_running); if (!already_running) { goto run; diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index 2c9e37ada..fcd37b503 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -88,7 +88,7 @@ bool InitApplicationBundle() #endif } -void CheckAppWithSameBundleID(bool &already_running) +void CheckIfAlreadyRunning(bool &already_running) { try { NSBundle *bundle = [NSBundle mainBundle]; @@ -107,7 +107,7 @@ void CheckAppWithSameBundleID(bool &already_running) already_running = app_count > 1; } catch (const char *error) { - blog(LOG_ERROR, "CheckAppWithSameBundleID: %s", error); + blog(LOG_ERROR, "CheckIfAlreadyRunning: %s", error); } } diff --git a/UI/platform-windows.cpp b/UI/platform-windows.cpp index 4639ae89d..2ad0dccfc 100644 --- a/UI/platform-windows.cpp +++ b/UI/platform-windows.cpp @@ -328,7 +328,7 @@ RunOnceMutex &RunOnceMutex::operator=(RunOnceMutex &&rom) return *this; } -RunOnceMutex GetRunOnceMutex(bool &already_running) +RunOnceMutex CheckIfAlreadyRunning(bool &already_running) { string name; diff --git a/UI/platform-x11.cpp b/UI/platform-x11.cpp index 6162b6497..73cb7c15a 100644 --- a/UI/platform-x11.cpp +++ b/UI/platform-x11.cpp @@ -53,7 +53,7 @@ using std::vector; using std::ostringstream; #ifdef __linux__ -void RunningInstanceCheck(bool &already_running) +void CheckIfAlreadyRunning(bool &already_running) { int uniq = socket(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0); @@ -133,7 +133,7 @@ struct RunOnce { } RO; const char *RunOnce::thr_name = "OBS runonce"; -void PIDFileCheck(bool &already_running) +void CheckIfAlreadyRunning(bool &already_running) { std::string tmpfile_name = "/tmp/obs-studio.lock." + std::to_string(geteuid()); diff --git a/UI/platform.hpp b/UI/platform.hpp index 1be30f654..9851fb918 100644 --- a/UI/platform.hpp +++ b/UI/platform.hpp @@ -39,6 +39,14 @@ void SetAlwaysOnTop(QWidget *window, bool enable); bool SetDisplayAffinitySupported(void); +#ifdef _WIN32 +class RunOnceMutex; +RunOnceMutex +#else +void +#endif +CheckIfAlreadyRunning(bool &already_running); + #ifdef _WIN32 uint32_t GetWindowsVersion(); uint32_t GetWindowsBuild(); @@ -62,7 +70,6 @@ public: RunOnceMutex &operator=(RunOnceMutex &&rom); }; -RunOnceMutex GetRunOnceMutex(bool &already_running); QString GetMonitorName(const QString &id); bool IsRunningOnWine(); #endif @@ -72,12 +79,5 @@ void EnableOSXVSync(bool enable); void EnableOSXDockIcon(bool enable); void InstallNSApplicationSubclass(); void disableColorSpaceConversion(QWidget *window); -void CheckAppWithSameBundleID(bool &already_running); bool ProcessIsRosettaTranslated(); #endif -#ifdef __linux__ -void RunningInstanceCheck(bool &already_running); -#endif -#if defined(__FreeBSD__) || defined(__DragonFly__) -void PIDFileCheck(bool &already_running); -#endif