X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=ApplicationController.m;h=aa51eeb4f18a0a810a0daaa6c018327e5be24563;hp=e87421c062b0e173d01965140ca5bf2a21b8e5d1;hb=dd1f684886c2809133356bb9b335a35293e8849e;hpb=3a40cba25b9bb38887fe4809277d4c0f73462d12 diff --git a/ApplicationController.m b/ApplicationController.m index e87421c..aa51eeb 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -5,6 +5,13 @@ // Created by Sam McCall on 4/05/09. // +#import "ApplicationController.h" + +#import "Config.h" +#import "ConfigsController.h" +#import "JoystickController.h" +#import "TargetController.h" + @implementation ApplicationController { BOOL active; } @@ -15,20 +22,12 @@ - (void)didSwitchApplication:(NSNotification *)notification { NSRunningApplication *currentApp = notification.userInfo[NSWorkspaceApplicationKey]; - ProcessSerialNumber psn; - OSStatus err; - if ((err = GetProcessForPID(currentApp.processIdentifier, &psn)) == noErr) { - [self.configsController applicationSwitchedTo:currentApp.localizedName withPsn:psn]; - } else { - NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; - NSLog(@"Error getting PSN for %@: %@", currentApp.localizedName, error); - } + [self.configsController activateConfigForProcess:currentApp.localizedName]; } - (void)applicationDidFinishLaunching:(NSNotification *)notification { [drawer open]; self.targetController.enabled = NO; - self.active = NO; [self.jsController setup]; [self.configsController load]; [[NSWorkspace sharedWorkspace].notificationCenter @@ -39,31 +38,19 @@ } - (void)applicationWillTerminate:(NSNotification *)aNotification { - // TODO: Save immediately / shortly after changing and then enable - // sudden termination support. - [configsController save]; + [[NSUserDefaults standardUserDefaults] synchronize]; [[NSWorkspace sharedWorkspace].notificationCenter removeObserver:self name:NSWorkspaceDidActivateApplicationNotification object:nil]; } -// TODO: Active state should probably be in the ConfigsController or -// JoystickController, not here. - -- (BOOL)active { - return active; -} - -- (void)setActive:(BOOL)newActive { - activeButton.label = newActive ? @"Stop" : @"Start"; - activeButton.image = [NSImage imageNamed:newActive ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; - activeMenuItem.state = newActive; - active = newActive; -} - - (IBAction)toggleActivity:(id)sender { - self.active = !self.active; + BOOL sendRealEvents = !self.jsController.sendingRealEvents; + self.jsController.sendingRealEvents = sendRealEvents; + activeButton.label = sendRealEvents ? @"Stop" : @"Start"; + activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"]; + activeMenuItem.state = sendRealEvents; } - (NSUInteger)firstConfigMenuIndex { @@ -94,6 +81,6 @@ - (void)chooseConfig:(id)sender { int idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex]; Config *chosen = self.configsController.configs[idx]; - [configsController activateConfig:chosen forApplication:NULL]; + [configsController activateConfig:chosen]; } @end