@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 {
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 {