From bf62b06504aeb5d111735f4a0f40b1b3f9e9e350 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 6 Mar 2013 15:12:07 +0100 Subject: [PATCH] Support magic @Application token for automatic mapping names. Fall back to the bundle name if no localized name is available. --- EnjoyableApplicationDelegate.m | 8 ++++++-- NJMappingsController.m | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) 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 { -- 2.30.2