X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=EnjoyableApplicationDelegate.m;h=313ba9a2fbf65df4a82e89369a7ceade015b0204;hp=388103b38e2a8b867a9640a629bbbe1608960d27;hb=6044e47a97de33531c47cd209b30d4405aa0530a;hpb=b46786face17680799d7fd9795dead8a801ae9c1 diff --git a/EnjoyableApplicationDelegate.m b/EnjoyableApplicationDelegate.m index 388103b..313ba9a 100644 --- a/EnjoyableApplicationDelegate.m +++ b/EnjoyableApplicationDelegate.m @@ -15,8 +15,8 @@ @implementation EnjoyableApplicationDelegate -- (void)didSwitchApplication:(NSNotification *)notification { - NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey]; +- (void)didSwitchApplication:(NSNotification *)note { + NSRunningApplication *currentApp = note.userInfo[NSWorkspaceApplicationKey]; [self.mappingsController activateMappingForProcess:currentApp.localizedName]; } @@ -46,12 +46,18 @@ [self.mappingsController load]; } -- (void)applicationWillTerminate:(NSNotification *)aNotification { - [NSUserDefaults.standardUserDefaults synchronize]; - [NSNotificationCenter.defaultCenter removeObserver:self]; +- (void)applicationDidBecomeActive:(NSNotification *)notification { + [window makeKeyAndOrderFront:nil]; +} + +- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication + hasVisibleWindows:(BOOL)flag { + [window makeKeyAndOrderFront:nil]; + return NO; } - (void)eventTranslationActivated:(NSNotification *)note { + [NSProcessInfo.processInfo disableAutomaticTermination:@"Input translation is active."]; [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(didSwitchApplication:) @@ -61,6 +67,7 @@ } - (void)eventTranslationDeactivated:(NSNotification *)note { + [NSProcessInfo.processInfo enableAutomaticTermination:@"Input translation is active."]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification @@ -75,10 +82,12 @@ int added = 0; for (NJMapping *mapping in mappings) { NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @""; - NSMenuItem *item = [dockMenuBase addItemWithTitle:mapping.name - action:@selector(chooseMapping:) - keyEquivalent:keyEquiv]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name + action:@selector(chooseMapping:) + keyEquivalent:keyEquiv]; item.representedObject = mapping; + item.state = mapping == self.mappingsController.currentMapping; + [dockMenuBase addItem:item]; } [_outputController refreshMappings]; }