-
Notifications
You must be signed in to change notification settings - Fork 90
/
main.aardio
328 lines (273 loc) · 11.2 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
/*启动参数{{*/
_IMTIP_APP = true;
if(_ARGV.chat){
loadcodex("\dlg\aiChat.aardio");
return;
}
for(k,v in _ARGV){
if(string.endWith(v,".aardio",true)){
if(io.exist(v)){
__argvImTipConfig = v;
}
}
}
/*}}*/
import style;
import fonts.imtip;
import win.ui.atom;
import win.ui;
import win.dlg.message;
import fonts.fontAwesomeSub;
/*DSG{{*/
mainForm = win.form(text="ImTip 5.5 - 桌面助手";right=649;bottom=414;bgcolor=16777215;border="dialog frame";max=false;min=false)
mainForm.add(
btnAiChat={cls="plus";text="AI 智能助手";left=36;top=273;right=178;bottom=303;align="left";bgcolor=11580047;db=1;dl=1;font=LOGFONT(h=-14);iconStyle={align="left";font=LOGFONT(h=-16;name='FontAwesome');padding={left=10;top=1}};iconText='\uF007';notify=1;tabstop=1;textPadding={left=29};z=9};
btnFilterWindows={cls="plus";text="编辑规则";left=439;top=225;right=544;bottom=254;align="left";color=3947580;db=1;disabled=1;dr=1;font=LOGFONT(h=-13);iconStyle={align="left";font=LOGFONT(h=-13;name='FontAwesome');padding={left=8}};iconText='\uF044';notify=1;textPadding={left=25};z=12};
btnHotkey={cls="plus";text="编辑超级热键";left=36;top=40;right=178;bottom=70;align="left";bgcolor=11580047;dl=1;dt=1;font=LOGFONT(h=-14);iconStyle={align="left";font=LOGFONT(h=-16;name='imtip');padding={left=10;top=1}};iconText='\uE8CE';notify=1;tabstop=1;textPadding={left=29};z=6};
btnImTip={cls="plus";text="配置输入法提示";left=36;top=226;right=178;bottom=256;align="left";bgcolor=11580047;db=1;dl=1;font=LOGFONT(h=-14);iconStyle={align="left";font=LOGFONT(h=-16;name='FontAwesome');padding={left=10;top=1}};iconText='\uF0F6';notify=1;tabstop=1;textPadding={left=29};z=8};
chkFilterWindows={cls="plus";text="启用扩展规则";left=326;top=225;right=432;bottom=254;align="left";db=1;dr=1;iconStyle={align="left";font=LOGFONT(h=-15;name='FontAwesome');padding={top=1}};iconText='\uF0C8 ';notify=1;tabstop=1;textPadding={left=20};z=13};
chkHotkey={cls="plus";text="启用超级热键";left=214;top=41;right=410;bottom=70;align="left";dl=1;dr=1;dt=1;iconStyle={align="left";font=LOGFONT(h=-15;name='FontAwesome');padding={top=1}};iconText='\uF0C8 ';notify=1;tabstop=1;textPadding={left=20};z=7};
chkSysRun={cls="plus";text="允许开机启动";left=39;top=355;right=603;bottom=384;align="left";db=1;dl=1;dr=1;iconStyle={align="left";font=LOGFONT(h=-15;name='FontAwesome');padding={top=1}};iconText='\uF0C8 ';notify=1;tabstop=1;textPadding={left=20};z=10};
chkWatchFullScreen={cls="plus";text="忽略全屏窗口";left=214;top=225;right=320;bottom=254;align="left";db=1;dl=1;iconStyle={align="left";font=LOGFONT(h=-15;name='FontAwesome');padding={top=1}};iconText='\uF0C8 ';notify=1;tabstop=1;textPadding={left=20};z=11};
group1={cls="plus";left=18;top=21;right=628;bottom=320;align="left";border={color=-16744448;radius=8;width=1};db=1;dl=1;dr=1;dt=1;font=LOGFONT(h=-14);textPadding={left=16};valign="top";z=2};
group2={cls="plus";left=18;top=342;right=628;bottom=396;align="left";border={color=-16744448;radius=8;width=1};db=1;dl=1;dr=1;font=LOGFONT(h=-14);textPadding={left=16};valign="top";z=1};
groupTitle1={cls="plus";text="软件功能";left=31;top=7;right=107;bottom=33;dl=1;dt=1;z=4};
groupTitle2={cls="plus";text="启动选项";left=36;top=328;right=112;bottom=354;db=1;dl=1;z=5};
lpHotkey={cls="syslink";text='<a href="https://imtip.aardio.com">ImTip</a> 强大的『超级热键』集成 <a href="https://www.aardio.com">aardio</a> 开发环境,可调用 aardio 的全部标准库与扩展库。\n提供丰富的热键功能。支持快捷获取屏幕选区文本、输入位置、输入法状态,快捷调用 AI 大模型接口,快速开发智能桌面助手。\n\n<a href="https://www.aardio.com/zh-cn/doc/?q=library-guide%2Fstd%2Fkey%2Fhotkey.html">ImTip 超级热键开发指南</a>\n<a href="https://www.aardio.com/zh-cn/doc/?q=guide%2Flanguage%2Fsyntax-quick-ref.html">aardio 语法速览</a>\n<a href="https://www.aardio.com/vip">VIP 技术支持</a>';left=62;top=90;right=599;bottom=219;db=1;dl=1;dr=1;dt=1;notify=1;transparent=1;z=3}
)
/*}}*/
var atom,hwnd = mainForm.atom("E474890D-1DFA-4575-B456-7B46C15665DC.imtip");
if(!atom){
if(__argvImTipConfig) win.sendCopyData(hwnd,__argvImTipConfig );
else {
win.sendCopyData(hwnd,"show");
}
win.quitMessage();
return;
}
import fsys.update.simpleMain;
if( fsys.update.simpleMain(
"ImTip 桌面助手",
"http://imtip.aardio.com/update/",
io.appData("/aardio/std/ImTip/app/update"),
function(version,description,status){})){
return 0;
}
mainForm.chkSysRun.skin(style.checkBox);
mainForm.chkHotkey.skin(style.checkBox);
mainForm.chkFilterWindows.skin(style.checkBox);
mainForm.chkWatchFullScreen.skin(style.checkBox);
mainForm.btnHotkey.skin(style.button);
mainForm.btnAiChat.skin(style.button);
mainForm.btnImTip.skin(style.button);
mainForm.enableDpiScaling("init");
import config;
if(!_ARGV.sys){
if(!_ARGV.updated){
mainForm.show()
}
else {
if(!config.setting.runOnce){
mainForm.show();
config.setting.runOnce = true;
config.setting.save();
}
}
}
//显示输入状态栏
import key.ime.stateBar;
imeBar = key.ime.stateBar(mainForm);
imeBar.interval = config.setting.interval;
imeBar.timeout = config.setting.timeout;
imeBar.editorClasses = config.setting.editorClasses;
imeBar.quirksMode = config.setting.updateQuirksMode();
//下面创建托盘图标
import win.util.tray;
mainForm.tray = win.util.tray(mainForm)
mainForm.tray.tip = "ImTip:桌面助手" //设置鼠标提示
//响应托盘消息
mainForm.onTrayMessage = {
[0x205/*_WM_RBUTTONUP*/] = function(wParam){
import ui.appTrayMenu;
var menu = ui.appTrayMenu(mainForm); //延迟创建,避免系统启动时 DPI 缩放前创建菜单
win.setForeground(mainForm.hwnd); //避免不点击菜单不会消失,父窗口隐藏也要这样做
menu.popup();
};
[0x201/*_WM_LBUTTONDOWN*/] = function(wParam){
if(..mainSettingForm) ..mainSettingForm.show(false);
mainForm.show();
win.setForeground(mainForm.hwnd);
};
}
import config;
import app.util;
mainForm.importImTipStyle = function(path){
var buf = string.loadBuffer(path);
if(!#buf) return mainForm.msgboxErr("此文件不包含有效的 ImTip 外观配置方案!");
var data = string.match(buf,"\/\*ImTipConfig\{\{\*\/(.+)\/\*\}\}\*\/");
if(!#data) return mainForm.msgboxErr("此文件不包含有效的 ImTip 外观配置方案!");
try{
var cfg = eval(data);
app.util.updateTipStyle(cfg);
imeBar.imeSkin(cfg);
config.style.embeddingFontData = null;
config.style.embeddingFontName = null;
config.style.openStyle = null;
config.style.border = null;
config.style.embeddingFontData = null;
config.style.embeddingFontName = null;
config.style.openStyle = null;
config.style.border = null;
config.style.background = null;
config.style.foreground = null;
config.style.linearGradient = null;
config.style.paddingLeft = null;
config.style.paddingRight = null;
config.style.paddingTop = null;
config.style.paddingBottom = null;
table.assign(config.style,cfg);
config.style.save();
}
catch(e){
mainForm.msgboxErr(e);
}
}
mainForm.onCopyData = function(data,dataType){
if(data=="start"){
if(mainSettingForm){
return win.setForeground(mainSettingForm.hwnd);
}
var frmChild = mainForm.loadForm("\dlg\frmSetting.aardio");
frmChild.show();
}
elseif(string.endWith(data,".aardio",true) && io.exist(data) ){
if(mainSettingForm) {
win.setForeground(mainSettingForm.hwnd);
return mainSettingForm.importStyleFromFile(data);
}
mainForm.importImTipStyle(data);
}
elseif(data=="ime-enable"){
imeBar.imeWatch(true);
}
elseif(data=="ime-disable"){
imeBar.imeWatch(false);
}
elseif(data=="ime-switch"){
imeBar.imeWatch(!!..imeBar.paused);
}
else {
mainForm.show();
}
}
mainForm.onClose = function(){
mainForm.show(false);
return true;
}
if(config.style.width){
app.util.updateTipStyle(config.style);
imeBar.imeSkin(config.style)
}
if(__argvImTipConfig){
win.sendCopyData(mainForm.hwnd,__argvImTipConfig);
}
if(config.hotkey.chkEnableHotkey){
import app.hotkey;
app.hotkey.update(true);
}
mainForm.btnImTip.oncommand = function(id,event){
if(..mainHotkeyForm) ..mainHotkeyForm.hitMin();
if(!..mainSettingForm) ..mainSettingForm = ..mainForm.loadForm("\dlg\frmSetting.aardio");
..mainSettingForm.show();
mainForm.show(false);
}
mainForm.btnAiChat.oncommand = function(id,event){
import process.imTip;
process.imTip(chat = "");
mainForm.show(false);
}
mainForm.btnHotkey.oncommand = function(id,event){
mainForm.btnHotkey.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250';text=''}
import app.hotkey;
app.hotkey.edit();
thread.delay(1500);
mainForm.btnHotkey.disabledText = null;
mainForm.show(false);
}
mainForm.chkSysRun.checked = config.setting.sysRun;
mainForm.chkSysRun.oncommand = function(id,event){
if(_STUDIO_INVOKED){
error("此功能发布后可用。")
}
import sys.run;
import process.admin;
if( process.admin.isRunAs() && ! _WINXP ){
import sys.runAsTask;
sys.run("ImTip").delete();
if(owner.checked){
sys.runAsTask("ImTip","桌面助手").register("/sys");
config.setting.sysRunAs = true;
}
else {
sys.runAsTask("ImTip","桌面助手").delete();
config.setting.sysRunAs = null;
}
mainForm.chkSysRun.text = "允许开机以管理权限启动"
}
else{
if( config.setting.sysRunAs ){
mainForm.msgboxErr('之前创建的开机启动项拥有管理权限,\n以相同的管理权限启动 ImTip 才能移除。')
owner.checked = true;
return ;
}
if(owner.checked){
sys.run("ImTip").register("/sys");
}
else {
sys.run("ImTip").delete()
}
mainForm.chkSysRun.text = "允许开机以普通权限启动(当前进程无管理权限)"
}
config.setting.sysRun = owner.checked;
config.setting.save();
}
mainForm.chkHotkey.checked = ..config.hotkey.chkEnableHotkey;
mainForm.chkHotkey.oncommand = function(id,event){
..config.hotkey.chkEnableHotkey = !..config.hotkey.chkEnableHotkey;
import app.hotkey;
app.hotkey.update(..config.hotkey.chkEnableHotkey);
}
var thrdWatcherFilterWindows;
mainForm.btnFilterWindows.skin(style.transButton)
mainForm.btnFilterWindows.oncommand = function(id,event){
mainForm.btnFilterWindows.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250';text=''}
import app.filterWindows;
app.filterWindows.edit();
thread.delay(1500);
mainForm.btnFilterWindows.disabledText = null;
}
mainForm.chkFilterWindows.oncommand = function(id,event){
config.setting.filterWindows = owner.checked;
config.setting.save();
mainForm.btnFilterWindows.disabled = !config.setting.filterWindows;
import app.filterWindows;
app.filterWindows.update();
}
mainForm.chkFilterWindows.checked = config.setting.filterWindows;
if(config.setting.filterWindows){
import app.filterWindows;
app.filterWindows.update();
mainForm.btnFilterWindows.disabled = false;
}
mainForm.chkWatchFullScreen.checked = config.setting.watchFullScreen;
mainForm.chkWatchFullScreen.oncommand = function(id,event){
config.setting.watchFullScreen = owner.checked;
config.setting.save();
import app.filterWindows;
app.filterWindows.watchFullScreen(config.setting.watchFullScreen);
}
if(config.setting.watchFullScreen){
import app.filterWindows;
app.filterWindows.watchFullScreen(true);
}
win.loopMessage();