Skip to content

Commit

Permalink
Fix #22, state after reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
codler committed Sep 26, 2012
1 parent 4d0ce73 commit 28443a6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,22 @@ - (void)updateStatusItem

NSString *psState = CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey));

psState = ([psState isEqualToString:(NSString *)CFSTR(kIOPSBatteryPowerValue)]) ?
NSLocalizedString(@"Battery Power", @"Powersource state") :
([psState isEqualToString:(NSString *)CFSTR(kIOPSACPowerValue)]) ?
NSLocalizedString(@"AC Power", @"Powersource state") :
NSLocalizedString(@"Off Line", @"Powersource state");
NSString *psStateTranslated = ([psState isEqualToString:(NSString *)CFSTR(kIOPSBatteryPowerValue)]) ?
NSLocalizedString(@"Battery Power", @"Powersource state") :
([psState isEqualToString:(NSString *)CFSTR(kIOPSACPowerValue)]) ?
NSLocalizedString(@"AC Power", @"Powersource state") :
NSLocalizedString(@"Off Line", @"Powersource state");

[self.statusItem.menu itemWithTag:kBTRMenuPowerSourceState].title = [NSString stringWithFormat:NSLocalizedString(@"Power source: %@", @"Powersource menuitem"), psState];
[self.statusItem.menu itemWithTag:kBTRMenuPowerSourceState].title = [NSString stringWithFormat:NSLocalizedString(@"Power source: %@", @"Powersource menuitem"), psStateTranslated];

// Still calculating the estimated time remaining...
// Fixes #22 - state after reboot
if ([psState isEqualToString:(NSString *)CFSTR(kIOPSBatteryPowerValue)] && CFDictionaryGetValue(description, CFSTR(kIOPSIsChargingKey)) == kCFBooleanFalse && (kIOPSTimeRemainingUnknown == timeRemaining || kIOPSTimeRemainingUnlimited == timeRemaining))
{
[self setStatusBarImage:[self getBatteryIconPercent:self.currentPercent] title:[NSString stringWithFormat:@" %@", NSLocalizedString(@"Calculating…", @"Calculating sidetext")]];
}
// We're connected to an unlimited power source (AC adapter probably)
if (kIOPSTimeRemainingUnlimited == timeRemaining)
else if (kIOPSTimeRemainingUnlimited == timeRemaining)
{
// Check if the battery is charging atm
if (CFDictionaryGetValue(description, CFSTR(kIOPSIsChargingKey)) == kCFBooleanTrue)
Expand Down Expand Up @@ -263,11 +269,6 @@ - (void)updateStatusItem
}

}
// Still calculating the estimated time remaining...
else if (kIOPSTimeRemainingUnknown == timeRemaining)
{
[self setStatusBarImage:[self getBatteryIconPercent:self.currentPercent] title:[NSString stringWithFormat:@" %@", NSLocalizedString(@"Calculating…", @"Calculating sidetext")]];
}
// Time is known!
else
{
Expand Down

0 comments on commit 28443a6

Please sign in to comment.