Skip to content

Commit fa6e570

Browse files
committed
Fix #51, option to hide icon and fix #55, option to show as per cent
1 parent 8e848bf commit fa6e570

File tree

8 files changed

+106
-30
lines changed

8 files changed

+106
-30
lines changed

Battery Time Remaining.xcodeproj/project.pbxproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
2822133616369BB70019A3EE /* ko */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
6060
2824FFEF1611A5D500CD3140 /* zh-Hans */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
6161
28369FFA15EE902E005957A0 /* sk */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Localizable.strings; sourceTree = "<group>"; };
62-
2841C7DC15C91CC100F4F15F /* Battery Time Remaining.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Battery Time Remaining.app"; sourceTree = BUILT_PRODUCTS_DIR; };
62+
2841C7DC15C91CC100F4F15F /* Battery Time 2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Battery Time 2.app"; sourceTree = BUILT_PRODUCTS_DIR; };
6363
2841C7E015C91CC100F4F15F /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
6464
2841C7E315C91CC100F4F15F /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
6565
2841C7E415C91CC100F4F15F /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
@@ -125,7 +125,7 @@
125125
2841C7DD15C91CC100F4F15F /* Products */ = {
126126
isa = PBXGroup;
127127
children = (
128-
2841C7DC15C91CC100F4F15F /* Battery Time Remaining.app */,
128+
2841C7DC15C91CC100F4F15F /* Battery Time 2.app */,
129129
);
130130
name = Products;
131131
sourceTree = "<group>";
@@ -155,15 +155,15 @@
155155
2841C7E615C91CC100F4F15F /* Battery Time Remaining */ = {
156156
isa = PBXGroup;
157157
children = (
158-
28FEDA6215DA5EB200320B72 /* LLManager.h */,
159-
28FEDA6315DA5EB200320B72 /* LLManager.m */,
160-
28FEDA6415DA5EB200320B72 /* LLStrings.h */,
161158
2841C7F215C91CC100F4F15F /* AppDelegate.h */,
162-
28527E561622E8A800EE3644 /* ImageFilter.h */,
163-
28527E571622E8A800EE3644 /* ImageFilter.m */,
164159
2841C7F315C91CC100F4F15F /* AppDelegate.m */,
165160
28833BAC15D7B90B00741727 /* HttpGet.h */,
166161
28833BAD15D7B90B00741727 /* HttpGet.m */,
162+
28527E561622E8A800EE3644 /* ImageFilter.h */,
163+
28527E571622E8A800EE3644 /* ImageFilter.m */,
164+
28FEDA6215DA5EB200320B72 /* LLManager.h */,
165+
28FEDA6315DA5EB200320B72 /* LLManager.m */,
166+
28FEDA6415DA5EB200320B72 /* LLStrings.h */,
167167
2841C7E715C91CC100F4F15F /* Supporting Files */,
168168
);
169169
path = "Battery Time Remaining";
@@ -212,7 +212,7 @@
212212
);
213213
name = "Battery Time Remaining";
214214
productName = "Battery Time Remaining";
215-
productReference = 2841C7DC15C91CC100F4F15F /* Battery Time Remaining.app */;
215+
productReference = 2841C7DC15C91CC100F4F15F /* Battery Time 2.app */;
216216
productType = "com.apple.product-type.application";
217217
};
218218
/* End PBXNativeTarget section */
@@ -397,7 +397,7 @@
397397
GCC_PRECOMPILE_PREFIX_HEADER = YES;
398398
GCC_PREFIX_HEADER = "Battery Time Remaining/Battery Time Remaining-Prefix.pch";
399399
INFOPLIST_FILE = "Battery Time Remaining/Battery Time Remaining-Info.plist";
400-
PRODUCT_NAME = "$(TARGET_NAME)";
400+
PRODUCT_NAME = "Battery Time 2";
401401
PROVISIONING_PROFILE = "";
402402
WRAPPER_EXTENSION = app;
403403
};
@@ -412,7 +412,7 @@
412412
GCC_PRECOMPILE_PREFIX_HEADER = YES;
413413
GCC_PREFIX_HEADER = "Battery Time Remaining/Battery Time Remaining-Prefix.pch";
414414
INFOPLIST_FILE = "Battery Time Remaining/Battery Time Remaining-Info.plist";
415-
PRODUCT_NAME = "$(TARGET_NAME)";
415+
PRODUCT_NAME = "Battery Time 2";
416416
PROVISIONING_PROFILE = "";
417417
WRAPPER_EXTENSION = app;
418418
};

Battery Time Remaining/AppDelegate.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#define kBTRMenuAdvanced 7
2121
#define kBTRMenuParenthesis 8
2222
#define kBTRMenuFahrenheit 9
23-
#define kBTRMenuWhiteText 10
24-
#define kBTRMenuEnergySaverSetting 11
25-
#define kBTRMenuUpdater 12
26-
#define kBTRMenuQuitKey 13
23+
#define kBTRMenuPercentage 10
24+
#define kBTRMenuWhiteText 11
25+
#define kBTRMenuHideIcon 12
26+
#define kBTRMenuEnergySaverSetting 13
27+
#define kBTRMenuUpdater 14
28+
#define kBTRMenuQuitKey 15
2729

2830
#endif
2931

Battery Time Remaining/AppDelegate.m

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ @interface AppDelegate ()
4343
BOOL isCapacityWarning;
4444
BOOL showParenthesis;
4545
BOOL showFahrenheit;
46+
BOOL showPercentage;
4647
BOOL showWhiteText;
48+
BOOL hideIcon;
4749
}
4850

4951
- (void)cacheBatteryIcon;
@@ -130,27 +132,43 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
130132
showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"];
131133
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState;
132134

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:@""];
135137
[fahrenheitSubmenuItem setTag:kBTRMenuFahrenheit];
136138
fahrenheitSubmenuItem.target = self;
137139
showFahrenheit = [[NSUserDefaults standardUserDefaults] boolForKey:@"fahrenheit"];
138140
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;
139148

140149
// 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:@""];
142151
[whiteTextSubmenuItem setTag:kBTRMenuWhiteText];
143152
whiteTextSubmenuItem.target = self;
144153
showWhiteText = [[NSUserDefaults standardUserDefaults] boolForKey:@"whiteText"];
145154
whiteTextSubmenuItem.state = (showWhiteText) ? NSOnState : NSOffState;
146155

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+
147163
// Build the setting submenu
148164
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
149165
[settingSubmenu addItem:advancedSubmenuItem];
150166
[settingSubmenu addItem:parenthesisSubmenuItem];
151167
[settingSubmenu addItem:fahrenheitSubmenuItem];
168+
[settingSubmenu addItem:percentageSubmenuItem];
152169
[settingSubmenu addItem:whiteTextSubmenuItem];
153-
170+
[settingSubmenu addItem:hideIconSubmenuItem];
171+
154172
// Settings menu item
155173
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
156174
[settingMenu setTag:kBTRMenuSetting];
@@ -437,9 +455,17 @@ - (void)updateStatusItemMenu
437455
- (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
438456
{
439457
// 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+
}
443469

444470
// Title
445471
NSMutableDictionary *attributedStyle = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -457,6 +483,10 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
457483
[attributedStyle setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
458484
}
459485

486+
if (showPercentage)
487+
{
488+
title = [NSString stringWithFormat:@"%ld %%", self.currentPercent];
489+
}
460490

461491
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributedStyle];
462492
self.statusItem.attributedTitle = attributedTitle;
@@ -582,7 +612,7 @@ - (void)openHomeUrl:(id)sender
582612

583613
- (void)openMacAppStore:(id)sender
584614
{
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"]];
586616
}
587617

588618
- (void)promptAutoUpdate:(id)sender
@@ -683,6 +713,28 @@ - (void)toggleFahrenheit:(id)sender
683713
[self updateStatusItem];
684714
}
685715

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+
686738
- (void)toggleWhiteText:(id)sender {
687739
NSMenuItem *item = sender;
688740
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
@@ -704,6 +756,28 @@ - (void)toggleWhiteText:(id)sender {
704756
[self updateStatusItem];
705757
}
706758

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+
707781
- (void)notify:(NSString *)message
708782
{
709783
[self notify:@"Battery Time Remaining" message:message];

Battery Time Remaining/Battery Time Remaining-Info.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
<key>CFBundleIconFile</key>
1010
<string>icon</string>
1111
<key>CFBundleIdentifier</key>
12-
<string>com.codler.${PRODUCT_NAME:rfc1034identifier}</string>
12+
<string>com.codler.Battery-Time-Remaining2</string>
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>
1616
<string>${PRODUCT_NAME}</string>
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.6.2</string>
20+
<string>2.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -26,15 +26,15 @@
2626
<key>CFBundleTypeRole</key>
2727
<string>Viewer</string>
2828
<key>CFBundleURLName</key>
29-
<string>com.codler.${PRODUCT_NAME:rfc1034identifier}</string>
29+
<string>com.codler.Battery-Time-Remaining2</string>
3030
<key>CFBundleURLSchemes</key>
3131
<array>
32-
<string>com.codler.Battery-Time-Remaining</string>
32+
<string>com.codler.Battery-Time-Remaining2</string>
3333
</array>
3434
</dict>
3535
</array>
3636
<key>CFBundleVersion</key>
37-
<string>13</string>
37+
<string>214</string>
3838
<key>LSApplicationCategoryType</key>
3939
<string>public.app-category.utilities</string>
4040
<key>LSHasLocalizedDisplayName</key>
314 Bytes
Binary file not shown.
770 Bytes
Binary file not shown.

LaunchAtLoginHelper/LLStrings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// strings used by LLManager and LaunchAtLoginHelper
22
//
33

4-
#define LLURLScheme @"com.codler.Battery-Time-Remaining"
5-
#define LLHelperBundleIdentifier @"com.codler.Battery-Time-Remaining-Helper"
4+
#define LLURLScheme @"com.codler.Battery-Time-Remaining2"
5+
#define LLHelperBundleIdentifier @"com.codler.Battery-Time-Remaining-Helper2"

LaunchAtLoginHelper/LaunchAtLoginHelper/LaunchAtLoginHelper-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<key>CFBundleIconFile</key>
1010
<string></string>
1111
<key>CFBundleIdentifier</key>
12-
<string>com.codler.Battery-Time-Remaining-Helper</string>
12+
<string>com.codler.Battery-Time-Remaining-Helper2</string>
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>

0 commit comments

Comments
 (0)