@@ -10,7 +10,9 @@ import process;
10
10
/*DSG{{*/
11
11
mainForm = win.form(text="RunCat_with_aardio";right=296;bottom=263)
12
12
mainForm.add(
13
+ autoCat={cls="radiobutton";text="自动";left=200;top=43;right=262;bottom=65;dl=1;dt=1;z=5};
13
14
blackcat={cls="radiobutton";text="黑猫";left=114;top=43;right=176;bottom=65;dl=1;dt=1;z=4};
15
+ checkbox={cls="checkbox";text="加入windows启动项";left=9;top=226;right=158;bottom=252;db=1;dl=1;z=6};
14
16
cpuCheckFrequency={cls="edit";left=112;top=188;right=194;bottom=211;dl=1;dt=1;edge=1;num=1;tabstop=1;z=1};
15
17
static={cls="static";text="CPU检测频率(秒)";left=9;top=191;right=106;bottom=214;dl=1;dt=1;transparent=1;z=2};
16
18
whitecat={cls="radiobutton";text="白猫";left=24;top=43;right=86;bottom=65;checked=1;dl=1;dt=1;group=1;z=3}
@@ -52,7 +54,20 @@ _iconLib = {
52
54
}
53
55
}
54
56
/*}}*/
55
- var iconTab = config.system.whitecat ? _iconLib[1] : _iconLib[2];
57
+ var isLightTheme = function(){
58
+ import win.reg;
59
+ var v = win.reg.query("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme");
60
+ if v===null return true;
61
+ else return v==0 ? false : true;
62
+ }
63
+
64
+ var getIconIndex = function(){
65
+ if config.system.autoCat return isLightTheme() ? 2:1 ;
66
+ else return config.system.blackcat ? 2:1 ;
67
+ }
68
+
69
+ var iconTab = _iconLib[getIconIndex()];
70
+
56
71
57
72
/*创建托盘图标{{*/
58
73
var tray = win.util.tray(mainForm);
@@ -69,7 +84,6 @@ import console
69
84
console.open();
70
85
*/
71
86
72
-
73
87
_ANIMATE_DEFAULT_INTERVAL = 200;
74
88
75
89
@@ -92,13 +106,14 @@ cpuCheck_timer.onTimer = function(hwnd,msg,id,tick){
92
106
var ret, idleTime, kernelTime, userTime = GetSystemTimes(0, 0, 0);
93
107
var usage = 0;
94
108
if ret {
95
- var t = (idleTime + userTime - idleTime)/1000 /_coreNum;
109
+ var t = (idleTime + userTime - idleTime)/10000 /_coreNum;
96
110
table.push(cpuTms, t);
97
111
if #cpuTms > 2 table.shift(cpuTms);
98
112
if #cpuTms == 2 {
99
- var per = math.abs(cpuTms[2] - cpuTms[1]) / owner.getInterval() * 1000 ;
100
- usage = per * 100 /* _% */ / _Frequency /* cpu 使用率 是这么计算的吗? */;
113
+ var per = math.abs(cpuTms[2] - cpuTms[1]) / owner.getInterval() * 100 ;
114
+ usage = per * 100 * 100 /* _% */ / _Frequency /* cpu 使用率 是这么计算的吗? */;
101
115
}
116
+
102
117
}
103
118
if usage > 0 {
104
119
tray.tip = "CPU: " ++ math.round(usage, 1) ++ "%";
@@ -159,13 +174,29 @@ mainForm.blackcat.oncommand = function(id,event){
159
174
config.system.save();
160
175
iconTab = _iconLib[2];
161
176
}
162
-
177
+ mainForm.autoCat.oncommand = function(id,event){
178
+ if event !== 0/*_BN_CLICKED*/ return ;
179
+ config.system.save();
180
+ iconTab = _iconLib[(isLightTheme() ? 2:1)];
181
+ }
163
182
mainForm.cpuCheckFrequency.onModified = function(modified){
164
183
config.system.save();
165
184
cpuCheck_timer.setInterval(owner.text * 1000);
166
185
}
186
+ var setStartup = function(add = true){
187
+ if _STUDIO_INVOKED return ;
188
+ import win.reg;
189
+ var reg = win.reg("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run");
190
+ if add reg.setSzValue(config.__appName, '"' + io._exepath + '"' );
191
+ else reg.delKey(config.__appName);
192
+ reg.close();
193
+ }
194
+ mainForm.checkbox.oncommand = function(id,event){
195
+ if event !== 0/*_BN_CLICKED*/ return ;
196
+ setStartup(owner.checked);
197
+ }
167
198
168
- mainForm.show();
199
+ // mainForm.show();
169
200
170
201
iconBlink_timer.enable();
171
202
cpuCheck_timer.enable();
0 commit comments