@@ -43,7 +43,9 @@ @interface AppDelegate ()
43
43
BOOL isCapacityWarning;
44
44
BOOL showParenthesis;
45
45
BOOL showFahrenheit;
46
+ BOOL showPercentage;
46
47
BOOL showWhiteText;
48
+ BOOL hideIcon;
47
49
}
48
50
49
51
- (void )cacheBatteryIcon ;
@@ -130,27 +132,43 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
130
132
showParenthesis = [[NSUserDefaults standardUserDefaults ] boolForKey: @" parentheses" ];
131
133
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState ;
132
134
133
- // Display in Fahrenheit menu item
134
- NSMenuItem *fahrenheitSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display temperature in Fahrenheit" , @" Display temperature in Fahrenheit setting" ) action: @selector (toggleFahrenheit: ) keyEquivalent: @" " ];
135
+ // Fahrenheit menu item
136
+ NSMenuItem *fahrenheitSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display Fahrenheit" , @" Display Fahrenheit setting" ) action: @selector (toggleFahrenheit: ) keyEquivalent: @" " ];
135
137
[fahrenheitSubmenuItem setTag: kBTRMenuFahrenheit ];
136
138
fahrenheitSubmenuItem.target = self;
137
139
showFahrenheit = [[NSUserDefaults standardUserDefaults ] boolForKey: @" fahrenheit" ];
138
140
fahrenheitSubmenuItem.state = (showFahrenheit) ? NSOnState : NSOffState ;
141
+
142
+ // Percentage menu item
143
+ NSMenuItem *percentageSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display percentage" , @" Display percentage setting" ) action: @selector (togglePercentage: ) keyEquivalent: @" " ];
144
+ [percentageSubmenuItem setTag: kBTRMenuPercentage ];
145
+ percentageSubmenuItem.target = self;
146
+ showPercentage = [[NSUserDefaults standardUserDefaults ] boolForKey: @" percentage" ];
147
+ percentageSubmenuItem.state = (showPercentage) ? NSOnState : NSOffState ;
139
148
140
149
// Toggle Black & White Text
141
- NSMenuItem *whiteTextSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display white text color " , @" Display white text color " ) action: @selector (toggleWhiteText: ) keyEquivalent: @" " ];
150
+ NSMenuItem *whiteTextSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Display white text" , @" Display white text" ) action: @selector (toggleWhiteText: ) keyEquivalent: @" " ];
142
151
[whiteTextSubmenuItem setTag: kBTRMenuWhiteText ];
143
152
whiteTextSubmenuItem.target = self;
144
153
showWhiteText = [[NSUserDefaults standardUserDefaults ] boolForKey: @" whiteText" ];
145
154
whiteTextSubmenuItem.state = (showWhiteText) ? NSOnState : NSOffState ;
146
155
156
+ // Icon menu item
157
+ NSMenuItem *hideIconSubmenuItem = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Hide icon" , @" Hide icon setting" ) action: @selector (toggleHideIcon: ) keyEquivalent: @" " ];
158
+ [hideIconSubmenuItem setTag: kBTRMenuHideIcon ];
159
+ hideIconSubmenuItem.target = self;
160
+ hideIcon = [[NSUserDefaults standardUserDefaults ] boolForKey: @" hideIcon" ];
161
+ hideIconSubmenuItem.state = (hideIcon) ? NSOnState : NSOffState ;
162
+
147
163
// Build the setting submenu
148
164
NSMenu *settingSubmenu = [[NSMenu alloc ] initWithTitle: @" Setting Menu" ];
149
165
[settingSubmenu addItem: advancedSubmenuItem];
150
166
[settingSubmenu addItem: parenthesisSubmenuItem];
151
167
[settingSubmenu addItem: fahrenheitSubmenuItem];
168
+ [settingSubmenu addItem: percentageSubmenuItem];
152
169
[settingSubmenu addItem: whiteTextSubmenuItem];
153
-
170
+ [settingSubmenu addItem: hideIconSubmenuItem];
171
+
154
172
// Settings menu item
155
173
NSMenuItem *settingMenu = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" Settings" , @" Settings menuitem" ) action: nil keyEquivalent: @" " ];
156
174
[settingMenu setTag: kBTRMenuSetting ];
@@ -437,9 +455,17 @@ - (void)updateStatusItemMenu
437
455
- (void )setStatusBarImage : (NSImage *)image title : (NSString *)title
438
456
{
439
457
// Image
440
- [image setTemplate: ( ! isCapacityWarning)];
441
- [self .statusItem setImage: image];
442
- [self .statusItem setAlternateImage: [ImageFilter invertColor: image]];
458
+ if (!hideIcon)
459
+ {
460
+ [image setTemplate: ( ! isCapacityWarning)];
461
+ [self .statusItem setImage: image];
462
+ [self .statusItem setAlternateImage: [ImageFilter invertColor: image]];
463
+ }
464
+ else
465
+ {
466
+ [self .statusItem setImage: nil ];
467
+ [self .statusItem setAlternateImage: nil ];
468
+ }
443
469
444
470
// Title
445
471
NSMutableDictionary *attributedStyle = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -457,6 +483,10 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
457
483
[attributedStyle setObject: [NSColor blackColor ] forKey: NSForegroundColorAttributeName ];
458
484
}
459
485
486
+ if (showPercentage)
487
+ {
488
+ title = [NSString stringWithFormat: @" %ld %% " , self .currentPercent];
489
+ }
460
490
461
491
NSAttributedString *attributedTitle = [[NSAttributedString alloc ] initWithString: title attributes: attributedStyle];
462
492
self.statusItem .attributedTitle = attributedTitle;
@@ -582,7 +612,7 @@ - (void)openHomeUrl:(id)sender
582
612
583
613
- (void )openMacAppStore : (id )sender
584
614
{
585
- [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" macappstore://itunes.apple.com/app/id551420833 ?mt=12" ]];
615
+ [[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: @" macappstore://itunes.apple.com/app/id665678267 ?mt=12" ]];
586
616
}
587
617
588
618
- (void )promptAutoUpdate : (id )sender
@@ -683,6 +713,28 @@ - (void)toggleFahrenheit:(id)sender
683
713
[self updateStatusItem ];
684
714
}
685
715
716
+ - (void )togglePercentage : (id )sender
717
+ {
718
+ NSMenuItem *item = sender;
719
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
720
+
721
+ if ([defaults boolForKey: @" percentage" ])
722
+ {
723
+ item.state = NSOffState ;
724
+ showPercentage = NO ;
725
+ [defaults setBool: NO forKey: @" percentage" ];
726
+ }
727
+ else
728
+ {
729
+ item.state = NSOnState ;
730
+ showPercentage = YES ;
731
+ [defaults setBool: YES forKey: @" percentage" ];
732
+ }
733
+ [defaults synchronize ];
734
+
735
+ [self updateStatusItem ];
736
+ }
737
+
686
738
- (void )toggleWhiteText : (id )sender {
687
739
NSMenuItem *item = sender;
688
740
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
@@ -704,6 +756,28 @@ - (void)toggleWhiteText:(id)sender {
704
756
[self updateStatusItem ];
705
757
}
706
758
759
+ - (void )toggleHideIcon : (id )sender
760
+ {
761
+ NSMenuItem *item = sender;
762
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
763
+
764
+ if ([defaults boolForKey: @" hideIcon" ])
765
+ {
766
+ item.state = NSOffState ;
767
+ hideIcon = NO ;
768
+ [defaults setBool: NO forKey: @" hideIcon" ];
769
+ }
770
+ else
771
+ {
772
+ item.state = NSOnState ;
773
+ hideIcon = YES ;
774
+ [defaults setBool: YES forKey: @" hideIcon" ];
775
+ }
776
+ [defaults synchronize ];
777
+
778
+ [self updateStatusItem ];
779
+ }
780
+
707
781
- (void )notify : (NSString *)message
708
782
{
709
783
[self notify: @" Battery Time Remaining" message: message];
0 commit comments