Skip to content

Commit 4eb8f4d

Browse files
committed
Add option to display temperature in degrees Fahrenheit
1 parent 895e958 commit 4eb8f4d

File tree

15 files changed

+40
-2
lines changed

15 files changed

+40
-2
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 kBTRMenuFahrenheit 12
2526

2627
#endif
2728

Battery Time Remaining/AppDelegate.m

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

4445
- (void)cacheBatteryIcon;
4546
- (NSImage *)loadBatteryIconNamed:(NSString *)iconName;
47+
- (double)convertCelsiusToFahrenheit:(double)celsius;
4648

4749
@end
4850

@@ -123,11 +125,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
123125
parenthesisSubmenuItem.target = self;
124126
showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"];
125127
parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState;
128+
129+
// Display in Fahrenheit menu item
130+
NSMenuItem *displayFahrenheitSubmenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Display temperature in degrees Fahrenheit", @"Display temperature in Fahrenheit setting") action:@selector(toggleFahrenheit:) keyEquivalent:@""];
131+
[displayFahrenheitSubmenuItem setTag:kBTRMenuFahrenheit];
132+
displayFahrenheitSubmenuItem.target = self;
133+
displayFahrenheit = [[NSUserDefaults standardUserDefaults] boolForKey:@"fahrenheit"];
134+
displayFahrenheitSubmenuItem.state = (displayFahrenheit) ? NSOnState : NSOffState;
126135

127136
// Build the setting submenu
128137
NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"];
129138
[settingSubmenu addItem:advancedSubmenuItem];
130139
[settingSubmenu addItem:parenthesisSubmenuItem];
140+
[settingSubmenu addItem:displayFahrenheitSubmenuItem];
131141

132142
// Settings menu item
133143
NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""];
@@ -328,11 +338,11 @@ - (void)updateStatusItemMenu
328338

329339
[self.statusItem.menu itemWithTag:kBTRMenuPowerSourcePercent].title = [NSString stringWithFormat: NSLocalizedString(@"%ld %% left ( %ld/%ld mAh )", @"Advanced percentage left menuitem"), self.currentPercent, [currentBatteryPower integerValue], [maxBatteryPower integerValue]];
330340

331-
// Each item in array will be a row in menu
341+
// Each item in array will be a row in menu
332342
NSArray *advancedBatteryInfoTexts = [NSArray arrayWithObjects:
333343
[NSString stringWithFormat:NSLocalizedString(@"Cycle count: %ld", @"Advanced battery info menuitem"), [cycleCount integerValue]],
334344
[NSString stringWithFormat:NSLocalizedString(@"Power usage: %.2f Watt", @"Advanced battery info menuitem"), [watt doubleValue]],
335-
[NSString stringWithFormat:NSLocalizedString(@"Temperature: %.1f°C", @"Advanced battery info menuitem"), [temperature doubleValue]],
345+
(displayFahrenheit) ? [NSString stringWithFormat:NSLocalizedString(@"Temperature: %.1f°F", @"Advanced battery info menuitem"), [self convertCelsiusToFahrenheit:[temperature doubleValue]]] : [NSString stringWithFormat:NSLocalizedString(@"Temperature: %.1f°C", @"Advanced battery info menuitem"), [temperature doubleValue]],
336346
nil];
337347

338348
NSDictionary *advancedAttributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -572,6 +582,28 @@ - (void)toggleParenthesis:(id)sender
572582
[self updateStatusItem];
573583
}
574584

585+
- (void)toggleFahrenheit:(id)sender
586+
{
587+
NSMenuItem *item = sender;
588+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
589+
590+
if ([defaults boolForKey:@"fahrenheit"])
591+
{
592+
item.state = NSOffState;
593+
displayFahrenheit = NO;
594+
[defaults setBool:NO forKey:@"fahrenheit"];
595+
}
596+
else
597+
{
598+
item.state = NSOnState;
599+
displayFahrenheit = YES;
600+
[defaults setBool:YES forKey:@"fahrenheit"];
601+
}
602+
[defaults synchronize];
603+
604+
[self updateStatusItem];
605+
}
606+
575607
- (void)notify:(NSString *)message
576608
{
577609
[self notify:@"Battery Time Remaining" message:message];
@@ -647,6 +679,11 @@ - (void)optionKeyPressed
647679
}
648680
}
649681

682+
- (double)convertCelsiusToFahrenheit:(double)celsius
683+
{
684+
return ((celsius * 9.0) / 5.0 + 32.0);
685+
}
686+
650687
#pragma mark - NSUserNotificationCenterDelegate methods
651688

652689
// Force show notification
464 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.
480 Bytes
Binary file not shown.
482 Bytes
Binary file not shown.
476 Bytes
Binary file not shown.
394 Bytes
Binary file not shown.
468 Bytes
Binary file not shown.
482 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)