瀏覽代碼

Added basic SystemInfoKit support

Thomas Buck 9 年之前
父節點
當前提交
8a8e5666b4
共有 3 個文件被更改,包括 137 次插入2 次删除
  1. 135
    0
      CaseLights/AppDelegate.m
  2. 1
    1
      CaseLights/Info.plist
  3. 1
    1
      JSystemInfoKit

+ 135
- 0
CaseLights/AppDelegate.m 查看文件

@@ -10,6 +10,8 @@
10 10
 #import "Serial.h"
11 11
 #import "GPUStats.h"
12 12
 
13
+#import <SystemInfoKit/SystemInfoKit.h>
14
+
13 15
 #define PREF_SERIAL_PORT @"SerialPort"
14 16
 #define PREF_LIGHTS_STATE @"LightState"
15 17
 
@@ -77,6 +79,41 @@
77 79
         // TODO Enable item if it was last used
78 80
     }
79 81
     
82
+    // Check available temperatures and add menu items
83
+    JSKSMC *smc = [JSKSMC smc];
84
+    for (int i = 0; i < [[smc workingTempKeys] count]; i++) {
85
+        NSString *key = [smc.workingTempKeys objectAtIndex:i];
86
+        //NSString *name = [smc humanReadableNameForKey:key];
87
+        
88
+        //NSLog(@"%@: %@\n", key, name);
89
+        
90
+        if ([key isEqualToString:@"TC0D"]) {
91
+            NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"CPU Temperature" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
92
+            [menuVisualizations addItem:item];
93
+            
94
+            // TODO enable item if it was last used
95
+        }
96
+        
97
+        // TODO add GPU temperature item
98
+    }
99
+    
100
+    // Add CPU Usage menu item
101
+    NSMenuItem *cpuUsageItem = [[NSMenuItem alloc] initWithTitle:@"CPU Usage" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
102
+    [menuVisualizations addItem:cpuUsageItem];
103
+    
104
+    // TODO enable item if it was last used
105
+    
106
+    // Add Memory Usage item
107
+    NSMenuItem *memoryUsageItem = [[NSMenuItem alloc] initWithTitle:@"RAM Usage" action:@selector(selectedMemoryVisualization:) keyEquivalent:@""];
108
+    [menuVisualizations addItem:memoryUsageItem];
109
+    
110
+    // TODO enable item if it was last used
111
+    
112
+    JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
113
+    //JSKMCPUUsageInfo cpuUsageInfo = systemMonitor.cpuUsageInfo;
114
+    JSKMMemoryUsageInfo memoryUsageInfo = systemMonitor.memoryUsageInfo;
115
+    NSLog(@"Memory Usage: %lld Free, %lld Used, %lld Active, %lld Inactive, %lld Compressed, %lld Wired\n", memoryUsageInfo.freeMemory / 1000000, memoryUsageInfo.usedMemory / 1000000, memoryUsageInfo.activeMemory / 1000000, memoryUsageInfo.inactiveMemory / 1000000, memoryUsageInfo.compressedMemory / 1000000, memoryUsageInfo.wiredMemory / 1000000);
116
+    
80 117
     // Prepare serial port menu
81 118
     NSArray *ports = [Serial listSerialPorts];
82 119
     if ([ports count] > 0) {
@@ -153,11 +190,109 @@
153 190
 }
154 191
 
155 192
 - (void)selectedStaticColor:(NSMenuItem *)source {
193
+    // Turn off all other LED menu items
194
+    for (int i = 0; i < [menuColors numberOfItems]; i++) {
195
+        [[menuColors itemAtIndex:i] setState:NSOffState];
196
+    }
197
+    for (int i = 0; i < [menuAnimations numberOfItems]; i++) {
198
+        [[menuAnimations itemAtIndex:i] setState:NSOffState];
199
+    }
200
+    for (int i = 0; i < [menuVisualizations numberOfItems]; i++) {
201
+        [[menuVisualizations itemAtIndex:i] setState:NSOffState];
202
+    }
203
+    [buttonOff setState:NSOffState];
204
+    
205
+    // Turn on "off" menu item
206
+    [source setState:NSOnState];
156 207
     
208
+    // TODO store new selection
209
+    
210
+    // TODO send command
157 211
 }
158 212
 
159 213
 - (void)selectedGPUVisualization:(NSMenuItem *)sender {
214
+    // Turn off all other LED menu items
215
+    for (int i = 0; i < [menuColors numberOfItems]; i++) {
216
+        [[menuColors itemAtIndex:i] setState:NSOffState];
217
+    }
218
+    for (int i = 0; i < [menuAnimations numberOfItems]; i++) {
219
+        [[menuAnimations itemAtIndex:i] setState:NSOffState];
220
+    }
221
+    for (int i = 0; i < [menuVisualizations numberOfItems]; i++) {
222
+        [[menuVisualizations itemAtIndex:i] setState:NSOffState];
223
+    }
224
+    [buttonOff setState:NSOffState];
225
+    
226
+    if ([sender.title isEqualToString:@"GPU Usage"]) {
227
+        // Turn on "off" menu item
228
+        [sender setState:NSOnState];
229
+        
230
+        // TODO store new selection
231
+        
232
+        // TODO send command
233
+    } else if ([sender.title isEqualToString:@"VRAM Usage"]) {
234
+        // Turn on "off" menu item
235
+        [sender setState:NSOnState];
236
+        
237
+        // TODO store new selection
238
+        
239
+        // TODO send command
240
+    } else {
241
+        NSLog(@"Unknown GPU Visualization selected!\n");
242
+    }
243
+}
244
+
245
+- (void)selectedCPUVisualization:(NSMenuItem *)sender {
246
+    // Turn off all other LED menu items
247
+    for (int i = 0; i < [menuColors numberOfItems]; i++) {
248
+        [[menuColors itemAtIndex:i] setState:NSOffState];
249
+    }
250
+    for (int i = 0; i < [menuAnimations numberOfItems]; i++) {
251
+        [[menuAnimations itemAtIndex:i] setState:NSOffState];
252
+    }
253
+    for (int i = 0; i < [menuVisualizations numberOfItems]; i++) {
254
+        [[menuVisualizations itemAtIndex:i] setState:NSOffState];
255
+    }
256
+    [buttonOff setState:NSOffState];
257
+    
258
+    if ([sender.title isEqualToString:@"CPU Usage"]) {
259
+        // Turn on "off" menu item
260
+        [sender setState:NSOnState];
261
+        
262
+        // TODO store new selection
263
+        
264
+        // TODO send command
265
+    } else if ([sender.title isEqualToString:@"CPU Temperature"]) {
266
+        // Turn on "off" menu item
267
+        [sender setState:NSOnState];
268
+        
269
+        // TODO store new selection
270
+        
271
+        // TODO send command
272
+    } else {
273
+        NSLog(@"Unknown CPU Visualization selected!\n");
274
+    }
275
+}
276
+
277
+- (void)selectedMemoryVisualization:(NSMenuItem *)sender {
278
+    // Turn off all other LED menu items
279
+    for (int i = 0; i < [menuColors numberOfItems]; i++) {
280
+        [[menuColors itemAtIndex:i] setState:NSOffState];
281
+    }
282
+    for (int i = 0; i < [menuAnimations numberOfItems]; i++) {
283
+        [[menuAnimations itemAtIndex:i] setState:NSOffState];
284
+    }
285
+    for (int i = 0; i < [menuVisualizations numberOfItems]; i++) {
286
+        [[menuVisualizations itemAtIndex:i] setState:NSOffState];
287
+    }
288
+    [buttonOff setState:NSOffState];
289
+    
290
+    // Turn on "off" menu item
291
+    [sender setState:NSOnState];
292
+    
293
+    // TODO store new selection
160 294
     
295
+    // TODO send command
161 296
 }
162 297
 
163 298
 - (void)selectedSerialPort:(NSMenuItem *)source {

+ 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>43</string>
24
+	<string>52</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

+ 1
- 1
JSystemInfoKit

@@ -1 +1 @@
1
-Subproject commit 0e0ede0c5454708f5381f2bb954c266be1a4437e
1
+Subproject commit c1abc02fca1ee422b9b37030181adf2ef60e0498

Loading…
取消
儲存