Skip to content

Commit

Permalink
Handle dark mode.
Browse files Browse the repository at this point in the history
Why:

* The icon is hard to see in darkmode.

This change addresses the need by:

* Check current appearance when rendering the menu in order to know
  whether or not to display a dark or light icon.
* Add an observer to see when the apearance has changed and rerender the
  menu icon.

Side effects:

* The icon is now visible when in dark mode.
  • Loading branch information
squaresurf committed May 28, 2019
1 parent 332d7fd commit 977c472
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions objective-octocat-notifications/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0
diskCapacity:0
diskPath:nil];

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(appearanceChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];


[NSURLCache setSharedURLCache:sharedCache];

[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
Expand All @@ -43,6 +47,10 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)appearanceChanged:(NSNotification *)notify {
[_statusItemController setActiveStateFromNotificationsCount];
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
_haveAskedIfWeShouldAddToLoginItemsDefaultsKey = [NSString stringWithFormat:@"%@.haveAskedIfWeShouldAddToLoginItems", [[NSRunningApplication currentApplication] bundleIdentifier]];
Expand Down
1 change: 1 addition & 0 deletions objective-octocat-notifications/OonStatusBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{
NSStatusItem *statusItem;
OonIcon *defaultIcon;
OonIcon *defaultDarkIcon;
OonIcon *hasNotificationsIcon;
}

Expand Down
7 changes: 6 additions & 1 deletion objective-octocat-notifications/OonStatusBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ - (id)init
self = [super init];
if (self) {
defaultIcon = [OonIcon forStatusBarFrom:OonIconStatusBarDefault];
defaultDarkIcon = [OonIcon forStatusBarFrom:OonIconStatusBarActive];
hasNotificationsIcon = [OonIcon forStatusBarFrom:OonIconStatusBarHasNotifications];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
}
Expand All @@ -35,7 +36,11 @@ - (void) setActiveStateTo:(BOOL) hasNotifications
if (hasNotifications) {
[statusItem setImage:hasNotificationsIcon];
} else {
[statusItem setImage:defaultIcon];
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] isEqualToString:@"Dark"]) {
[statusItem setImage:defaultDarkIcon];
} else {
[statusItem setImage:defaultIcon];
}
}
}

Expand Down

0 comments on commit 977c472

Please sign in to comment.