X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FEnjoyableApplicationDelegate.m;h=f02ec90663ba6e4d29a7db97076b4f6f38e85d9f;hp=f1513996c2d8687d8a3c47d9e97d60012f04a35c;hb=f8ae7787fe3fe272eaf04586e3007339c907fb33;hpb=9923a1899abb5f85259cc912a43435dd5a3ae6a7 diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index f151399..f02ec90 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -48,7 +48,14 @@ } - (void)applicationDidFinishLaunching:(NSNotification *)notification { - [window makeKeyAndOrderFront:nil]; + if (NSRunningApplication.currentApplication.wasLaunchedAsLoginItemOrResume + && [NSUserDefaults.standardUserDefaults boolForKey:@"hidden in status item"]) { + [self transformIntoElement:self]; + NSApplication *app = notification.object; + [app deactivate]; + } else { + [window makeKeyAndOrderFront:nil]; + } } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication @@ -65,15 +72,18 @@ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformIntoElement:) object:self]; + [NSUserDefaults.standardUserDefaults setBool:NO forKey:@"hidden in status item"]; } - (void)applicationWillBecomeActive:(NSNotification *)notification { - [self restoreToForeground:notification]; + if (window.isVisible) + [self restoreToForeground:notification]; } - (void)transformIntoElement:(id)sender { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToUIElementApplication); + [NSUserDefaults.standardUserDefaults setBool:YES forKey:@"hidden in status item"]; } - (void)flashStatusItem {