Browse Source

Fix colored menu bar icon invisibility in dark mode

Thomas Buck 8 years ago
parent
commit
e6c50edf78
2 changed files with 21 additions and 5 deletions
  1. 20
    4
      CaseLights/AppDelegate.m
  2. 1
    1
      CaseLights/Info.plist

+ 20
- 4
CaseLights/AppDelegate.m View File

@@ -62,6 +62,7 @@
62 62
 #define MENU_ITEM_TAG_NOTHING -1
63 63
 #define MENU_ITEM_TAG_AUDIO -2
64 64
 
65
+// Define this to color the status bar icon according to the current RGB LED value
65 66
 #define COLORED_MENU_BAR_ICON
66 67
 
67 68
 @interface AppDelegate ()
@@ -116,12 +117,27 @@
116 117
     NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
117 118
     
118 119
     NSImage *copiedImage = [image copy];
120
+    NSColor *copiedTint = [tint copy];
121
+    
122
+    // Fix colors for different interface styles
123
+    NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
124
+    CGFloat r, g, b, a;
125
+    [copiedTint getRed:&r green:&g blue:&b alpha:&a];
126
+    if ((osxMode != nil) && ([osxMode isEqualToString:@"Dark"])) {
127
+        // Dark mode
128
+        if ((r < 0.001f) && (g < 0.001f) && (b < 0.001f)) {
129
+            copiedTint = [NSColor whiteColor];
130
+        }
131
+    } else {
132
+        // Normal mode
133
+        if ((r > 0.999f) && (g > 0.999f) && (b > 0.999f)) {
134
+            copiedTint = [NSColor blackColor];
135
+        }
136
+    }
119 137
     
120 138
     [copiedImage lockFocus];
121
-    
122
-    [tint set];
139
+    [copiedTint set];
123 140
     NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
124
-    
125 141
     [copiedImage unlockFocus];
126 142
     
127 143
     return copiedImage;
@@ -141,7 +157,7 @@
141 157
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
142 158
 #ifdef COLORED_MENU_BAR_ICON
143 159
     [statusImage setTemplate:NO];
144
-    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor blackColor]]];
160
+    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]];
145 161
 #else
146 162
     [statusImage setTemplate:YES];
147 163
     [statusItem setImage:statusImage];

+ 1
- 1
CaseLights/Info.plist View File

@@ -21,7 +21,7 @@
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>405</string>
24
+	<string>408</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

Loading…
Cancel
Save