[Scummvm-git-logs] scummvm master -> 06380fc9c3860e7210725e0ceaac12107b9b56b8

sev- noreply at scummvm.org
Mon Nov 28 23:11:09 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
06380fc9c3 MACOSX: Prefer openURL/openURLs over openFile on macOS 10.15+


Commit: 06380fc9c3860e7210725e0ceaac12107b9b56b8
    https://github.com/scummvm/scummvm/commit/06380fc9c3860e7210725e0ceaac12107b9b56b8
Author: Donovan Watteau (contrib at dwatteau.fr)
Date: 2022-11-29T00:11:03+01:00

Commit Message:
MACOSX: Prefer openURL/openURLs over openFile on macOS 10.15+

They're the recommended APIs now, and openFile is deprecated starting
with macOS 11.0. openURLs:withApplicationAtURL (for TextEdit usage)
requires macOS 10.15+, so we need different code paths.

Changed paths:
    backends/platform/sdl/macosx/appmenu_osx.mm
    backends/platform/sdl/macosx/macosx-compat.h


diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm
index 51774b77c2f..15e33bf51f7 100644
--- a/backends/platform/sdl/macosx/appmenu_osx.mm
+++ b/backends/platform/sdl/macosx/appmenu_osx.mm
@@ -85,14 +85,27 @@ static void openFromBundle(NSString *file) {
 		}
 	}
 
+	// RTF and HTML files are widely recognized and we can rely on the default
+	// file association working for those. For the other ones this might not be
+	// the case so we explicitly indicate they should be open with TextEdit.
 	if (path) {
-		// RTF and HTML files are widely recognized and we can rely on the default
-		// file association working for those. For the other ones this might not be
-		// the case so we explicitly indicate they should be open with TextEdit.
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
 		if ([path hasSuffix:@".html"] || [path hasSuffix:@".rtf"])
 			[[NSWorkspace sharedWorkspace] openFile:path];
 		else
 			[[NSWorkspace sharedWorkspace] openFile:path withApplication:@"TextEdit"];
+#else
+		NSURL *pathUrl = [NSURL fileURLWithPath:path isDirectory:NO];
+		if ([path hasSuffix:@".html"] || [path hasSuffix:@".rtf"]) {
+			[[NSWorkspace sharedWorkspace] openURL:pathUrl];
+		} else {
+			[[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObjects:pathUrl, nil]
+				withApplicationAtURL:[[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.apple.TextEdit"]
+				configuration:[NSWorkspaceOpenConfiguration configuration]
+				completionHandler:nil
+			];
+		}
+#endif
 	}
 }
 
@@ -147,7 +160,12 @@ static void openFromBundle(NSString *file) {
 		NSString *file;
 		while ((file = [dirEnum nextObject])) {
 			if ([file hasPrefix:@"ScummVM Manual"] && [file hasSuffix:@".pdf"]) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
 				[[NSWorkspace sharedWorkspace] openFile:[bundlePath stringByAppendingPathComponent:file]];
+#else
+				NSURL *fileUrl = [NSURL fileURLWithPath:[bundlePath stringByAppendingPathComponent:file] isDirectory:NO];
+				[[NSWorkspace sharedWorkspace] openURL:fileUrl];
+#endif
 				return;
 			}
 		}
diff --git a/backends/platform/sdl/macosx/macosx-compat.h b/backends/platform/sdl/macosx/macosx-compat.h
index 80c9a97c724..44654146c48 100644
--- a/backends/platform/sdl/macosx/macosx-compat.h
+++ b/backends/platform/sdl/macosx/macosx-compat.h
@@ -44,4 +44,8 @@
 #define MAC_OS_X_VERSION_10_12 101200
 #endif
 
+#ifndef MAC_OS_X_VERSION_10_15
+#define MAC_OS_X_VERSION_10_15 101500
+#endif
+
 #endif




More information about the Scummvm-git-logs mailing list