Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#65 See both time and percentage on status bar at the same time

  • Loading branch information...
commit 401e49bfc9e9329ec037fa44460215d2a009a2de 1 parent 299e073
@codler authored
View
7 Battery Time Remaining/AppDelegate.h
@@ -23,9 +23,10 @@
#define kBTRMenuPercentage 10
#define kBTRMenuWhiteText 11
#define kBTRMenuHideIcon 12
-#define kBTRMenuEnergySaverSetting 13
-#define kBTRMenuUpdater 14
-#define kBTRMenuQuitKey 15
+#define kBTRMenuHideTime 13
+#define kBTRMenuEnergySaverSetting 14
+#define kBTRMenuUpdater 15
+#define kBTRMenuQuitKey 16
#endif
View
55 Battery Time Remaining/AppDelegate.m
@@ -46,6 +46,7 @@ @interface AppDelegate ()
BOOL showPercentage;
BOOL showWhiteText;
BOOL hideIcon;
+ BOOL hideTime;
}
- (void)cacheBatteryIcon;
@@ -159,6 +160,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
hideIconSubmenuItem.target = self;
hideIcon = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideIcon"];
hideIconSubmenuItem.state = (hideIcon) ? NSOnState : NSOffState;
+
+ // Time menu item
+ NSMenuItem *hideTimeSubmenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Hide time", @"Hide time setting") action:@selector(toggleHideTime:) keyEquivalent:@""];
+ [hideTimeSubmenuItem setTag:kBTRMenuHideTime];
+ hideTimeSubmenuItem.target = self;
+ hideTime = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideTime"];
+ hideTimeSubmenuItem.state = (hideTime) ? NSOnState : NSOffState;
// Build the setting submenu
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
@@ -168,6 +176,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[settingSubmenu addItem:percentageSubmenuItem];
[settingSubmenu addItem:whiteTextSubmenuItem];
[settingSubmenu addItem:hideIconSubmenuItem];
+ [settingSubmenu addItem:hideTimeSubmenuItem];
// Settings menu item
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
@@ -454,6 +463,12 @@ - (void)updateStatusItemMenu
- (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
{
+ // Force show icon if no text
+ if (!showPercentage && hideTime)
+ {
+ hideIcon = NO;
+ }
+
// Image
if (!hideIcon)
{
@@ -487,9 +502,21 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
[attributedStyle setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
}
+ if (hideTime)
+ {
+ title = nil;
+ }
+
if (showPercentage)
{
- title = [NSString stringWithFormat:@"%ld %%", self.currentPercent];
+ if (title != nil)
+ {
+ title = [NSString stringWithFormat:@"%ld %% %@", self.currentPercent, title];
+ }
+ else
+ {
+ title = [NSString stringWithFormat:@"%ld %%", self.currentPercent];
+ }
}
if (title != nil)
@@ -501,6 +528,10 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
title = [NSString stringWithFormat:@" %@", title];
}
+ else
+ {
+ title = @"";
+ }
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributedStyle];
self.statusItem.attributedTitle = attributedTitle;
@@ -792,6 +823,28 @@ - (void)toggleHideIcon:(id)sender
[self updateStatusItem];
}
+- (void)toggleHideTime:(id)sender
+{
+ NSMenuItem *item = sender;
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ if ([defaults boolForKey:@"hideTime"])
+ {
+ item.state = NSOffState;
+ hideTime = NO;
+ [defaults setBool:NO forKey:@"hideTime"];
+ }
+ else
+ {
+ item.state = NSOnState;
+ hideTime = YES;
+ [defaults setBool:YES forKey:@"hideTime"];
+ }
+ [defaults synchronize];
+
+ [self updateStatusItem];
+}
+
- (void)notify:(NSString *)message
{
[self notify:@"Battery Time Remaining" message:message];
Please sign in to comment.
Something went wrong with that request. Please try again.