clickgo 3.0.4-dev5 → 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.
@@ -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 send(
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
- if (!listeners[name]) {
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
- send('cg-set-state', JSON.stringify({
186
- 'token': token,
187
- 'state': 'max'
188
- }));
41
+ invoke('cg-set-state', token, 'max');
189
42
  }
190
43
  export function min(): void {
191
- send('cg-set-state', JSON.stringify({
192
- 'token': token,
193
- 'state': 'min'
194
- }));
44
+ invoke('cg-set-state', token, 'min');
195
45
  }
196
46
  export function restore(): void {
197
- send('cg-set-state', JSON.stringify({
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
- send('cg-set-size', JSON.stringify({
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
@@ -170,7 +170,8 @@ function run(url, opt = {}) {
170
170
  }) : undefined;
171
171
  const app = yield core.fetchApp(url, {
172
172
  'notifyId': notifyId,
173
- 'current': ntask ? ntask.path : undefined
173
+ 'current': ntask ? ntask.path : undefined,
174
+ 'progress': opt.progress
174
175
  });
175
176
  if (notifyId) {
176
177
  setTimeout(function () {
@@ -276,13 +277,6 @@ function run(url, opt = {}) {
276
277
  core.trigger('taskEnded', task.id);
277
278
  return f - 100;
278
279
  }
279
- if (clickgo.getNative() && opt.sync) {
280
- f.vroot.$refs.form.isNativeSync = true;
281
- window.addEventListener('resize', function () {
282
- f.vroot.$refs.form.setPropData('width', window.innerWidth);
283
- f.vroot.$refs.form.setPropData('height', window.innerHeight);
284
- });
285
- }
286
280
  if (app.config.style && app.files[app.config.style + '.css']) {
287
281
  const style = app.files[app.config.style + '.css'];
288
282
  const r = tool.stylePrepend(style, 'cg-task' + task.id.toString() + '_');
@@ -311,7 +305,15 @@ function run(url, opt = {}) {
311
305
  }
312
306
  }
313
307
  if (task.id === 1) {
314
- clickgo.native.send('cg-init', clickgo.native.getToken());
308
+ native.invoke('cg-init', native.getToken());
309
+ }
310
+ if (clickgo.getNative() && opt.sync) {
311
+ f.vroot.$refs.form.isNativeSync = true;
312
+ native.invoke('cg-set-size', native.getToken(), f.vroot.$refs.form.widthData, f.vroot.$refs.form.heightData);
313
+ window.addEventListener('resize', function () {
314
+ f.vroot.$refs.form.setPropData('width', window.innerWidth);
315
+ f.vroot.$refs.form.setPropData('height', window.innerHeight);
316
+ });
315
317
  }
316
318
  return task.id;
317
319
  });
@@ -323,9 +325,7 @@ function end(taskId) {
323
325
  return true;
324
326
  }
325
327
  if (clickgo.getNative() && task.main) {
326
- clickgo.native.send('cg-main-close', JSON.stringify({
327
- 'token': clickgo.native.getToken()
328
- }));
328
+ native.invoke('cg-close', native.getToken());
329
329
  }
330
330
  const fid = form.getMaxZIndexID({
331
331
  'taskIds': [task.id]
@@ -356,7 +356,6 @@ function end(taskId) {
356
356
  clearTimeout(parseFloat(timer));
357
357
  }
358
358
  }
359
- native.clearListener(taskId);
360
359
  dom.clearWatchSize(taskId);
361
360
  delete exports.list[taskId];
362
361
  core.trigger('taskEnded', taskId);
@@ -656,12 +655,12 @@ function refreshSystemPosition() {
656
655
  case 'left':
657
656
  case 'right': {
658
657
  form.vroot.$refs.form.setPropData('width', 'auto');
659
- form.vroot.$refs.form.setPropData('height', document.body.clientHeight);
658
+ form.vroot.$refs.form.setPropData('height', window.innerHeight);
660
659
  break;
661
660
  }
662
661
  case 'top':
663
662
  case 'bottom': {
664
- form.vroot.$refs.form.setPropData('width', document.body.clientWidth);
663
+ form.vroot.$refs.form.setPropData('width', window.innerWidth);
665
664
  form.vroot.$refs.form.setPropData('height', 'auto');
666
665
  break;
667
666
  }
@@ -676,7 +675,7 @@ function refreshSystemPosition() {
676
675
  }
677
676
  case 'right': {
678
677
  exports.systemTaskInfo.length = form.vroot.$el.offsetWidth;
679
- form.vroot.$refs.form.setPropData('left', document.body.clientWidth - exports.systemTaskInfo.length);
678
+ form.vroot.$refs.form.setPropData('left', window.innerWidth - exports.systemTaskInfo.length);
680
679
  form.vroot.$refs.form.setPropData('top', 0);
681
680
  break;
682
681
  }
@@ -689,7 +688,7 @@ function refreshSystemPosition() {
689
688
  case 'bottom': {
690
689
  exports.systemTaskInfo.length = form.vroot.$el.offsetHeight;
691
690
  form.vroot.$refs.form.setPropData('left', 0);
692
- form.vroot.$refs.form.setPropData('top', document.body.clientHeight - exports.systemTaskInfo.length);
691
+ form.vroot.$refs.form.setPropData('top', window.innerHeight - exports.systemTaskInfo.length);
693
692
  break;
694
693
  }
695
694
  }
package/dist/lib/task.ts CHANGED
@@ -222,7 +222,8 @@ export async function run(url: string, opt: types.ITaskRunOptions = {}): Promise
222
222
  }) : undefined;
223
223
  const app: types.IApp | null = await core.fetchApp(url, {
224
224
  'notifyId': notifyId,
225
- 'current': ntask ? ntask.path : undefined
225
+ 'current': ntask ? ntask.path : undefined,
226
+ 'progress': opt.progress
226
227
  });
227
228
  if (notifyId) {
228
229
  setTimeout(function(): void {
@@ -339,13 +340,6 @@ export async function run(url: string, opt: types.ITaskRunOptions = {}): Promise
339
340
  core.trigger('taskEnded', task.id);
340
341
  return f - 100;
341
342
  }
342
- if (clickgo.getNative() && opt.sync) {
343
- f.vroot.$refs.form.isNativeSync = true;
344
- window.addEventListener('resize', function(): void {
345
- f.vroot.$refs.form.setPropData('width', window.innerWidth);
346
- f.vroot.$refs.form.setPropData('height', window.innerHeight);
347
- });
348
- }
349
343
  // --- 设置 global style(如果 form 创建失败,就不设置 global style 了) ---
350
344
  if (app.config.style && app.files[app.config.style + '.css']) {
351
345
  const style = app.files[app.config.style + '.css'] as string;
@@ -378,7 +372,16 @@ export async function run(url: string, opt: types.ITaskRunOptions = {}): Promise
378
372
  }
379
373
  // --- 给 native 发送任务启动成功的消息 ---
380
374
  if (task.id === 1) {
381
- clickgo.native.send('cg-init', clickgo.native.getToken());
375
+ native.invoke('cg-init', native.getToken());
376
+ }
377
+ // --- 提交 sync ---
378
+ if (clickgo.getNative() && opt.sync) {
379
+ f.vroot.$refs.form.isNativeSync = true;
380
+ native.invoke('cg-set-size', native.getToken(), f.vroot.$refs.form.widthData, f.vroot.$refs.form.heightData);
381
+ window.addEventListener('resize', function(): void {
382
+ f.vroot.$refs.form.setPropData('width', window.innerWidth);
383
+ f.vroot.$refs.form.setPropData('height', window.innerHeight);
384
+ });
382
385
  }
383
386
  return task.id;
384
387
  }
@@ -394,9 +397,7 @@ export function end(taskId: number): boolean {
394
397
  }
395
398
  // --- 如果是 native 模式 ---
396
399
  if (clickgo.getNative() && task.main) {
397
- clickgo.native.send('cg-main-close', JSON.stringify({
398
- 'token': clickgo.native.getToken()
399
- }));
400
+ native.invoke('cg-close', native.getToken());
400
401
  }
401
402
  // --- 获取最大的 z index 窗体,并让他获取焦点 ---
402
403
  const fid = form.getMaxZIndexID({
@@ -433,7 +434,6 @@ export function end(taskId: number): boolean {
433
434
  }
434
435
  }
435
436
  // --- 移除各类监听 ---
436
- native.clearListener(taskId);
437
437
  dom.clearWatchSize(taskId);
438
438
  // --- 移除 task ---
439
439
  delete list[taskId];
@@ -815,12 +815,12 @@ export function refreshSystemPosition(): void {
815
815
  case 'left':
816
816
  case 'right': {
817
817
  form.vroot.$refs.form.setPropData('width', 'auto');
818
- form.vroot.$refs.form.setPropData('height', document.body.clientHeight);
818
+ form.vroot.$refs.form.setPropData('height', window.innerHeight);
819
819
  break;
820
820
  }
821
821
  case 'top':
822
822
  case 'bottom': {
823
- form.vroot.$refs.form.setPropData('width', document.body.clientWidth);
823
+ form.vroot.$refs.form.setPropData('width', window.innerWidth);
824
824
  form.vroot.$refs.form.setPropData('height', 'auto');
825
825
  break;
826
826
  }
@@ -835,7 +835,7 @@ export function refreshSystemPosition(): void {
835
835
  }
836
836
  case 'right': {
837
837
  systemTaskInfo.length = form.vroot.$el.offsetWidth;
838
- form.vroot.$refs.form.setPropData('left', document.body.clientWidth - systemTaskInfo.length);
838
+ form.vroot.$refs.form.setPropData('left', window.innerWidth - systemTaskInfo.length);
839
839
  form.vroot.$refs.form.setPropData('top', 0);
840
840
  break;
841
841
  }
@@ -848,7 +848,7 @@ export function refreshSystemPosition(): void {
848
848
  case 'bottom': {
849
849
  systemTaskInfo.length = form.vroot.$el.offsetHeight;
850
850
  form.vroot.$refs.form.setPropData('left', 0);
851
- form.vroot.$refs.form.setPropData('top', document.body.clientHeight - systemTaskInfo.length);
851
+ form.vroot.$refs.form.setPropData('top', window.innerHeight - systemTaskInfo.length);
852
852
  break;
853
853
  }
854
854
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clickgo",
3
- "version": "3.0.4-dev5",
3
+ "version": "3.0.7-dev8",
4
4
  "description": "Background interface, software interface, mobile phone APP interface operation library.",
5
5
  "keywords": [
6
6
  "deskrt",
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;