From 078caa79805e054a6ceb0665631a8f262dd69100 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Sat, 12 Oct 2013 14:41:57 -0700 Subject: [PATCH] mamburu: Added an option to enable/disable giving up media keys control to Last.fm app --- Application/MediaKeysApplication.m | 32 ++++++ .../General/English.lproj/Preferences.xib | 98 ++++++++++--------- 2 files changed, 86 insertions(+), 44 deletions(-) diff --git a/Application/MediaKeysApplication.m b/Application/MediaKeysApplication.m index 9bf4a406f..2fba4ced0 100644 --- a/Application/MediaKeysApplication.m +++ b/Application/MediaKeysApplication.m @@ -26,6 +26,11 @@ - (void)finishLaunching { [super finishLaunching]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"allowLastfmMediaKeys" + options:NSKeyValueObservingOptionNew + context:nil]; + keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self]; if([SPMediaKeyTap usesGlobalMediaKeyTap]) [keyTap startWatchingMediaKeys]; @@ -74,4 +79,31 @@ } } +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([keyPath isEqualToString:@"allowLastfmMediaKeys"]) + { + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + BOOL allowLastfmMediaKeys = [defs boolForKey:@"allowLastfmMediaKeys"]; + NSArray *old = [defs arrayForKey:kMediaKeyUsingBundleIdentifiersDefaultsKey]; + + NSMutableArray *new = [old mutableCopy]; + NSArray *lastfmIds = [NSArray arrayWithObjects:@"fm.last.Last.fm", @"fm.last.Scrobbler", nil]; + if (allowLastfmMediaKeys) + { + [new addObjectsFromArray:lastfmIds]; + } + else + { + [new removeObjectsInArray:lastfmIds]; + } + + [defs setObject:new forKey:kMediaKeyUsingBundleIdentifiersDefaultsKey]; + } + else + { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + + @end diff --git a/Preferences/General/English.lproj/Preferences.xib b/Preferences/General/English.lproj/Preferences.xib index fbb5f04a6..fd13c62c2 100644 --- a/Preferences/General/English.lproj/Preferences.xib +++ b/Preferences/General/English.lproj/Preferences.xib @@ -13,7 +13,7 @@ - + @@ -272,41 +272,65 @@ name - - - - - - - - name url + + + name + slug + preference + + + + + name + slug + preference + + + + + + + + + + + @@ -384,20 +408,6 @@ - - - name - slug - preference - - - - - name - slug - preference - -