From: Joe Wreschnig Date: Wed, 6 Mar 2013 14:12:07 +0000 (+0100) Subject: Support magic @Application token for automatic mapping names. Fall back to the bundle... X-Git-Tag: version-1.0~28 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=bf62b06504aeb5d111735f4a0f40b1b3f9e9e350;p=enjoyable.git Support magic @Application token for automatic mapping names. Fall back to the bundle name if no localized name is available. --- diff --git a/EnjoyableApplicationDelegate.m b/EnjoyableApplicationDelegate.m index 1406115..2478b4e 100644 --- a/EnjoyableApplicationDelegate.m +++ b/EnjoyableApplicationDelegate.m @@ -16,8 +16,12 @@ @implementation EnjoyableApplicationDelegate - (void)didSwitchApplication:(NSNotification *)note { - NSRunningApplication *currentApp = note.userInfo[NSWorkspaceApplicationKey]; - [self.mappingsController activateMappingForProcess:currentApp.localizedName]; + NSRunningApplication *activeApp = note.userInfo[NSWorkspaceApplicationKey]; + NSString *name = activeApp.localizedName; + if (!name) + name = activeApp.bundleIdentifier; + if (name && ![name isEqualToString:NSRunningApplication.currentApplication.localizedName]) + [self.mappingsController activateMappingForProcess:name]; } - (void)applicationDidFinishLaunching:(NSNotification *)notification { diff --git a/NJMappingsController.m b/NJMappingsController.m index 43f6282..567f233 100644 --- a/NJMappingsController.m +++ b/NJMappingsController.m @@ -56,15 +56,19 @@ count:len]; } - - (void)activateMappingForProcess:(NSString *)processName { - NJMapping *oldMapping = manualMapping; - NJMapping *newMapping = self[processName]; - if (!newMapping) - newMapping = oldMapping; - if (newMapping != _currentMapping) - [self activateMapping:newMapping]; - manualMapping = oldMapping; + if ([manualMapping.name.lowercaseString isEqualToString:@"@application"]) { + manualMapping.name = processName; + [self mappingsChanged]; + } else { + NJMapping *oldMapping = manualMapping; + NJMapping *newMapping = self[processName]; + if (!newMapping) + newMapping = oldMapping; + if (newMapping != _currentMapping) + [self activateMapping:newMapping]; + manualMapping = oldMapping; + } } - (void)activateMapping:(NJMapping *)mapping {