Permalink
Browse files

#79 Notifications while charging

  • Loading branch information...
1 parent 2ab697d commit ddb2536c1df9924d62588a449306d82f76e10b65 @codler committed Jan 2, 2014
Showing with 16 additions and 9 deletions.
  1. +16 −9 Battery Time Remaining/AppDelegate.m
@@ -324,6 +324,17 @@ - (void)updateStatusItem
// Return the time remaining string
[self setStatusBarImage:[self getBatteryIconNamed:@"BatteryCharging"] title:[NSString stringWithFormat:title, hour, minute]];
+
+ // Send notification once
+ if (self.previousPercent != self.currentPercent)
+ {
+ if ([[self.notifications valueForKey:[@(self.currentPercent) stringValue]] boolValue] && self.currentPercent >= 50)
+ {
+ [self notify:NSLocalizedString(@"Battery Time Remaining", "Battery Time Remaining notification") message:[NSString stringWithFormat:NSLocalizedString(@"%1$ld:%2$02ld left (%3$ld%%)", @"Time remaining left notification"), hour, minute, self.currentPercent]];
+ }
+ self.previousPercent = self.currentPercent;
+ }
+
}
else
{
@@ -362,19 +373,15 @@ - (void)updateStatusItem
// Return the time remaining string
[self setStatusBarImage:[self getBatteryIconPercent:self.currentPercent] title:[NSString stringWithFormat:title, hour, minute]];
- for (NSString *key in self.notifications)
+ // Send notification once
+ if (self.previousPercent != self.currentPercent)
{
- if ([[self.notifications valueForKey:key] boolValue] && [key intValue] == self.currentPercent)
+ if ([[self.notifications valueForKey:[@(self.currentPercent) stringValue]] boolValue] && self.currentPercent <= 50)
{
- // Send notification once
- if (self.previousPercent != self.currentPercent)
- {
- [self notify:NSLocalizedString(@"Battery Time Remaining", "Battery Time Remaining notification") message:[NSString stringWithFormat:NSLocalizedString(@"%1$ld:%2$02ld left (%3$ld%%)", @"Time remaining left notification"), hour, minute, self.currentPercent]];
- }
- break;
+ [self notify:NSLocalizedString(@"Battery Time Remaining", "Battery Time Remaining notification") message:[NSString stringWithFormat:NSLocalizedString(@"%1$ld:%2$02ld left (%3$ld%%)", @"Time remaining left notification"), hour, minute, self.currentPercent]];
}
+ self.previousPercent = self.currentPercent;
}
- self.previousPercent = self.currentPercent;
}
}

0 comments on commit ddb2536

Please sign in to comment.