Browse Source

Fix colored menu bar icon invisibility in dark mode

Thomas Buck 9 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
 #define MENU_ITEM_TAG_NOTHING -1
62
 #define MENU_ITEM_TAG_NOTHING -1
63
 #define MENU_ITEM_TAG_AUDIO -2
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
 #define COLORED_MENU_BAR_ICON
66
 #define COLORED_MENU_BAR_ICON
66
 
67
 
67
 @interface AppDelegate ()
68
 @interface AppDelegate ()
116
     NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
117
     NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
117
     
118
     
118
     NSImage *copiedImage = [image copy];
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
     [copiedImage lockFocus];
138
     [copiedImage lockFocus];
121
-    
122
-    [tint set];
139
+    [copiedTint set];
123
     NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
140
     NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
124
-    
125
     [copiedImage unlockFocus];
141
     [copiedImage unlockFocus];
126
     
142
     
127
     return copiedImage;
143
     return copiedImage;
141
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
157
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
142
 #ifdef COLORED_MENU_BAR_ICON
158
 #ifdef COLORED_MENU_BAR_ICON
143
     [statusImage setTemplate:NO];
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
 #else
161
 #else
146
     [statusImage setTemplate:YES];
162
     [statusImage setTemplate:YES];
147
     [statusItem setImage:statusImage];
163
     [statusItem setImage:statusImage];

+ 1
- 1
CaseLights/Info.plist View File

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

Loading…
Cancel
Save