-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.aardio
1102 lines (947 loc) · 29.9 KB
/
main.aardio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import win.ui;
import win.ui.atom;
/*DSG{{*/
mainForm = win.form(text="ChiikawaBest";right=220;bottom=118;border="none";max=false;min=false)
mainForm.add(
bk={cls="bk";left=0;top=0;right=224;bottom=120;ah=1;aw=1;background="\res\keai.jpg";z=1}
)
/*}}*/
if(#_CMDLINE){
import string.list;
arg = string.list( _CMDLINE ,";");
if(arg.operation == "update"){
import fsys;
import process;
sleep(100);
fsys.copy(io._exepath,arg.path);
process.execute(arg.path,'operation=slowStart');
win.quitMessage();
return ;
}
elseif(arg.operation == "slowStart"){
sleep(2000);
}
}
//process库导入
import process;
//创建原子窗体
var atomId,hwnd = win.ui.atom.find("3C6F3EEC-7B25-44F1-B612-FBAA2319827D.ChiikawaBest")
if( atomId ){
if(!hwnd){
process.atom.delete(atomId);
process.execute(io._exepath,'operation=slowStart');
}
else {
win.show(hwnd, true);
win.setForeground(hwnd);
}
win.quitMessage();
return;
}
else {
mainForm._atomId = process.atom.add("3C6F3EEC-7B25-44F1-B612-FBAA2319827D.ChiikawaBest");
win.property.set(mainForm.hwnd, win.ui.atom._unique_prop_name, mainForm._atomId );
}
win.setTopmost(mainForm.hwnd);
win.show(mainForm.hwnd,false);
//////////////////////////////////////////////////////////////////////
//Libray导入
//////////////////////////////////////////////////////////////////////
import fsys.version;
mainForm.appVersion = "";
if( !_STUDIO_INVOKED ){
var versionInfo = fsys.version.getInfo( io._exepath )
mainForm.appVersion = tostring(versionInfo.productVersion["major"]) + '.' +tostring(versionInfo.productVersion["minor"]) + '.' +tostring(versionInfo.productVersion["build"]) + '.' +tostring(versionInfo.productVersion["revision"]);
mainForm.copyright = versionInfo.copyright;
}
//fsys的删除库
import fsys.remove;
//inet.downBox导入
import inet.downBox;
//inet.url导入
import inet.url;
//gid库导入用于翻转颜色
import gdi;
//sqlite导入
import sqlite;
//web.view库导入
import web.view.7;
//web.rest.github导入
import web.rest.github;
//soImage库导入,用于截图与读取
import soImage;
//string.gfmark导入,作为markdown渲染
import string.gfmark;
import fsys.dlg;
import fsys.dlg.dir;
//右下角提示库
//import win.util.popup;
//托盘库
import win.ui.menu;
import win.util.tray;
//取色库
import win.ui.ctrl.pick;
//web.socket库导入
import web.socket.server;
import web.socket.client;
import win.clip;
import sys.run;
import mouse;
//自定义窗口外观
import win.ui.simpleWindow;
win.ui.simpleWindow(mainForm,,,18,).skin(
background = {
hover = 0xff99ffcc;
active = 0xffff6666;
default = 0x00000000;
}
color = {
hover = 0xff666666;
active = 0xffffffff;
default = 0xFF7BA5BF;
}
)
//配置设置
mainForm.updateStatus = true;
mainForm.updateStatusText = "检测更新";
import fsys.config;
appName = "/ChiikawaBest/";
cfgPath = io.appData(appName+"app.config");
cfg = fsys.config(cfgPath);
//为了访问本地文件而采用异步http服务器
//异步可能会阻塞进程,所以采用了多线程http服务器
import wsock.tcp.simpleHttpServer;
namespace wsock.tcp.simpleHttpServer{
//startIp = "0.0.0.0"; //不限制本机 IP
//startPort = 40315; //不指定端口时会自动分配空闲端口
threadGlobal = { mainForm = ..mainForm }; //指定 HTTP 服务线程的默认全局变量,注意定义线程函数的作用域同名变量不能是局部变量
}
serverMain = wsock.tcp.simpleHttpServer.mainThread();
mainForm.serverPath = "";
mainForm.serverPort = 9090;
if(cfg.apps_setting.localPort){
mainForm.serverPort = tonumber(cfg.apps_setting.localPort);
}
serverMain.start("0.0.0.0",mainForm.serverPort);
if(serverMain.getLocalIp() == null){
serverMain.start("0.0.0.0",0);
}
mainForm.serverPath = serverMain.getUrl("",true);
//设置:网站根目录
siteBaseDir = "/home/";
if(not io.exist(siteBaseDir)){
io.createDir(siteBaseDir);
}
//wsock.tcp.asynHttpServer导入
//这里可以指定 IP 和端口,不指定则自动分配空闲端口;成功返回true,失败返回null
/*
import wsock.tcp.asynHttpServer;
siteServer = wsock.tcp.asynHttpServer();
if(siteServer.start("0.0.0.0", 40315) == null){
siteServer.start("0.0.0.0");
};
*/
//////////////////////////////////////////////////////////////////////
//全局变量
//////////////////////////////////////////////////////////////////////
//设置:webview2与inet代理
if(cfg.proxy_setting){
if(cfg.proxy_setting.使用http代理){
d_launch_params = "--proxy-server=http://" + cfg.proxy_setting.地址文本 + ":" + cfg.proxy_setting.端口文本 + " --accept-lang=zh-CN";
m_launch_params = d_launch_params + ` --user-agent="Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; PRO 7-S Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.2.46 Mobile Safari/537.36 AliApp(DingTalk/4.6.29) com.alibaba.android.rimet/11388461 Channel/10002068 language/zh-CN"`;
inet_launch_params = "HTTP=HTTP://" + cfg.proxy_setting.地址文本 + ":" + cfg.proxy_setting.端口文本;
}
elseif(cfg.proxy_setting.使用socks5代理){
d_launch_params = "--proxy-server=SOCKS5://" + cfg.proxy_setting.地址文本s + ":" + cfg.proxy_setting.端口文本s + " --accept-lang=zh-CN";
m_launch_params = d_launch_params + ` --user-agent="Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; PRO 7-S Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.2.46 Mobile Safari/537.36 AliApp(DingTalk/4.6.29) com.alibaba.android.rimet/11388461 Channel/10002068 language/zh-CN"`;
inet_launch_params = "SOCKS5=SOCKS5://" + cfg.proxy_setting.地址文本 + ":" + cfg.proxy_setting.端口文本;
}
else {
d_launch_params = "--accept-lang=zh-CN";
m_launch_params = d_launch_params + ` --user-agent="Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; PRO 7-S Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.2.46 Mobile Safari/537.36 AliApp(DingTalk/4.6.29) com.alibaba.android.rimet/11388461 Channel/10002068 language/zh-CN"`;
inet_launch_params = "";
}
}
else {
d_launch_params = "--accept-lang=zh-CN";
m_launch_params = d_launch_params + ` --user-agent="Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; PRO 7-S Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.2.46 Mobile Safari/537.36 AliApp(DingTalk/4.6.29) com.alibaba.android.rimet/11388461 Channel/10002068 language/zh-CN"`;
inet_launch_params = "";
}
if(cfg.apps_setting.模拟移动端渲染 == true){
launch_params = m_launch_params;
}
elseif(cfg.apps_setting.模拟移动端渲染 == null){
launch_params = m_launch_params;
}
else {
launch_params = d_launch_params;
}
//更新下载路径
updateFilePath = io.appData(appName+"updateFile/");
updateBox = inet.downBox(mainForm,"检查更新",true);
/*
import console;
console.log(updateFilePath)
*/
//设置:截图临时文件保存
scrSnapFilesDir = io.appData(appName+"scrSnapTempDir/");
if(not io.exist(scrSnapFilesDir)){
io.createDir(scrSnapFilesDir);
}
//设置:webview2用户数据位置
wbUserDataDir = io.appData(appName+"userDataDir");
wbHistoryDir = wbUserDataDir+"\EBWebView\Default\";
//设置:数据库设置
dbDirBackUp = io.appData(appName+"databaseBackups");
dbDir = io.appData(appName+"database");
if(not io.exist(dbDir)){
io.createDir(dbDir);
}
if(not io.exist(dbDirBackUp)){
io.createDir(dbDirBackUp);
}
//Base数据库路径
dbBasePath = dbDir+"/base.db"
dbBase = sqlite(dbBasePath);
//Timeline数据库路径
dbTimelinePath = dbDir+"/timeline.db";
dbTimeline = sqlite(dbTimelinePath);
//AlarmClock数据库路径
dbAlarmClockPath = dbDir+"/alarmClock.db";
dbAlarmClock = sqlite(dbAlarmClockPath);
//AppNotes数据库路径
dbAppNotesPath = dbDir+"/appNotes.db";
dbAppNotes = sqlite(dbAppNotesPath);
//LANChat数据库路径
dbLANChatPath = dbDir+"/LANChat.db";
dbLANChat = sqlite(dbLANChatPath);
if( not dbTimeline.existsTable("default") ){
dbTimeline.exec( "CREATE TABLE [default] (time PRIMARY KEY, title, content, image);");
}
if( not dbBase.existsTable("timeline") ){
dbBase.exec( "CREATE TABLE [timeline] (name PRIMARY KEY, time, category);");
var cmd = dbBase.prepare("REPLACE INTO [timeline] VALUES ( @name,@time,@category);");
cmd.step(
name = "default";
time = time.now();
category = "未分类";
)
}
if( dbBase.existsTable("timeline")){
var cmd = dbBase.prepare("SELECT * FROM [timeline];")
var columns = cmd.getColumns();
var isOk = table.find(columns,"category");
if(isOk){}
else {
dbBase.exec("ALTER TABLE [timeline] ADD COLUMN category TEXT DEFAULT ?;",{"未分类"});
}
}
if( not dbBase.existsTable("timelinecategory") ){
dbBase.exec( "CREATE TABLE [timelinecategory] (name PRIMARY KEY, time);");
var cmd = dbBase.prepare("REPLACE INTO [timelinecategory] VALUES ( @name,@time);");
cmd.step(
name = "未分类";
time = time.now();
)
}
if( not dbBase.existsTable("timelinecategory未分类") ){
dbBase.exec( "CREATE TABLE [timelinecategory未分类] (name PRIMARY KEY, time);");
var cmd = dbBase.prepare("REPLACE INTO [timelinecategory未分类] VALUES ( @name,@time);");
for rowid, Tname, Ttime in dbBase.each("SELECT rowid,* FROM timeline") {
cmd.step(
name = Tname;
time = Ttime;
)
}
}
if( not dbBase.existsTable("timelineskin") ){
dbBase.exec( "CREATE TABLE [timelineskin] (name PRIMARY KEY, color);");
var cmd = dbBase.prepare("REPLACE INTO [timelineskin] VALUES ( @name,@color);");
cmd.step(
name = "bg";
color = "FFF7F4ED";
);
cmd.step(
name = "txt";
color = "FF31322C";
);
cmd.step(
name = "hl";
color = "FFFECC11";
);
cmd.step(
name = "normal";
color = "FF31322C";
)
}
timeline_skin = {
bg = "FFF7F4ED";
txt = "FF31322C";
hl = "FFFECC11";
normal = "FF31322C";
};
if( dbBase.existsTable("timelineskin") ) {
for rowid, name, color in dbBase.each("SELECT rowid,* FROM timelineskin") {
select(name) {
case "bg" {
timeline_skin.bg = color;
}
case "txt" {
timeline_skin.txt = color;
}
case "hl" {
timeline_skin.hl = color;
}
case "normal" {
timeline_skin.normal = color;
}
else {
}
}
}
}
if( not dbAlarmClock.existsTable("default")){
dbAlarmClock.exec( "CREATE TABLE [default] (time PRIMARY KEY, content);");
}
if( not dbAppNotes.existsTable("appNotesDefault")){
dbAppNotes.exec( "CREATE TABLE [appNotesDefault] (name PRIMARY KEY, content);")
}
if( not dbAppNotes.existsTable("appNotesPos")){
dbAppNotes.exec( "CREATE TABLE [appNotesPos] (name PRIMARY KEY, xx, yy, xwidth, yheight);")
}
if( not dbLANChat.existsTable("LANChat")){
dbLANChat.exec( "CREATE TABLE [LANChat] (time PRIMARY KEY, domain, chatgroup, content);")
}
//////////////////////////////////////////////////////////////////////
//设置:托盘消息
//////////////////////////////////////////////////////////////////////
mainForm.trayCreate = function(){
win.setForeground(mainForm.hwnd);
/*
下面创建托盘弹出菜单。
如果程序要开机启动到托盘,最好在这里创建菜单,在用户点击前不要创建菜单,
避免系统启动时 DPI 缩放前创建的菜单字体偏小(出现这情况的机率很小)。
如果不想重复创建菜单最好写到一个库里,然后在这里 import 即可避免上述问题。
*/
import win.ui.menu;
mainForm.popmenu = win.ui.popmenu(mainForm);//创建弹出菜单
/*
stat = win.isVisible(mainForm.hwnd);
if(stat){
mainForm.popmenu.add("隐藏主窗口",function(id){
mainForm.show(false);
});
}else {
mainForm.popmenu.add("显示主窗口",function(id){
mainForm.show(true);
win.setForeground(mainForm.hwnd)
});
}
*/
mainForm.popmenu.add("显示主窗口",function(id){
mainForm.show(true);
win.setForeground(mainForm.hwnd)
});
mainForm.popmenu.add();//分隔线
mainForm.popmenu.add("设置",function(){
var settings1 = mainForm.loadForm("\dlg\settings.aardio");
settings1.show();
})
mainForm.popmenu.add();//分隔线
mainForm.popmenu.add("网页监控 (Alt+C)",function(){
if(webwatcher == "notExist"){
webwatcher = mainForm.loadForm("\dlg\webwatcher.aardio");
}
win.setForeground(webwatcher.hwnd);
webwatcher.show();
})
mainForm.popmenu.add("时间线 (Alt+X)",function(){
win.setForeground(timeline_choice.hwnd);
timeline_choice.show();
})
mainForm.popmenu.add("闹钟 (Alt+1)",function(){
win.setForeground(alarmForm.hwnd);
alarmForm.show();
})
mainForm.popmenu.add("截图 (Alt+Q)",function(){
var watchWin1 = win.loadForm("\dlg\watchWin.aardio",,win.getDesktop());
watchWin1.rdyMove();
watchWin1.show();
})
mainForm.popmenu.add();//分隔线
mainForm.popmenu.add("打开数据文件夹",function(){
process("explorer.exe",io.appData(appName))
})
mainForm.popmenu.add("应用日志",function(){
win.setForeground(logForm.hwnd);
logForm.show();
})
mainForm.popmenu.add("加载库",function(){
var dirPath = fsys.dlg.dir("\");
if(dirPath){
mainForm.loadAddOns(dirPath);
}
})
mainForm.popmenu.add();//分割线
mainForm.popmenu.add("版本:"+mainForm.appVersion,function(){
var frmChild = mainForm.loadForm("\dlg\productDescription.aardio");
frmChild.show();
})
mainForm.popmenu.add("关于软件/手动更新",function(){
process("explorer.exe","https://github.com/YrracOwl/ChiikawaBest")
process.exploreSelect(io._exepath);
})
/*
if(mainForm.updateStatus){//检查更新
mainForm.popmenu.add("检测更新",function(){
mainForm.checkUpdate();
});
}
else {
mainForm.popmenu.add("检测更新中...",function(){});
};
*/
mainForm.popmenu.add();//分隔线
mainForm.popmenu.add('退出',function(id){
if(serverMain){
serverMain.stop();
serverMain = null;
}
mainForm.onClose = null;
alarmForm.closeTodosAll();
mainForm.onClose = function(hwnd,message,wParam,lParam){
if(webwatcher != "notExist"){
webwatcher.onClose = null;
webwatcher.close();
}
cleanHistory();
fadeHide();
}
mainForm.releaseAddOns();
mainForm.close();
})
mainForm.popmenu.popup();
mainForm.popmenu.close();
}
mainForm.onTrayMessage = {
[0x205/*_WM_RBUTTONUP*/] = function(wParam){
mainForm.trayCreate();
};
[0x201/*_WM_LBUTTONDOWN*/] = function(wParam){
mainForm.show(true);
win.setForeground(mainForm.hwnd)
};
[0x203/*_WM_LBUTTONDBLCLK*/] = function(wParam){
};
[0x404/*_PARAM_DESTROY*/] = function(wParam){
};
[0x405/*_PARAM_CLICKED*/] = function(wParam){
};
}
mainForm.onClose = function(hwnd,message,wParam,lParam){
mainForm.show(false); //隐藏窗口
if(!cfg.apps_setting.启动到托盘 and minimize_1st_show){
minimize_1st_show = false;
mainForm.tray.pop("应用"+mainForm.appVersion+"已启动,右击托盘获取更多菜单","ChiikawaBest",,3000);
}
//mainForm.popmenu.setString(1,"显示")
return true;//阻击默认消息传递,取消最小化过程
}
mainForm.onDestroy = function(){
if(serverMain){
serverMain.stop();
serverMain = null;
}
alarmForm.closeTodosAll();
mainForm.releaseAddOns();
}
var minimize_1st_show = true;
mainForm.onMinimize = function(lParam){
mainForm.show(false); //隐藏窗口
if(!cfg.apps_setting.启动到托盘 and minimize_1st_show){
minimize_1st_show = false;
mainForm.tray.pop("应用"+mainForm.appVersion+"已启动,右击托盘获取更多菜单","ChiikawaBest",,3000);
}
//mainForm.popmenu.setString(1,"显示")
return true;//阻击默认消息传递,取消最小化过程
}
//////////////////////////////////////////////////////////////////////
//计划任务
//////////////////////////////////////////////////////////////////////
//计划任务导入
import win.taskScheduler;
webWatcher_taskScheduler = win.taskScheduler(mainForm);
//////////////////////////////////////////////////////////////////////
//自定义函数
//////////////////////////////////////////////////////////////////////
updateUrlBackUp = "https://raw.githubusercontent.com/YrracOwl/ChiikawaBest/master/release/ChiikawaBest.exe";
updateUrlbase = "https://raw.githubusercontent.com/YrracOwl/ChiikawaBest/master/release/ChiikawaBest.exe";
var updateUrlPrefix1 = "https://github.moeyy.xyz/";
var updateUrlPrefix2 = "https://git.886.be/";
var updateUrlPrefix3 = "https://ghps.cc/";
var updateUrlPrefix = {updateUrlPrefix1;updateUrlPrefix2;updateUrlPrefix3};
if(cfg.apps_setting.urlSetting){
updateUrlbase = cfg.apps_setting.urlSetting;
}
mainForm.updateUrl = updateUrlbase;
mainForm.updateCheckOver = false;
mainForm.updateOk = null;
//检查更新函数
mainForm.updateStart = function(){
var confirmed = mainForm.msgboxTest("确定更新并自动重启吗?","更新中...");
if(confirmed){
updateBox.download(mainForm.updateUrl,updateFilePath,,,inet_launch_params)
mainForm.msgbox("下载已完成,即将重启","即将重启",,1600);
if(serverMain){
serverMain.stop();
serverMain = null;
}
mainForm.onClose = null;
mainForm.releaseAddOns();
alarmForm.closeTodosAll();
var currentPath = io._exepath;
process.execute(updateFilePath+"ChiikawaBest.exe",'operation=update;path='+currentPath);
mainForm.updateStatus = true;
mainForm.close();
}
}
mainForm.checkUpdate = function(){
mainForm.updateStatus = false;
var LatestReleaseUrlPath = updateUrlbase;
var updateUrlMirrors = {};
for(k,v in updateUrlPrefix){
updateUrlMirrors[k] = updateUrlPrefix[k] + LatestReleaseUrlPath;
}
var updateTestThrd = {};
for(k,v in updateUrlMirrors){
var updateUrl = v;
updateTestThrd[k] = thread.create(
function(updateUrl,updateFilePath,inet_launch_params,mainForm){
import win;
import inet.downBox;
updateBox = inet.downBox(win.getDesktop(),"检查更新",true);
var ok = updateBox.test(updateUrl,updateFilePath,,,inet_launch_params);
if(ok != null){
mainForm.updateOk = ok;
mainForm.updateUrl = updateUrl;
mainForm.updateCheckOver = true;
}
else {
mainForm.updateOk = ok;
mainForm.updateUrl = updateUrl;
mainForm.updateCheckOver = true;
}
},updateUrl,updateFilePath,inet_launch_params,mainForm
);
}
thread.invokeAndWait(
function(mainForm){
while(!mainForm.updateCheckOver){
}
},mainForm
)
for(k,v in updateTestThrd){
thread.suspend(updateTestThrd[k]);
raw.closehandle(updateTestThrd[k]);
}
mainForm.updateStatus = true;
if(mainForm.updateOk){
var wannaForceUpdate = mainForm.msgboxTest("服务器无更新,是否强制拉取更新并重启","检测更新");
if(wannaForceUpdate){
fsys.remove(updateFilePath);
mainForm.updateStart();
}
else {
mainForm.updateUrl = updateUrlbase;
mainForm.updateCheckOver = false;
mainForm.updateOk = null;
return;
}
}
elseif( mainForm.updateOk === null){
mainForm.msgboxErr("下载错误,请检查有无代理!HTTP错误代码:"+ ( updateBox.statusCode : ""));
return;
}
mainForm.updateStart();
}
mainForm.initialCheckUpdate = function(){
mainForm.updateStatus = false;
var LatestReleaseUrlPath = updateUrlbase;
/*
var LatestReleaseUrlPath = web.rest.github.latestRelease("YrracOwl/ChiikawaBest","ChiikawaBest.exe");
if(LatestReleaseUrlPath == null){
mainForm.msgboxErr("当前无法访问Github,请稍后再试");
return;
}
*/
var updateUrlMirrors = {};
for(k,v in updateUrlPrefix){
updateUrlMirrors[k] = updateUrlPrefix[k] + LatestReleaseUrlPath;
}
var updateTestThrd = {};
for(k,v in updateUrlMirrors){
var updateUrl = v;
updateTestThrd[k] = thread.create(
function(updateUrl,updateFilePath,inet_launch_params,mainForm){
import win;
import inet.downBox;
updateBox = inet.downBox(win.getDesktop(),"检查更新",true);
var ok = updateBox.test(updateUrl,updateFilePath,,,inet_launch_params);
if(ok != null){
mainForm.updateOk = ok;
mainForm.updateUrl = updateUrl;
mainForm.updateCheckOver = true;
}
else {
mainForm.updateOk = ok;
mainForm.updateUrl = updateUrl;
mainForm.updateCheckOver = true;
}
},updateUrl,updateFilePath,inet_launch_params,mainForm
);
}
thread.invokeAndWait(
function(mainForm){
while(!mainForm.updateCheckOver){
}
},mainForm
)
for(k,v in updateTestThrd){
thread.suspend(updateTestThrd[k]);
raw.closehandle(updateTestThrd[k]);
}
mainForm.updateStatus = true;
if(mainForm.updateOk){
mainForm.tray.pop("应用己是最新...","ChiikawaBest",,1200);
return;
}
elseif( mainForm.updateOk === null){
mainForm.tray.pop("下载错误,请检查有无代理!","ChiikawaBest",,1200);
//mainForm.msgboxErr("下载错误,请检查有无代理!HTTP错误代码:"+ ( updateBox.statusCode : ""));
return;
}
mainForm.updateStart();
}
//log函数
logForm = mainForm.loadForm("\dlg\log.aardio");
logForm.show(false);
logMsg = function(...){
logInfo("消息",...);
}
logWarn = function(...){
logInfo("警告",...);
}
logErr = function(...){
logInfo("错误",...);
}
logWrite = function(...){
logInfo("写入",...);
}
logInfo = function(infoType, ...){
var colorSet = {
//0xbbggrr
0xffffff;//1白色
0x000000;//2黑色
0x0000ff;//3正红色
0x00ff00;//4正绿色
0xff0000;//5正蓝色
0x349bdb;//6黄不老
0x1d16c8;//7丹雘
0x6b4e35;//8青雀头黛
0x84a71b;//9竹绿
};
var color = colorSet[2];
var bkcolor = colorSet[1];
select(infoType) {
case "消息" {
color = colorSet[8];
}
case "警告" {
color = colorSet[6];
}
case "错误" {
color = colorSet[7];
}
case "写入" {
color = colorSet[9];
}
else {
color = colorSet[2];
}
};
logForm.richedit.appendText("[ "+infoType+" ] " + tostring(time.now()),": ")
var arg = { ... };
for(k,v in arg){
logForm.richedit.appendText(tostring(v))
logForm.richedit.appendText(" ")
}
logForm.richedit.appendText('\r\n')
logForm.richedit.lineSel(-2);
logForm.richedit.setSelCharformat(textColor = color);
logForm.richedit.deselect();
}
//渐隐扩散特效
fadeHide = function(){
for(i=17;1;-1){
mainForm.transparent( i * 10);
x,y,cx,cy = mainForm.getPos();
mainForm.setPos(x-1,y-1,cx+2,cy+2);
win.delay(5);
};
win.quitMessage();
}
mainForm.cleanHistoryWhenClose = false;
//清除用户webview2数据
cleanHistory = function(){
if(mainForm.cleanHistoryWhenClose){
if(io.exist(wbHistoryDir + "Visited Links")){
mainForm.msgbox("3秒后即将清理历史记录","注意",0,3000)
if(io.remove(wbHistoryDir + "Visited Links") and io.remove(wbHistoryDir + "History") and io.remove(wbHistoryDir + "History-journal")){
mainForm.msgbox("清理成功!即将自动退出!", "恭喜!",0,1200)
}
else {
mainForm.msgbox("清理失败!请手动清理!即将自动退出!", "注意!",0,2000)
}
}
else {
mainForm.msgbox("没有历史记录!即将自动退出!","恭喜!",0,1000)
}
}
}
//多线程写数据库函数
//创建线程
thrdWriteDBFunc = function(db_path,str_prepare,str_step){
import sqlite;
var db = sqlite(db_path)
//多线程冲突锁定时的重试次数
db.busyTimeout(10000);
thread.lock("PRINT",λ() io.print("正在写数据库,线程ID:",thread.getId()) )
var command = db.prepare(str_prepare)
for(i=1;10;1){
command.step(str_step)
}
command.finalize();
db.close();
}
//全局闹钟
alarmForm = mainForm.loadForm("\dlg\add_alarm.aardio");
//全局网页监控
//webwatcher = mainForm.loadForm("\dlg\webwatcher.aardio");
webwatcher = "notExist";
webwatcherPrcsCntShot = 0;
//全局时间线选择
timeline_choice = mainForm.loadForm("\dlg\timeline_choice_treeview.aardio");
//数据库是否需要更新
//字段判断
mainForm.haveDBImgField = function(timeline_name){
var cmd = dbTimeline.prepare("SELECT * FROM ?? ",{timeline_name})
var columns = cmd.getColumns();
var isOk = table.find(columns,"image");
if(isOk){
logWarn("返回值为",tostring(isOk),"拥有image字段")
}
else {
logErr("返回值为",tostring(isOk),"无image字段");
}
return isOk;
}
mainForm.createDBImgField = function(timeline_name){
dbTimeline.exec("ALTER TABLE ? ADD COLUMN image blob;",{timeline_name});
var isDone = mainForm.haveDBImgField(timeline_name);
if(isDone){
win.msgboxTest("升级成功!请重新打开!","升级成功",win.getDesktop());
}
else {
win.msgboxErr("升级失败!请重启程序再尝试!","升级失败",win.getDesktop());
}
}
mainForm.loadWatchWin = function(){
if(win.isVisible(mainForm.hwnd)){
mainForm.show(false);
win.setForeground(mainForm.hwnd)
thread.invoke(
function(mainForm){
import win;
win.delay(100);
mainForm.loadWatchWin();
},mainForm
)
return;
}
var watchWinHK = win.loadForm("\dlg\watchWin.aardio",,win.getDesktop());
watchWinHK.show(false);
var x,y = win.getCursorPos();
win.setPos(watchWinHK.hwnd,x,y);
watchWinHK.undoTop();
watchWinHK.doTop();
watchWinHK.rdyDrag();
watchWinHK.show(true);
}
mainForm.loadWebWatcher = function(){
if(win.isVisible(mainForm.hwnd)){
mainForm.show(false);
win.setForeground(mainForm.hwnd)
thread.invoke(
function(mainForm){
import win;
win.delay(100);
mainForm.loadWebWatcher();
},mainForm
)
return;
}
if(webwatcher == "notExist"){
webwatcher = mainForm.loadForm("\dlg\webwatcher.aardio");
}
webwatcher.doForeground();
webwatcher.show();
}
mainForm.showTimeline = function(){
if(win.isVisible(mainForm.hwnd)){
mainForm.show(false);
win.setForeground(mainForm.hwnd)
thread.invoke(
function(mainForm){
import win;
win.delay(100);
mainForm.showTimeline();
},mainForm
)
return;
}
timeline_choice.show();
timeline_choice.doForeground();
}
mainForm.showAlarm =function(){
if(win.isVisible(mainForm.hwnd)){
mainForm.show(false);
win.setForeground(mainForm.hwnd)
thread.invoke(
function(mainForm){
import win;
win.delay(100);
mainForm.showAlarm();
},mainForm
)
return;
}
alarmForm.show();
alarmForm.doForeground();
}
//super hotkey库导入
import key.hotkey;
//注册快捷键
mainForm.superHotkey = key.hotkey(mainForm) //创建超级热键,必须用于窗口程序中
//批量加载热键配置表
/*
mainForm.superHotkey.loadTable({
(function(){
//这里的代码可以直接执行
})();
["~1"] = function(hFocus){
mainForm.loadWatchWin();
};
["~2"] = function(hFocus){
mainForm.showTimeline();
};
["~Q"] = function(hFocus){
mainForm.showAlarm();
};
["~W"] = function(hFocus){
mainForm.loadWebWatcher();
};
});
*/
if(io.exist("\ChiikawaBest_WatchWin.exe")){
hkid1 = mainForm.reghotkey(function(id,mod,vk){
var prc = process.shell("ChiikawaBest_WatchWin.exe");
},1,0x51);//ALT+Q
}
else {
hkid1 = mainForm.reghotkey(function(id,mod,vk){
mainForm.loadWatchWin();
},1,0x51);//ALT+Q
}