Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix dark mode

  • Loading branch information...
commit 80f351b3f9f4a37b6c319bcc2cb6ebe819542b76 1 parent 8288b4d
@codler authored
View
34 Battery Time Remaining/AppDelegate.m
@@ -39,6 +39,8 @@ @interface AppDelegate ()
NSString *previousState;
NSTimer *unpluggedTimer;
NSInteger unpluggedTimerCount;
+ BOOL isDarkMode;
+ BOOL isMenuOpen;
BOOL isOptionKeyPressed;
BOOL isCapacityWarning;
BOOL showParenthesis;
@@ -63,7 +65,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
self.advancedSupported = ([self getAdvancedBatteryInfo] != nil);
[self cacheBatteryIcon];
isCapacityWarning = NO;
-
+ isMenuOpen = NO;
+
+ // Observe Dark mode changes
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
+ [self updateDarkMode];
+
// Init notification
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
[self loadNotificationSetting];
@@ -470,7 +477,7 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
// Image
if (!hideIcon)
{
- [image setTemplate:!isCapacityWarning];
+ [image setTemplate:(isMenuOpen || !isCapacityWarning)];
[self.statusItem setImage:image];
}
else
@@ -572,6 +579,11 @@ - (NSImage *)getBatteryIconPercent:(NSInteger)percent
batteryLevelLeft = [self getBatteryIconNamed:@"BatteryLevelCapR-L"];
batteryLevelMiddle = [self getBatteryIconNamed:@"BatteryLevelCapR-M"];
batteryLevelRight = [self getBatteryIconNamed:@"BatteryLevelCapR-R"];
+
+ if (isDarkMode)
+ {
+ batteryOutline = [ImageFilter invertColor:batteryOutline];
+ }
}
const CGFloat drawingUnit = [batteryLevelLeft size].width;
@@ -884,6 +896,18 @@ - (double)convertCelsiusToFahrenheit:(double)celsius
return ((celsius * 9.0) / 5.0 + 32.0);
}
+- (void)updateDarkMode
+{
+ NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain];
+ id style = [dict objectForKey:@"AppleInterfaceStyle"];
+ isDarkMode = ( style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"] );
+}
+
+- (void)darkModeChanged:(NSNotification *)notif
+{
+ [self updateDarkMode];
+}
+
#pragma mark - NSUserNotificationCenterDelegate methods
// Force show notification
@@ -905,6 +929,9 @@ - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNot
- (void)menuWillOpen:(NSMenu *)menu
{
+ isMenuOpen = YES;
+ [self.statusItem.image setTemplate:YES];
+
[self updateStatusItemMenu];
// Detect instant if option key is pressed
@@ -967,6 +994,9 @@ - (void)menuWillOpen:(NSMenu *)menu
- (void)menuDidClose:(NSMenu *)menu
{
+ isMenuOpen = NO;
+ [self.statusItem.image setTemplate:!isCapacityWarning];
+
if ([[self.statusItem.menu itemWithTag:kBTRMenuSetting].submenu itemWithTag:kBTRMenuAdvanced].state == NSOffState)
{
[self showAdvanced:NO];
View
4 Battery Time Remaining/Battery Time Remaining-Info.plist
@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>3.0</string>
+ <string>3.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
@@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
- <string>300</string>
+ <string>301</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSHasLocalizedDisplayName</key>
View
1  Battery Time Remaining/ImageFilter.h
@@ -11,5 +11,6 @@
@interface ImageFilter : NSObject
+ (NSImage *)offset:(NSImage *)_image top:(CGFloat)top;
++ (NSImage *)invertColor:(NSImage *)_image;
@end
View
17 Battery Time Remaining/ImageFilter.m
@@ -27,4 +27,21 @@ + (NSImage *)offset:(NSImage *)_image top:(CGFloat)top
return newImage;
}
++ (NSImage *)invertColor:(NSImage *)_image
+{
+ NSImage *image = [_image copy];
+ [image lockFocus];
+
+ CIImage *ciImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]];
+ CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"];
+ [filter setDefaults];
+ [filter setValue:ciImage forKey:@"inputImage"];
+ CIImage *output = [filter valueForKey:@"outputImage"];
+ [output drawInRect:NSMakeRect(0, 0, [_image size].width, [_image size].height) fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0];
+
+ [image unlockFocus];
+
+ return image;
+}
+
@end
View
12 Readme.md
@@ -46,6 +46,18 @@ App icon provided by happytel.com free calling for all.
Change log
----------
+2014-10-28 - **v3.0.1** - [diff](https://github.com/codler/Battery-Time-Remaining/compare/v3.0...v3.0.1)
+
+* Fix dark mode ([codler](https://github.com/codler)
+
+2014-10-28 - **v1.7.1** - [diff](https://github.com/codler/Battery-Time-Remaining/compare/v1.7...v1.7.1)
+
+* Fix dark mode ([codler](https://github.com/codler)
+
+2014-10-18 - **v1.7** - [diff](https://github.com/codler/Battery-Time-Remaining/compare/v1.6.5...v1.7)
+
+* Added support for OS X 10.10 Yosemite ([codler](https://github.com/codler) [#89](https://github.com/codler/Battery-Time-Remaining/issues/89))
+
2014-10-17 - **v3.0** - [diff](https://github.com/codler/Battery-Time-Remaining/compare/v2.1...v3.0)
* Added support for OS X 10.10 Yosemite ([codler](https://github.com/codler) [#89](https://github.com/codler/Battery-Time-Remaining/issues/89))
View
2  build_version
@@ -1 +1 @@
-16
+18
View
2  build_version2
@@ -1 +1 @@
-300
+301
Please sign in to comment.
Something went wrong with that request. Please try again.