Explorar el Código

UI: Simplify multi-instance check

gxalpha hace 3 años
padre
commit
6d86b58ed7
Se han modificado 5 ficheros con 16 adiciones y 21 borrados
  1. 3 8
      UI/obs-app.cpp
  2. 2 2
      UI/platform-osx.mm
  3. 1 1
      UI/platform-windows.cpp
  4. 2 2
      UI/platform-x11.cpp
  5. 8 8
      UI/platform.hpp

+ 3 - 8
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;

+ 2 - 2
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);
 	}
 }
 

+ 1 - 1
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;
 

+ 2 - 2
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());

+ 8 - 8
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