소스 검색

run-time option for icon colorization

Thomas Buck 9 년 전
부모
커밋
fe0dc0986c
3개의 변경된 파일53개의 추가작업 그리고 24개의 파일을 삭제
  1. 45
    23
      CaseLights/AppDelegate.m
  2. 7
    0
      CaseLights/Base.lproj/MainMenu.xib
  3. 1
    1
      CaseLights/Info.plist

+ 45
- 23
CaseLights/AppDelegate.m 파일 보기

@@ -20,6 +20,7 @@
20 20
 #define PREF_BRIGHTNESS @"Brightness"
21 21
 #define PREF_COLOR @"ManualColor"
22 22
 #define PREF_SENSITIVITY @"Sensitivity"
23
+#define PREF_COLORED_ICON @"ColorizeIcon"
23 24
 
24 25
 #define TEXT_MANUAL @"Select..."
25 26
 #define TEXT_CPU_USAGE @"CPU Usage"
@@ -62,9 +63,6 @@
62 63
 #define MENU_ITEM_TAG_NOTHING -1
63 64
 #define MENU_ITEM_TAG_AUDIO -2
64 65
 
65
-// Define this to color the status bar icon according to the current RGB LED value
66
-#define COLORED_MENU_BAR_ICON
67
-
68 66
 @interface AppDelegate ()
69 67
 
70 68
 @property (weak) IBOutlet NSMenu *statusMenu;
@@ -86,6 +84,7 @@
86 84
 @property (weak) IBOutlet NSSlider *sensitivitySlider;
87 85
 @property (weak) IBOutlet NSMenuItem *sensitivityLabel;
88 86
 @property (weak) IBOutlet NSMenuItem *sensitivityMenu;
87
+@property (weak) IBOutlet NSMenuItem *colorizeIconItem;
89 88
 
90 89
 @property (strong) NSMenuItem *menuItemColor;
91 90
 
@@ -110,7 +109,7 @@
110 109
 @synthesize statusItem, statusImage;
111 110
 @synthesize staticColors, animation;
112 111
 @synthesize serial, lastLEDMode, microphone;
113
-@synthesize menuItemColor;
112
+@synthesize menuItemColor, colorizeIconItem;
114 113
 
115 114
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
116 115
     srand((unsigned)time(NULL));
@@ -121,18 +120,7 @@
121 120
     animation = nil;
122 121
     microphone = nil;
123 122
     
124
-    // Prepare status bar menu
125
-    statusImage = [NSImage imageNamed:@"MenuIcon"];
126
-    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
127
-#ifdef COLORED_MENU_BAR_ICON
128
-    [statusImage setTemplate:NO];
129
-    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]];
130 123
     [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
131
-#else
132
-    [statusImage setTemplate:YES];
133
-    [statusItem setImage:statusImage];
134
-#endif
135
-    [statusItem setMenu:statusMenu];
136 124
     
137 125
     // Set default configuration values, load existing ones
138 126
     NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
@@ -141,6 +129,7 @@
141 129
     [appDefaults setObject:@"" forKey:PREF_LED_MODE];
142 130
     [appDefaults setObject:[NSNumber numberWithFloat:50.0] forKey:PREF_BRIGHTNESS];
143 131
     [appDefaults setObject:[NSNumber numberWithFloat:100.0] forKey:PREF_SENSITIVITY];
132
+    [appDefaults setObject:[NSNumber numberWithBool:YES] forKey:PREF_COLORED_ICON];
144 133
     [store registerDefaults:appDefaults];
145 134
     [store synchronize];
146 135
     NSString *savedPort = [store stringForKey:PREF_SERIAL_PORT];
@@ -153,6 +142,21 @@
153 142
     if (lastColorData != nil) {
154 143
         lastColor = (NSColor *)[NSUnarchiver unarchiveObjectWithData:lastColorData];
155 144
     }
145
+    BOOL coloredIcon = [store boolForKey:PREF_COLORED_ICON];
146
+    
147
+    // Prepare status bar menu
148
+    statusImage = [NSImage imageNamed:@"MenuIcon"];
149
+    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
150
+    if (coloredIcon == YES) {
151
+        [statusImage setTemplate:NO];
152
+        [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]];
153
+        [colorizeIconItem setState:NSOnState];
154
+    } else {
155
+        [statusImage setTemplate:YES];
156
+        [statusItem setImage:statusImage];
157
+        [colorizeIconItem setState:NSOffState];
158
+    }
159
+    [statusItem setMenu:statusMenu];
156 160
     
157 161
     // Prepare brightness menu
158 162
     brightnessItem.view = brightnessSlider;
@@ -471,9 +475,27 @@
471 475
 #endif
472 476
     }
473 477
     
474
-#ifdef COLORED_MENU_BAR_ICON
475
-    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]]];
476
-#endif
478
+    if (colorizeIconItem.state == NSOnState) {
479
+        [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]]];
480
+    }
481
+}
482
+
483
+- (IBAction)colorizeIconSelected:(NSMenuItem *)sender {
484
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
485
+    if ([sender state] == NSOffState) {
486
+        // Colorize icon
487
+        [statusImage setTemplate:NO];
488
+        [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.0f alpha:1.0f]]];
489
+        [colorizeIconItem setState:NSOnState];
490
+        [store setObject:[NSNumber numberWithBool:YES] forKey:PREF_COLORED_ICON];
491
+    } else {
492
+        // Don't colorize icon
493
+        [statusImage setTemplate:YES];
494
+        [statusItem setImage:statusImage];
495
+        [colorizeIconItem setState:NSOffState];
496
+        [store setObject:[NSNumber numberWithBool:NO] forKey:PREF_COLORED_ICON];
497
+    }
498
+    [store synchronize];
477 499
 }
478 500
 
479 501
 - (IBAction)relistSerialPorts:(id)sender {
@@ -934,11 +956,13 @@
934 956
     [application orderFrontStandardAboutPanel:self];
935 957
 }
936 958
 
937
-#ifdef COLORED_MENU_BAR_ICON
938 959
 - (void)darkModeChanged:(NSNotification *)notification {
939
-    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:nil]];
960
+    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
961
+    BOOL colorize = [store boolForKey:PREF_COLORED_ICON];
962
+    if (colorize == YES) {
963
+        [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:nil]];
964
+    }
940 965
 }
941
-#endif
942 966
 
943 967
 // ------------------------------------------------------
944 968
 // ----------------- Microphone Delegate ----------------
@@ -1165,7 +1189,6 @@
1165 1189
 // --------------------- Utilities ---------------------
1166 1190
 // -----------------------------------------------------
1167 1191
 
1168
-#ifdef COLORED_MENU_BAR_ICON
1169 1192
 + (NSImage *)tintedImage:(NSImage *)image WithColor:(NSColor *)tint {
1170 1193
     NSSize size = [image size];
1171 1194
     NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
@@ -1217,7 +1240,6 @@
1217 1240
     
1218 1241
     return copiedImage;
1219 1242
 }
1220
-#endif
1221 1243
 
1222 1244
 + (double)map:(double)val FromMin:(double)fmin FromMax:(double)fmax ToMin:(double)tmin ToMax:(double)tmax {
1223 1245
     double norm = (val - fmin) / (fmax - fmin);

+ 7
- 0
CaseLights/Base.lproj/MainMenu.xib 파일 보기

@@ -20,6 +20,7 @@
20 20
                 <outlet property="brightnessSlider" destination="axk-la-AqI" id="J4R-Mw-KN7"/>
21 21
                 <outlet property="buttonLights" destination="tLQ-BA-kGu" id="FZv-Ju-l7n"/>
22 22
                 <outlet property="buttonOff" destination="gT4-tm-Hvn" id="EEv-lf-Qo7"/>
23
+                <outlet property="colorizeIconItem" destination="F4i-Jg-lxm" id="TIi-7F-Pxz"/>
23 24
                 <outlet property="menuAnimations" destination="FJm-ND-abA" id="iGI-Hg-tms"/>
24 25
                 <outlet property="menuAudio" destination="KUj-jy-iwd" id="ct3-CS-KXG"/>
25 26
                 <outlet property="menuColors" destination="ZKz-ek-t6c" id="B2S-fy-Ca6"/>
@@ -761,6 +762,12 @@
761 762
                         <action selector="relistSerialPorts:" target="Voe-Tx-rLC" id="iFU-PL-xR8"/>
762 763
                     </connections>
763 764
                 </menuItem>
765
+                <menuItem title="Colorize Icon" id="F4i-Jg-lxm">
766
+                    <modifierMask key="keyEquivalentModifierMask"/>
767
+                    <connections>
768
+                        <action selector="colorizeIconSelected:" target="Voe-Tx-rLC" id="CC5-K4-QIW"/>
769
+                    </connections>
770
+                </menuItem>
764 771
                 <menuItem title="About CaseLights" id="GeK-ey-XEn">
765 772
                     <modifierMask key="keyEquivalentModifierMask"/>
766 773
                     <connections>

+ 1
- 1
CaseLights/Info.plist 파일 보기

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

Loading…
취소
저장