Skip to content

Commit 723ba5b

Browse files
committed
Added the option of white text time in the menu bar
I use the menu bar theme called Obsidian to make my menu bar black. So I added a toggle with the option to make the time shown to the right of the battery white (the battery is automatically themed by Obsidian). Signed-off-by: Johnny <[email protected]>
1 parent 895e958 commit 723ba5b

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

Battery Time Remaining/AppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define kBTRMenuEnergySaverSetting 9
2323
#define kBTRMenuUpdater 10
2424
#define kBTRMenuQuitKey 11
25+
#define kBTRMenuWhiteText 12
2526

2627
#endif
2728

Battery Time Remaining/AppDelegate.m

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ @interface AppDelegate ()
3939
BOOL isOptionKeyPressed;
4040
BOOL isCapacityWarning;
4141
BOOL showParenthesis;
42+
BOOL whiteText;
4243
}
4344

4445
- (void)cacheBatteryIcon;
@@ -124,10 +125,18 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
124125
showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"];
125126
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState;
126127

128+
// Toggle Black & White Text
129+
NSMenuItem *colorTextSubmenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"White Text Color", @"White Text Color") action:@selector(toggleTextColor:) keyEquivalent:@""];
130+
[colorTextSubmenuItem setTag:kBTRMenuWhiteText];
131+
colorTextSubmenuItem.target = self;
132+
whiteText = [[NSUserDefaults standardUserDefaults] boolForKey:@"whiteText"];
133+
colorTextSubmenuItem.state = (whiteText) ? NSOnState : NSOffState;
134+
127135
// Build the setting submenu
128136
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
129137
[settingSubmenu addItem:advancedSubmenuItem];
130138
[settingSubmenu addItem:parenthesisSubmenuItem];
139+
[settingSubmenu addItem:colorTextSubmenuItem];
131140

132141
// Settings menu item
133142
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
@@ -363,11 +372,18 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
363372
[self.statusItem setAlternateImage:[ImageFilter invertColor:image]];
364373

365374
// Title
366-
NSDictionary *attributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
367-
// Font
368-
[NSFont menuFontOfSize:12.0f],
369-
NSFontAttributeName,
370-
nil];
375+
NSMutableDictionary *attributedStyle = [NSMutableDictionary dictionaryWithObjectsAndKeys:
376+
// Font
377+
[NSFont menuFontOfSize:12.0f],
378+
NSFontAttributeName,
379+
nil];
380+
381+
if(whiteText) {
382+
[attributedStyle setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
383+
} else {
384+
[attributedStyle setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
385+
}
386+
371387

372388
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributedStyle];
373389
self.statusItem.attributedTitle = attributedTitle;
@@ -572,6 +588,27 @@ - (void)toggleParenthesis:(id)sender
572588
[self updateStatusItem];
573589
}
574590

591+
- (void)toggleTextColor:(id)sender {
592+
NSMenuItem *item = sender;
593+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
594+
595+
if ([defaults boolForKey:@"whiteText"])
596+
{
597+
item.state = NSOffState;
598+
whiteText = NO;
599+
[defaults setBool:NO forKey:@"whiteText"];
600+
}
601+
else
602+
{
603+
item.state = NSOnState;
604+
whiteText = YES;
605+
[defaults setBool:YES forKey:@"whiteText"];
606+
}
607+
[defaults synchronize];
608+
609+
[self updateStatusItem];
610+
}
611+
575612
- (void)notify:(NSString *)message
576613
{
577614
[self notify:@"Battery Time Remaining" message:message];

0 commit comments

Comments
 (0)