Skip to content

Commit

Permalink
Persist the dock icon preference between runs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcaspi committed May 29, 2018
1 parent acae56b commit 27ce7c5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Statusfy/SFYAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


static NSString * const SFYPlayerStatePreferenceKey = @"ShowPlayerState";
static NSString * const SFYPlayerDockIconPreferenceKey = @"YES";
static NSString * const SFYPlayerHideDockIconPreferenceKey = @"HideDockIcon";

@interface SFYAppDelegate ()

Expand All @@ -24,17 +24,18 @@ @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;

NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];

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];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27ce7c5

Please sign in to comment.