macOS: Fix an OS-generated warning printed to stdout on launch in bundled apps.
authorAlex Szpakowski <slime73@gmail.com>
Thu, 09 Nov 2017 22:24:09 -0400
changeset 116972b03795fbd49
parent 11696 7dc3cec9ac85
child 11698 c5ae532b96d0
macOS: Fix an OS-generated warning printed to stdout on launch in bundled apps.
src/video/cocoa/SDL_cocoaevents.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Wed Nov 08 14:17:23 2017 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Thu Nov 09 22:24:09 2017 -0400
     1.3 @@ -38,6 +38,8 @@
     1.4  - (void)terminate:(id)sender;
     1.5  - (void)sendEvent:(NSEvent *)theEvent;
     1.6  
     1.7 ++ (void)registerUserDefaults;
     1.8 +
     1.9  @end
    1.10  
    1.11  @implementation SDLApplication
    1.12 @@ -90,6 +92,17 @@
    1.13      [super sendEvent:theEvent];
    1.14  }
    1.15  
    1.16 ++ (void)registerUserDefaults
    1.17 +{
    1.18 +    NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
    1.19 +                                 [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
    1.20 +                                 [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
    1.21 +                                 [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
    1.22 +                                 nil];
    1.23 +    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
    1.24 +    [appDefaults release];
    1.25 +}
    1.26 +
    1.27  @end // SDLApplication
    1.28  
    1.29  /* setAppleMenu disappeared from the headers in 10.4 */
    1.30 @@ -227,6 +240,10 @@
    1.31      if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
    1.32          [NSApp activateIgnoringOtherApps:YES];
    1.33      }
    1.34 +
    1.35 +    /* If we call this before NSApp activation, macOS might print a complaint
    1.36 +     * about ApplePersistenceIgnoreState. */
    1.37 +    [SDLApplication registerUserDefaults];
    1.38  }
    1.39  @end
    1.40  
    1.41 @@ -379,13 +396,12 @@
    1.42              CreateApplicationMenus();
    1.43          }
    1.44          [NSApp finishLaunching];
    1.45 -        NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
    1.46 -            [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
    1.47 -            [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
    1.48 -            [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
    1.49 -            nil];
    1.50 -        [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
    1.51 -        [appDefaults release];
    1.52 +        if ([NSApp delegate]) {
    1.53 +            /* The SDL app delegate calls this in didFinishLaunching if it's
    1.54 +             * attached to the NSApp, otherwise we need to call it manually.
    1.55 +             */
    1.56 +            [SDLApplication registerUserDefaults];
    1.57 +        }
    1.58      }
    1.59      if (NSApp && !appDelegate) {
    1.60          appDelegate = [[SDLAppDelegate alloc] init];