From d2ea998f492a686abc0c5c83510921e789ff995c Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Sun, 2 Apr 2023 18:56:44 +0200 Subject: [PATCH] UI: Use native ObjectiveC methods to generate data file paths --- UI/platform-osx.mm | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index a0f0bec11..61a81947e 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -40,38 +40,22 @@ bool isInBundle() bool GetDataFilePath(const char *data, string &output) { - NSRunningApplication *app = [NSRunningApplication currentApplication]; - NSURL *bundleURL = [app bundleURL]; - NSString *path = [NSString - stringWithFormat:@"Contents/Resources/%@", - [NSString stringWithUTF8String:data]]; - NSURL *dataURL = [bundleURL URLByAppendingPathComponent:path]; - output = [[dataURL path] UTF8String]; + NSURL *bundleUrl = [[NSBundle mainBundle] bundleURL]; + NSString *path = [[bundleUrl path] + stringByAppendingFormat:@"/%@/%s", @"Contents/Resources", data]; + output = path.UTF8String; return !access(output.c_str(), R_OK); } void CheckIfAlreadyRunning(bool &already_running) { - try { - NSBundle *bundle = [NSBundle mainBundle]; - if (!bundle) - throw "Could not find main bundle"; + NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier]; - NSString *bundleID = [bundle bundleIdentifier]; - if (!bundleID) - throw "Could not find bundle identifier"; + NSUInteger appCount = [[NSRunningApplication + runningApplicationsWithBundleIdentifier:bundleId] count]; - int app_count = - [NSRunningApplication - runningApplicationsWithBundleIdentifier:bundleID] - .count; - - already_running = app_count > 1; - - } catch (const char *error) { - blog(LOG_ERROR, "CheckIfAlreadyRunning: %s", error); - } + already_running = appCount > 1; } string GetDefaultVideoSavePath() @@ -143,12 +127,10 @@ void SetAlwaysOnTop(QWidget *window, bool enable) Qt::WindowFlags flags = window->windowFlags(); if (enable) { - /* Force the level of the window high so it sits on top of - * full-screen applications like Keynote */ - NSView *nsv = (__bridge NSView *)reinterpret_cast( + NSView *view = (__bridge NSView *)reinterpret_cast( window->winId()); - NSWindow *nsw = nsv.window; - [nsw setLevel:1024]; + + [[view window] setLevel:NSScreenSaverWindowLevel]; flags |= Qt::WindowStaysOnTopHint; } else {