Support magic @Application token for automatic mapping names. Fall back to the bundle...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 6 Mar 2013 14:12:07 +0000 (15:12 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 6 Mar 2013 14:12:07 +0000 (15:12 +0100)
EnjoyableApplicationDelegate.m
NJMappingsController.m

index 140611539795ffdd3c3be11f2fd89f334f264256..2478b4e81c62654861a463b14ba22528d16e4fe8 100644 (file)
 @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 {
index 43f6282a4fc6876814fd4c2e439a34becffa43da..567f2337930b242b38d8a080ec53f28501d9fb4d 100644 (file)
                                             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 {