From 27ce7c568251eeda2045556112c1970f3161ab18 Mon Sep 17 00:00:00 2001 From: Dan Caspi Date: Tue, 29 May 2018 13:41:00 -0700 Subject: [PATCH] Persist the dock icon preference between runs I never use the Statusfy dock icon and it occupies precious real-state on the dock. This commit Makes it so that Statusfy remembers the user's dock icon preference. --- Statusfy/SFYAppDelegate.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Statusfy/SFYAppDelegate.m b/Statusfy/SFYAppDelegate.m index 6775ba2..e21ed7a 100644 --- a/Statusfy/SFYAppDelegate.m +++ b/Statusfy/SFYAppDelegate.m @@ -10,7 +10,7 @@ static NSString * const SFYPlayerStatePreferenceKey = @"ShowPlayerState"; -static NSString * const SFYPlayerDockIconPreferenceKey = @"YES"; +static NSString * const SFYPlayerHideDockIconPreferenceKey = @"HideDockIcon"; @interface SFYAppDelegate () @@ -24,9 +24,10 @@ @implementation SFYAppDelegate - (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification { - //Initialize the variable the getDockIconVisibility method checks - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:SFYPlayerDockIconPreferenceKey]; - + if (![self getDockIconVisibility]) { + // Hide the dock icon, in accordance with the user's preference + [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory]; + } self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; self.statusItem.highlightMode = YES; @@ -34,7 +35,7 @@ - (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification self.playerStateMenuItem = [[NSMenuItem alloc] initWithTitle:[self determinePlayerStateMenuItemTitle] action:@selector(togglePlayerStateVisibility) keyEquivalent:@""]; - self.dockIconMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Hide Dock Icon", nil) action:@selector(toggleDockIconVisibility) keyEquivalent:@""]; + self.dockIconMenuItem = [[NSMenuItem alloc] initWithTitle:[self determineDockIconMenuItemTitle] action:@selector(toggleDockIconVisibility) keyEquivalent:@""]; [menu addItem:self.playerStateMenuItem]; [menu addItem:self.dockIconMenuItem]; @@ -127,12 +128,13 @@ - (NSString *)determinePlayerStateText - (BOOL)getDockIconVisibility { - return [[NSUserDefaults standardUserDefaults] boolForKey:SFYPlayerDockIconPreferenceKey]; + // Return YES if the dock icon should be hidden or if the preference doesn't exist + return ![[NSUserDefaults standardUserDefaults] boolForKey:SFYPlayerHideDockIconPreferenceKey]; } - (void)setDockIconVisibility:(BOOL)visible { - [[NSUserDefaults standardUserDefaults] setBool:visible forKey:SFYPlayerDockIconPreferenceKey]; + [[NSUserDefaults standardUserDefaults] setBool:!visible forKey:SFYPlayerHideDockIconPreferenceKey]; } - (void)toggleDockIconVisibility