clickgo 3.0.6-dev7 → 3.0.7-dev8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/app/task/form/bar/bar.js +3 -0
- package/dist/app/task/form/bar/bar.xml +1 -1
- package/dist/global.css +1 -1
- package/dist/lib/core.js +33 -4
- package/dist/lib/core.ts +32 -3
- package/dist/lib/dom.js +6 -3
- package/dist/lib/dom.ts +6 -3
- package/dist/lib/form.js +215 -30
- package/dist/lib/form.ts +232 -42
- package/dist/lib/native.js +8 -148
- package/dist/lib/native.ts +6 -211
- package/dist/lib/task.js +3 -10
- package/dist/lib/task.ts +3 -10
- package/package.json +1 -1
- package/types/index.d.ts +15 -2
package/dist/lib/native.ts
CHANGED
|
@@ -15,23 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import * as clickgo from '../clickgo';
|
|
17
17
|
|
|
18
|
-
/** --- 最后一个 send ID --- */
|
|
19
|
-
let sendId = 0;
|
|
20
|
-
// --- sendList 一定会被清理 ---
|
|
21
|
-
let sendList: Array<{
|
|
22
|
-
'id': number;
|
|
23
|
-
'name': string;
|
|
24
|
-
'param': string | undefined;
|
|
25
|
-
}> = [];
|
|
26
|
-
|
|
27
|
-
/** --- 监听的 listener,需要调用者手动清理(或者 task 结束后自动会被清理,未设置 taskId 的则不会自动清理) --- */
|
|
28
|
-
const listeners: Record<string, Array<{
|
|
29
|
-
'id': number;
|
|
30
|
-
'once': boolean;
|
|
31
|
-
'taskId'?: number;
|
|
32
|
-
'handler': (param?: string) => void | Promise<void>;
|
|
33
|
-
}>> = {};
|
|
34
|
-
|
|
35
18
|
const token = (Math.random() * 100000000000000 * (100 + Math.round(Math.random() * (999 - 100)))).toString(32);
|
|
36
19
|
/**
|
|
37
20
|
* --- 获取 native 通讯 token,app 模式下无效 ---
|
|
@@ -40,217 +23,29 @@ export function getToken(): string {
|
|
|
40
23
|
return token;
|
|
41
24
|
}
|
|
42
25
|
|
|
43
|
-
/**
|
|
44
|
-
* --- 获取已经创建的监听列表 ---
|
|
45
|
-
*/
|
|
46
|
-
export function getListeners(): Array<{ 'id': number; 'name': string; 'once': boolean; 'taskId'?: number; }> {
|
|
47
|
-
const list = [];
|
|
48
|
-
for (const name in listeners) {
|
|
49
|
-
for (const item of listeners[name]) {
|
|
50
|
-
list.push({
|
|
51
|
-
'id': item.id,
|
|
52
|
-
'name': name,
|
|
53
|
-
'once': item.once,
|
|
54
|
-
'taskId': item.taskId
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return list;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
26
|
/**
|
|
62
27
|
* --- 向 native 发送指令 ---
|
|
63
28
|
* @param name 指令名
|
|
64
29
|
* @param param 参数
|
|
65
|
-
* @param handler 回调
|
|
66
|
-
* @param taskId 仅在任务活跃时可监听,App 模式下无效
|
|
67
30
|
*/
|
|
68
|
-
export function
|
|
69
|
-
name: string,
|
|
70
|
-
param?: string,
|
|
71
|
-
handler?: (param?: string) => void | Promise<void>,
|
|
72
|
-
taskId?: number
|
|
73
|
-
): number {
|
|
74
|
-
if (!clickgo.getNative()) {
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
|
77
|
-
const id = ++sendId;
|
|
78
|
-
sendList.push({
|
|
79
|
-
'id': id,
|
|
80
|
-
'name': name,
|
|
81
|
-
'param': param
|
|
82
|
-
});
|
|
83
|
-
if (handler) {
|
|
84
|
-
on(name, handler, id, true, taskId);
|
|
85
|
-
}
|
|
86
|
-
return id;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* --- 监听 native 传递的指令 ---
|
|
91
|
-
* @param name 指令名
|
|
92
|
-
* @param handler 指令接收回调
|
|
93
|
-
* @param id 可选,监听特定 id 的指令
|
|
94
|
-
* @param once 可选,默认为非一次性监听
|
|
95
|
-
* @param taskId 仅在任务活跃时可监听,App 模式下无效
|
|
96
|
-
*/
|
|
97
|
-
export function on(
|
|
98
|
-
name: string,
|
|
99
|
-
handler: (param?: string) => void | Promise<void>,
|
|
100
|
-
id?: number,
|
|
101
|
-
once: boolean = false,
|
|
102
|
-
taskId?: number
|
|
103
|
-
): void {
|
|
31
|
+
export function invoke(name: string, ...param: any[]): any {
|
|
104
32
|
if (!clickgo.getNative()) {
|
|
105
33
|
return;
|
|
106
34
|
}
|
|
107
|
-
|
|
108
|
-
listeners[name] = [];
|
|
109
|
-
}
|
|
110
|
-
listeners[name].push({
|
|
111
|
-
'id': id ?? 0,
|
|
112
|
-
'once': once,
|
|
113
|
-
'taskId': taskId,
|
|
114
|
-
'handler': handler
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* --- 监听一次 native 传递的指令 ---
|
|
120
|
-
* @param name 指令名
|
|
121
|
-
* @param handler 指令接收回调
|
|
122
|
-
* @param id 可选,监听特定 id 的指令
|
|
123
|
-
* @param taskId 仅在任务活跃时可监听,App 模式下无效
|
|
124
|
-
*/
|
|
125
|
-
export function once(
|
|
126
|
-
name: string,
|
|
127
|
-
handler: (param?: string) => void | Promise<void>,
|
|
128
|
-
id?: number,
|
|
129
|
-
taskId?: number
|
|
130
|
-
): void {
|
|
131
|
-
on(name, handler, id, true, taskId);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* --- 取消监听 native 指令 ---
|
|
136
|
-
* @param name 指令名
|
|
137
|
-
* @param handler 绑定监听时的回调函数
|
|
138
|
-
* @param taskId 校验 taskId,为空则不校验,但 App 模式下无效
|
|
139
|
-
*/
|
|
140
|
-
export function off(name: string, handler: (param?: string) => void | Promise<void>, taskId?: number): void {
|
|
141
|
-
if (!listeners[name]) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
for (let i = 0; i < listeners[name].length; ++i) {
|
|
145
|
-
if (listeners[name][i].handler !== handler) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (taskId && (listeners[name][i].taskId !== taskId)) {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
listeners[name].splice(i, 1);
|
|
152
|
-
if (listeners[name].length === 0) {
|
|
153
|
-
delete listeners[name];
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
--i;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* --- 清除某个 task 当中的全部本地监听 ---
|
|
162
|
-
* @param taskId 要清除的 task id,App 模式下无效
|
|
163
|
-
*/
|
|
164
|
-
export function clearListener(taskId?: number): void {
|
|
165
|
-
if (!taskId) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
for (const name in listeners) {
|
|
169
|
-
for (let i = 0; i < listeners[name].length; ++i) {
|
|
170
|
-
if (listeners[name][i].taskId !== taskId) {
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
listeners[name].splice(i, 1);
|
|
174
|
-
if (listeners[name].length === 0) {
|
|
175
|
-
delete listeners[name];
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
35
|
+
return (window as any).clickgoNative.invoke(name, ...param);
|
|
180
36
|
}
|
|
181
37
|
|
|
182
38
|
// --- 常见操作 ---
|
|
183
39
|
|
|
184
40
|
export function max(): void {
|
|
185
|
-
|
|
186
|
-
'token': token,
|
|
187
|
-
'state': 'max'
|
|
188
|
-
}));
|
|
41
|
+
invoke('cg-set-state', token, 'max');
|
|
189
42
|
}
|
|
190
43
|
export function min(): void {
|
|
191
|
-
|
|
192
|
-
'token': token,
|
|
193
|
-
'state': 'min'
|
|
194
|
-
}));
|
|
44
|
+
invoke('cg-set-state', token, 'min');
|
|
195
45
|
}
|
|
196
46
|
export function restore(): void {
|
|
197
|
-
|
|
198
|
-
'token': token,
|
|
199
|
-
'state': 'restore'
|
|
200
|
-
}));
|
|
47
|
+
invoke('cg-set-state', token, 'restore');
|
|
201
48
|
}
|
|
202
49
|
export function size(width: number, height: number): void {
|
|
203
|
-
|
|
204
|
-
'token': token,
|
|
205
|
-
'width': width,
|
|
206
|
-
'height': height
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// --- 以下为供 native 调用的内部函数 ---
|
|
211
|
-
|
|
212
|
-
// --- 将 send 值全部提交给 native ---
|
|
213
|
-
export function cgInnerGetSends(): string {
|
|
214
|
-
const json = JSON.stringify(sendList);
|
|
215
|
-
sendList = [];
|
|
216
|
-
return json;
|
|
50
|
+
invoke('cg-set-size', token, width, height);
|
|
217
51
|
}
|
|
218
|
-
|
|
219
|
-
// --- 供 native 调用的回调数据(执行结果) ---
|
|
220
|
-
export function cgInnerReceive(id: number, name: string, result?: string): void {
|
|
221
|
-
if (!listeners[name]) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
for (let i = 0; i < listeners[name].length; ++i) {
|
|
225
|
-
const item = listeners[name][i];
|
|
226
|
-
if (item.id > 0) {
|
|
227
|
-
if (item.id !== id) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
const r = item.handler(result);
|
|
231
|
-
if (r instanceof Promise) {
|
|
232
|
-
r.catch(function(e) {
|
|
233
|
-
console.log(e);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
const r = item.handler(result);
|
|
239
|
-
if (r instanceof Promise) {
|
|
240
|
-
r.catch(function(e) {
|
|
241
|
-
console.log(e);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (item.once) {
|
|
246
|
-
listeners[name].splice(i, 1);
|
|
247
|
-
--i;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
(window as any).clickGoNative = {
|
|
253
|
-
isReady: true,
|
|
254
|
-
cgInnerGetSends: cgInnerGetSends,
|
|
255
|
-
cgInnerReceive: cgInnerReceive
|
|
256
|
-
};
|
package/dist/lib/task.js
CHANGED
|
@@ -305,15 +305,11 @@ function run(url, opt = {}) {
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
if (task.id === 1) {
|
|
308
|
-
|
|
308
|
+
native.invoke('cg-init', native.getToken());
|
|
309
309
|
}
|
|
310
310
|
if (clickgo.getNative() && opt.sync) {
|
|
311
311
|
f.vroot.$refs.form.isNativeSync = true;
|
|
312
|
-
|
|
313
|
-
'token': clickgo.native.getToken(),
|
|
314
|
-
'width': f.vroot.$refs.form.widthData,
|
|
315
|
-
'height': f.vroot.$refs.form.heightData
|
|
316
|
-
}));
|
|
312
|
+
native.invoke('cg-set-size', native.getToken(), f.vroot.$refs.form.widthData, f.vroot.$refs.form.heightData);
|
|
317
313
|
window.addEventListener('resize', function () {
|
|
318
314
|
f.vroot.$refs.form.setPropData('width', window.innerWidth);
|
|
319
315
|
f.vroot.$refs.form.setPropData('height', window.innerHeight);
|
|
@@ -329,9 +325,7 @@ function end(taskId) {
|
|
|
329
325
|
return true;
|
|
330
326
|
}
|
|
331
327
|
if (clickgo.getNative() && task.main) {
|
|
332
|
-
|
|
333
|
-
'token': clickgo.native.getToken()
|
|
334
|
-
}));
|
|
328
|
+
native.invoke('cg-close', native.getToken());
|
|
335
329
|
}
|
|
336
330
|
const fid = form.getMaxZIndexID({
|
|
337
331
|
'taskIds': [task.id]
|
|
@@ -362,7 +356,6 @@ function end(taskId) {
|
|
|
362
356
|
clearTimeout(parseFloat(timer));
|
|
363
357
|
}
|
|
364
358
|
}
|
|
365
|
-
native.clearListener(taskId);
|
|
366
359
|
dom.clearWatchSize(taskId);
|
|
367
360
|
delete exports.list[taskId];
|
|
368
361
|
core.trigger('taskEnded', taskId);
|
package/dist/lib/task.ts
CHANGED
|
@@ -372,16 +372,12 @@ export async function run(url: string, opt: types.ITaskRunOptions = {}): Promise
|
|
|
372
372
|
}
|
|
373
373
|
// --- 给 native 发送任务启动成功的消息 ---
|
|
374
374
|
if (task.id === 1) {
|
|
375
|
-
|
|
375
|
+
native.invoke('cg-init', native.getToken());
|
|
376
376
|
}
|
|
377
377
|
// --- 提交 sync ---
|
|
378
378
|
if (clickgo.getNative() && opt.sync) {
|
|
379
379
|
f.vroot.$refs.form.isNativeSync = true;
|
|
380
|
-
|
|
381
|
-
'token': clickgo.native.getToken(),
|
|
382
|
-
'width': f.vroot.$refs.form.widthData,
|
|
383
|
-
'height': f.vroot.$refs.form.heightData
|
|
384
|
-
}));
|
|
380
|
+
native.invoke('cg-set-size', native.getToken(), f.vroot.$refs.form.widthData, f.vroot.$refs.form.heightData);
|
|
385
381
|
window.addEventListener('resize', function(): void {
|
|
386
382
|
f.vroot.$refs.form.setPropData('width', window.innerWidth);
|
|
387
383
|
f.vroot.$refs.form.setPropData('height', window.innerHeight);
|
|
@@ -401,9 +397,7 @@ export function end(taskId: number): boolean {
|
|
|
401
397
|
}
|
|
402
398
|
// --- 如果是 native 模式 ---
|
|
403
399
|
if (clickgo.getNative() && task.main) {
|
|
404
|
-
|
|
405
|
-
'token': clickgo.native.getToken()
|
|
406
|
-
}));
|
|
400
|
+
native.invoke('cg-close', native.getToken());
|
|
407
401
|
}
|
|
408
402
|
// --- 获取最大的 z index 窗体,并让他获取焦点 ---
|
|
409
403
|
const fid = form.getMaxZIndexID({
|
|
@@ -440,7 +434,6 @@ export function end(taskId: number): boolean {
|
|
|
440
434
|
}
|
|
441
435
|
}
|
|
442
436
|
// --- 移除各类监听 ---
|
|
443
|
-
native.clearListener(taskId);
|
|
444
437
|
dom.clearWatchSize(taskId);
|
|
445
438
|
// --- 移除 task ---
|
|
446
439
|
delete list[taskId];
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -61,10 +61,12 @@ export interface IGlobalEvents {
|
|
|
61
61
|
taskStartedHandler: null | ((taskId: number) => void | Promise<void>);
|
|
62
62
|
/** --- 任务结束后触发 --- */
|
|
63
63
|
taskEndedHandler: null | ((taskId: number) => void | Promise<void>);
|
|
64
|
+
/** --- launcher 的文件夹名称被修改后触发 --- */
|
|
65
|
+
launcherFolderNameChangedHandler: null | ((id: string, name: string) => void | Promise<void>);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/** --- Core Config 属性列表 --- */
|
|
67
|
-
export type TConfigName = 'locale' | 'task.position' | 'task.pin' | 'desktop.icon.storage' | 'desktop.icon.recycler' | 'desktop.wallpaper' | 'desktop.path';
|
|
69
|
+
export type TConfigName = 'locale' | 'task.position' | 'task.pin' | 'desktop.icon.storage' | 'desktop.icon.recycler' | 'desktop.wallpaper' | 'desktop.path' | 'launcher.list';
|
|
68
70
|
|
|
69
71
|
/** --- Config 对象 --- */
|
|
70
72
|
export interface IConfig {
|
|
@@ -75,10 +77,20 @@ export interface IConfig {
|
|
|
75
77
|
['desktop.icon.recycler']: boolean;
|
|
76
78
|
['desktop.wallpaper']: string | null;
|
|
77
79
|
['desktop.path']: string | null;
|
|
80
|
+
['launcher.list']: IConfigLauncherItem[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** --- Launcher 的 item 对象 --- */
|
|
84
|
+
export interface IConfigLauncherItem {
|
|
85
|
+
'id'?: string;
|
|
86
|
+
'name': string;
|
|
87
|
+
'path'?: string;
|
|
88
|
+
'icon'?: string;
|
|
89
|
+
'list'?: Array<{ 'id'?: string; 'name': string; 'path': string; 'icon': string; }>;
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
/** --- 全局事件类型 --- */
|
|
81
|
-
export type TGlobalEvent = 'error' | 'screenResize' | 'configChanged' | 'formCreated' | 'formRemoved' | 'formTitleChanged' | 'formIconChanged' | 'formStateMinChanged' | 'formStateMaxChanged' | 'formShowChanged' | 'formFocused' | 'formBlurred' | 'formFlash' | 'taskStarted' | 'taskEnded';
|
|
93
|
+
export type TGlobalEvent = 'error' | 'screenResize' | 'configChanged' | 'formCreated' | 'formRemoved' | 'formTitleChanged' | 'formIconChanged' | 'formStateMinChanged' | 'formStateMaxChanged' | 'formShowChanged' | 'formFocused' | 'formBlurred' | 'formFlash' | 'taskStarted' | 'taskEnded' | 'launcherFolderNameChanged';
|
|
82
94
|
|
|
83
95
|
export interface ICoreFetchAppOptions {
|
|
84
96
|
'notifyId'?: number;
|
|
@@ -627,6 +639,7 @@ export interface IVueObject {
|
|
|
627
639
|
cb: (n: any, o: any) => void | Promise<void>,
|
|
628
640
|
opt: Record<string, string | boolean>
|
|
629
641
|
): void;
|
|
642
|
+
h(tag: string, props?: Record<string, any> | any[], list?: any[]): any;
|
|
630
643
|
}
|
|
631
644
|
|
|
632
645
|
export type IVueOptionMergeFunction = (to: unknown, from: unknown, instance: IVue) => any;
|