Browse Source

UI: Use native ObjectiveC methods to generate data file paths

PatTheMav 2 years ago
parent
commit
d2ea998f49
1 changed files with 11 additions and 29 deletions
  1. 11 29
      UI/platform-osx.mm

+ 11 - 29
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 = [bundle bundleIdentifier];
-		if (!bundleID)
-			throw "Could not find bundle identifier";
-
-		int app_count =
-			[NSRunningApplication
-				runningApplicationsWithBundleIdentifier:bundleID]
-				.count;
+	NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
 
-		already_running = app_count > 1;
+	NSUInteger appCount = [[NSRunningApplication
+		runningApplicationsWithBundleIdentifier:bundleId] count];
 
-	} 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<void *>(
+		NSView *view = (__bridge NSView *)reinterpret_cast<void *>(
 			window->winId());
-		NSWindow *nsw = nsv.window;
-		[nsw setLevel:1024];
+
+		[[view window] setLevel:NSScreenSaverWindowLevel];
 
 		flags |= Qt::WindowStaysOnTopHint;
 	} else {