Browse Source

cocoa: Use `-[NSApplicationDelegate applicationSupportsSecureRestorableState]`.

This prevents warnings at startup on macOS Sonoma (14.0).

(cherry picked from commit 7d25a443c45450287e0a3ec5c1eb0e417647070e)
Ryan C. Gordon 1 year ago
parent
commit
3817f5126e
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/video/cocoa/SDL_cocoaevents.m

+ 17 - 0
src/video/cocoa/SDL_cocoaevents.m

@@ -133,6 +133,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
                       ofObject:(id)object
                         change:(NSDictionary *)change
                        context:(void *)context;
+- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
 @end
 
 @implementation SDLAppDelegate : NSObject
@@ -319,6 +320,22 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
     SDL_SendDropComplete(NULL);
 }
 
+- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
+{
+    // This just tells Cocoa that we didn't do any custom save state magic for the app,
+    // so the system is safe to use NSSecureCoding internally, instead of using unencrypted
+    // save states for backwards compatibility. If we don't return YES here, we'll get a
+    // warning on the console at startup:
+    //
+    // ```
+    // WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
+    // ```
+    //
+    // More-detailed explanation:
+    // https://stackoverflow.com/questions/77283578/sonoma-and-nsapplicationdelegate-applicationsupportssecurerestorablestate/77320845#77320845
+    return YES;
+}
+
 @end
 
 static SDLAppDelegate *appDelegate = nil;