From a984e2dd951bcbfe5e3e6374213eb9a5fd5423cf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 1 Dec 2016 06:58:56 -0500 Subject: Able to get a shortcut from the MASShortcutView Fuck damn it finally freaking works! Damn, just had to take a 1.5 hour nap after that. We're finally able to extract a shortcut out of the MASShortcutView. After trying a whole bunch of different things, I ultimately tried opening the debugger and figured out that for whatever reason the bindings weren't getting created and because of that my shortcut wasn't getting saved in the user defaults. Couldn't figure out how to get the binding to work even after includes and whatnot. Finally decided screw it I'm going to subclass the view and get the shortcut and store it in `NSUserDefaults` myself. So that's what we're going to do and this is the first step to getting that working. Hoo boy. Definitely need to vaccum the code after this. --- Low Battery Yup/AppDelegate.m | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'Low Battery Yup/AppDelegate.m') diff --git a/Low Battery Yup/AppDelegate.m b/Low Battery Yup/AppDelegate.m index 0c9bbdc..8a9005f 100644 --- a/Low Battery Yup/AppDelegate.m +++ b/Low Battery Yup/AppDelegate.m @@ -8,6 +8,9 @@ #import "AppDelegate.h" +static NSString *const kPreferenceGlobalShortcut = @"GlobalShortcut"; +static void *AppObservingContext = &AppObservingContext; + @implementation AppDelegate - (void)dealloc @@ -17,7 +20,35 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application + [_shortcut_view setAssociatedUserDefaultsKey:kPreferenceGlobalShortcut]; + +// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; +// [_shortcut_view bind:@"shortcutValue" toObject:defaults withKeyPath:@"thisisatest" options:nil]; + +// [defaults addObserver:self forKeyPath:@"thisisatest" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:AppObservingContext]; + +// [[MASShortcutBinder sharedBinder] +// bindShortcutWithDefaultsKey:kPreferenceGlobalShortcut +// toAction:^{NSLog(@"dudebro");}]; + +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + NSLog(@"OBSERVED"); + NSLog(@"%@", change); +} + +- (IBAction)logDefaults:(id)sender +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSLog(@"%@", [defaults objectForKey:[@"values." stringByAppendingString:kPreferenceGlobalShortcut]]); +// NSLog(@"%@", [defaults objectForKey:kPreferenceGlobalShortcut]); +// NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]); + +// NSLog(@"%@", [_shortcut_view shortcutValue]); +// NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"thisisatest"]); +// [[NSUserDefaults standardUserDefaults] setObject:@"dude come on" forKey:@"thisisatest"]; } @end -- cgit v1.2.3