Skip to content

Commit

Permalink
Updated Hide Dock so that it shows and hides based on the menu hits c…
Browse files Browse the repository at this point in the history
…onsistently. Icon state is not stored over quits.
  • Loading branch information
sidewinder12s committed Mar 19, 2015
1 parent 46998a7 commit 863246e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 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 = @"ShowDockIcon";
static NSString * const SFYPlayerDockIconPreferenceKey = @"YES";

@interface SFYAppDelegate ()

Expand All @@ -24,14 +24,17 @@ @implementation SFYAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
{
//Initialize the variable the getDockIconVisibility method checks
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:SFYPlayerDockIconPreferenceKey];

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:[self determineDockIconMenuItemTitle] action:@selector(toggleDockIconVisibility) keyEquivalent:@""];
self.dockIconMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Hide Dock Icon", nil) action:@selector(toggleDockIconVisibility) keyEquivalent:@""];

[menu addItem:self.playerStateMenuItem];
[menu addItem:self.dockIconMenuItem];
Expand All @@ -43,7 +46,6 @@ - (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(setStatusItemTitle) userInfo:nil repeats:YES];
}


#pragma mark - Setting title text

- (void)setStatusItemTitle
Expand All @@ -70,7 +72,6 @@ - (void)setStatusItemTitle
}
}


#pragma mark - Executing AppleScript

- (NSAppleEventDescriptor *)executeAppleScript:(NSString *)command
Expand All @@ -81,7 +82,6 @@ - (NSAppleEventDescriptor *)executeAppleScript:(NSString *)command
return eventDescriptor;
}


#pragma mark - Player state

- (BOOL)getPlayerStateVisibility
Expand Down Expand Up @@ -132,20 +132,23 @@ - (BOOL)getDockIconVisibility

- (void)setDockIconVisibility:(BOOL)visible
{
[[NSUserDefaults standardUserDefaults] setBool:visible forKey:SFYPlayerDockIconPreferenceKey];
[[NSUserDefaults standardUserDefaults] setBool:visible forKey:SFYPlayerDockIconPreferenceKey];
}

- (void)toggleDockIconVisibility
{
[self setDockIconVisibility:![self getDockIconVisibility]];
self.dockIconMenuItem.title = [self determineDockIconMenuItemTitle];

if([_dockIconMenuItem.title isEqual: @"Show Dock Icon"])
if(![self getDockIconVisibility])
{
//Apple recommended method to show and hide dock icon
//hide icon
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
}
else
{
//show icon
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
}
}
Expand All @@ -162,6 +165,4 @@ - (void)quit
[[NSApplication sharedApplication] terminate:self];
}

@end


@end

0 comments on commit 863246e

Please sign in to comment.