UI: Detect other instances of obs on macOS
Detect other instances of the obs by inspecting running applications with same bundle ID. fixes: #3053
This commit is contained in:
parent
64869bac46
commit
117d35433f
@ -1929,13 +1929,17 @@ static int run_program(fstream &logFile, int argc, char *argv[])
|
||||
OBSTranslator translator;
|
||||
program.installTranslator(&translator);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* --------------------------------------- */
|
||||
/* check and warn if already running */
|
||||
|
||||
bool cancel_launch = false;
|
||||
bool already_running = false;
|
||||
|
||||
#if defined(_WIN32)
|
||||
RunOnceMutex rom = GetRunOnceMutex(already_running);
|
||||
#elif defined(__APPLE__)
|
||||
CheckAppWithSameBundleID(already_running);
|
||||
#endif
|
||||
|
||||
if (!already_running) {
|
||||
goto run;
|
||||
@ -1979,7 +1983,6 @@ static int run_program(fstream &logFile, int argc, char *argv[])
|
||||
|
||||
/* --------------------------------------- */
|
||||
run:
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__)
|
||||
// Mounted by termina during chromeOS linux container startup
|
||||
|
@ -87,6 +87,29 @@ bool InitApplicationBundle()
|
||||
#endif
|
||||
}
|
||||
|
||||
void CheckAppWithSameBundleID(bool &already_running)
|
||||
{
|
||||
try {
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
if (!bundle)
|
||||
throw "Could not find main bundle";
|
||||
|
||||
NSString *bundleID = [bundle bundleIdentifier];
|
||||
if (!bundleID)
|
||||
throw "Could not find bundle identifier";
|
||||
|
||||
int app_count =
|
||||
[NSRunningApplication
|
||||
runningApplicationsWithBundleIdentifier:bundleID]
|
||||
.count;
|
||||
|
||||
already_running = app_count > 1;
|
||||
|
||||
} catch (const char *error) {
|
||||
blog(LOG_ERROR, "CheckAppWithSameBundleID: %s", error);
|
||||
}
|
||||
}
|
||||
|
||||
string GetDefaultVideoSavePath()
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
@ -68,4 +68,5 @@ void EnableOSXVSync(bool enable);
|
||||
void EnableOSXDockIcon(bool enable);
|
||||
void InstallNSApplicationSubclass();
|
||||
void disableColorSpaceConversion(QWidget *window);
|
||||
void CheckAppWithSameBundleID(bool &already_running);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user