clickgo 3.0.7-dev8 → 3.1.0-dev9

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/dist/lib/core.js CHANGED
@@ -9,13 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getAvailArea = exports.fetchApp = exports.readApp = exports.trigger = exports.removeSystemEventListener = exports.setSystemEventListener = exports.globalEvents = exports.getModule = exports.initModules = exports.regModule = exports.cdn = exports.config = void 0;
12
+ exports.getAvailArea = exports.fetchApp = exports.readApp = exports.trigger = exports.getModule = exports.initModules = exports.regModule = exports.boot = exports.getCdn = exports.AbstractApp = exports.config = void 0;
13
13
  const clickgo = require("../clickgo");
14
14
  const fs = require("./fs");
15
15
  const form = require("./form");
16
16
  const task = require("./task");
17
17
  const tool = require("./tool");
18
+ const control = require("./control");
19
+ const theme = require("./theme");
18
20
  const zip = require("./zip");
21
+ const dom = require("./dom");
19
22
  const configOrigin = {
20
23
  'locale': 'en',
21
24
  'task.position': 'bottom',
@@ -36,7 +39,223 @@ exports.config = clickgo.vue.reactive({
36
39
  'desktop.path': null,
37
40
  'launcher.list': []
38
41
  });
39
- exports.cdn = '';
42
+ class AbstractApp {
43
+ get filename() {
44
+ return '';
45
+ }
46
+ get taskId() {
47
+ return 0;
48
+ }
49
+ set taskId(v) {
50
+ form.notify({
51
+ 'title': 'Error',
52
+ 'content': `The software tries to modify the system variable "taskId" to "${v}".\nPath: ${this.filename}`,
53
+ 'type': 'danger'
54
+ });
55
+ }
56
+ config(config) {
57
+ var _a;
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const t = task.list[this.taskId];
60
+ if (!t) {
61
+ return false;
62
+ }
63
+ t.config = config;
64
+ if (t.app.net) {
65
+ if (!t.config.files) {
66
+ return false;
67
+ }
68
+ const files = t.config.files;
69
+ const net = t.app.net;
70
+ yield new Promise(function (resolve) {
71
+ var _a;
72
+ let loaded = 0;
73
+ const total = files.length;
74
+ const beforeTotal = Object.keys(t.app.files).length;
75
+ (_a = net.progress) === null || _a === void 0 ? void 0 : _a.call(net, loaded + beforeTotal, total + beforeTotal);
76
+ for (const file of files) {
77
+ fs.getContent(net.url + file.slice(1), {
78
+ 'current': net.current
79
+ }).then(function (blob) {
80
+ var _a;
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ if (blob === null || typeof blob === 'string') {
83
+ clickgo.form.notify({
84
+ 'title': 'File not found',
85
+ 'content': net.url + file.slice(1),
86
+ 'type': 'danger'
87
+ });
88
+ return;
89
+ }
90
+ const mime = tool.getMimeByPath(file);
91
+ if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
92
+ t.app.files[file] = (yield tool.blob2Text(blob)).replace(/^\ufeff/, '');
93
+ }
94
+ else {
95
+ t.app.files[file] = blob;
96
+ }
97
+ ++loaded;
98
+ (_a = net.progress) === null || _a === void 0 ? void 0 : _a.call(net, loaded + beforeTotal, total + beforeTotal);
99
+ if (net.notify) {
100
+ form.notifyProgress(net.notify, (loaded / total) / 2 + 0.5);
101
+ }
102
+ if (loaded < total) {
103
+ return;
104
+ }
105
+ resolve();
106
+ });
107
+ }).catch(function () {
108
+ var _a;
109
+ ++loaded;
110
+ (_a = net.progress) === null || _a === void 0 ? void 0 : _a.call(net, loaded + beforeTotal, total + beforeTotal);
111
+ if (net.notify) {
112
+ form.notifyProgress(net.notify, (loaded / total) / 2 + 0.5);
113
+ }
114
+ if (loaded < total) {
115
+ return;
116
+ }
117
+ resolve();
118
+ });
119
+ }
120
+ });
121
+ if (net.notify) {
122
+ setTimeout(function () {
123
+ form.hideNotify(net.notify);
124
+ }, 2000);
125
+ }
126
+ }
127
+ if (!(yield control.init(this.taskId))) {
128
+ return false;
129
+ }
130
+ if ((_a = config.themes) === null || _a === void 0 ? void 0 : _a.length) {
131
+ for (let path of config.themes) {
132
+ path += '.cgt';
133
+ path = tool.urlResolve('/', path);
134
+ const file = yield fs.getContent(path, {
135
+ 'files': t.app.files,
136
+ 'current': t.current
137
+ });
138
+ if (file && typeof file !== 'string') {
139
+ const th = yield theme.read(file);
140
+ if (th) {
141
+ yield theme.load(th, t.id);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ else {
147
+ if (theme.global) {
148
+ yield theme.load(undefined, this.taskId);
149
+ }
150
+ }
151
+ if (config.locales) {
152
+ for (let path in config.locales) {
153
+ const locale = config.locales[path];
154
+ if (!path.endsWith('.json')) {
155
+ path += '.json';
156
+ }
157
+ const lcontent = yield fs.getContent(path, {
158
+ 'encoding': 'utf8',
159
+ 'files': t.app.files,
160
+ 'current': t.current
161
+ });
162
+ if (!lcontent) {
163
+ continue;
164
+ }
165
+ try {
166
+ const data = JSON.parse(lcontent);
167
+ task.loadLocaleData(locale, data, '', t.id);
168
+ }
169
+ catch (_b) {
170
+ }
171
+ }
172
+ }
173
+ if (config.style) {
174
+ const style = yield fs.getContent(config.style + '.css', {
175
+ 'encoding': 'utf8',
176
+ 'files': t.app.files,
177
+ 'current': t.current
178
+ });
179
+ if (style) {
180
+ const r = tool.stylePrepend(style, 'cg-task' + this.taskId.toString() + '_');
181
+ dom.pushStyle(this.taskId, yield tool.styleUrl2DataUrl(config.style, r.style, t.app.files));
182
+ }
183
+ }
184
+ if (config.icon) {
185
+ const icon = yield fs.getContent(config.icon, {
186
+ 'files': t.app.files,
187
+ 'current': t.current
188
+ });
189
+ if (icon && typeof icon !== 'string') {
190
+ t.app.icon = yield tool.blob2DataUrl(icon);
191
+ }
192
+ }
193
+ t.class = this;
194
+ return true;
195
+ });
196
+ }
197
+ run(form) {
198
+ if (typeof form === 'number') {
199
+ const msg = 'Application run error, Form creation failed (' + form.toString() + ').';
200
+ trigger('error', this.taskId, 0, new Error(msg), msg);
201
+ return;
202
+ }
203
+ form.show();
204
+ }
205
+ onError() {
206
+ return;
207
+ }
208
+ onScreenResize() {
209
+ return;
210
+ }
211
+ onConfigChanged() {
212
+ return;
213
+ }
214
+ onFormCreated() {
215
+ return;
216
+ }
217
+ onFormRemoved() {
218
+ return;
219
+ }
220
+ onFormTitleChanged() {
221
+ return;
222
+ }
223
+ onFormIconChanged() {
224
+ return;
225
+ }
226
+ onFormStateMinChanged() {
227
+ return;
228
+ }
229
+ onFormStateMaxChanged() {
230
+ return;
231
+ }
232
+ onFormShowChanged() {
233
+ return;
234
+ }
235
+ onFormFocused() {
236
+ return;
237
+ }
238
+ onFormBlurred() {
239
+ return;
240
+ }
241
+ onFormFlash() {
242
+ return;
243
+ }
244
+ onTaskStarted() {
245
+ return;
246
+ }
247
+ onTaskEnded() {
248
+ return;
249
+ }
250
+ onLauncherFolderNameChanged() {
251
+ return;
252
+ }
253
+ }
254
+ exports.AbstractApp = AbstractApp;
255
+ function getCdn() {
256
+ return loader.cdn;
257
+ }
258
+ exports.getCdn = getCdn;
40
259
  clickgo.vue.watch(exports.config, function () {
41
260
  for (const key in configOrigin) {
42
261
  if (exports.config[key] !== undefined) {
@@ -90,7 +309,7 @@ const modules = {
90
309
  func: function () {
91
310
  return __awaiter(this, void 0, void 0, function* () {
92
311
  return new Promise(function (resolve, reject) {
93
- fetch(loader.cdn + '/npm/monaco-editor@0.33.0/min/vs/loader.js').then(function (r) {
312
+ fetch(loader.cdn + '/npm/monaco-editor@0.34.1/min/vs/loader.js').then(function (r) {
94
313
  return r.blob();
95
314
  }).then(function (b) {
96
315
  return tool.blob2DataUrl(b);
@@ -195,32 +414,29 @@ function getModule(name) {
195
414
  return modules[name].obj;
196
415
  }
197
416
  exports.getModule = getModule;
198
- exports.globalEvents = {
199
- errorHandler: null,
200
- screenResizeHandler: function () {
417
+ const globalEvents = {
418
+ screenResize: function () {
201
419
  form.refreshMaxPosition();
202
420
  },
203
- configChangedHandler: null,
204
- formCreatedHandler: null,
205
- formRemovedHandler: function (taskId, formId) {
421
+ formRemoved: function (taskId, formId) {
206
422
  if (!form.simpleSystemTaskRoot.forms[formId]) {
207
423
  return;
208
424
  }
209
425
  delete form.simpleSystemTaskRoot.forms[formId];
210
426
  },
211
- formTitleChangedHandler: function (taskId, formId, title) {
427
+ formTitleChanged: function (taskId, formId, title) {
212
428
  if (!form.simpleSystemTaskRoot.forms[formId]) {
213
429
  return;
214
430
  }
215
431
  form.simpleSystemTaskRoot.forms[formId].title = title;
216
432
  },
217
- formIconChangedHandler: function (taskId, formId, icon) {
433
+ formIconChanged: function (taskId, formId, icon) {
218
434
  if (!form.simpleSystemTaskRoot.forms[formId]) {
219
435
  return;
220
436
  }
221
437
  form.simpleSystemTaskRoot.forms[formId].icon = icon;
222
438
  },
223
- formStateMinChangedHandler: function (taskId, formId, state) {
439
+ formStateMinChanged: function (taskId, formId, state) {
224
440
  if (task.systemTaskInfo.taskId > 0) {
225
441
  return;
226
442
  }
@@ -240,94 +456,34 @@ exports.globalEvents = {
240
456
  }
241
457
  delete form.simpleSystemTaskRoot.forms[formId];
242
458
  }
243
- },
244
- formStateMaxChangedHandler: null,
245
- formShowChangedHandler: null,
246
- formFocusedHandler: null,
247
- formBlurredHandler: null,
248
- formFlashHandler: null,
249
- taskStartedHandler: null,
250
- taskEndedHandler: null,
251
- launcherFolderNameChangedHandler: null
252
- };
253
- function setSystemEventListener(name, func, formId, taskId) {
254
- if (!taskId) {
255
- return;
256
459
  }
257
- const t = task.list[taskId];
258
- if (!t) {
259
- return;
260
- }
261
- if (!formId) {
262
- return;
263
- }
264
- const f = t.forms[formId];
265
- if (!f) {
266
- return;
267
- }
268
- f.events[name] = func;
269
- }
270
- exports.setSystemEventListener = setSystemEventListener;
271
- function removeSystemEventListener(name, formId, taskId) {
272
- if (!taskId) {
273
- return;
274
- }
275
- const t = task.list[taskId];
276
- if (!t) {
277
- return;
278
- }
279
- if (!formId) {
280
- return;
281
- }
282
- const f = t.forms[formId];
283
- if (!f) {
284
- return;
285
- }
286
- delete f.events[name];
287
- }
288
- exports.removeSystemEventListener = removeSystemEventListener;
460
+ };
289
461
  function trigger(name, taskId = 0, formId = 0, param1 = '', param2 = '') {
290
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
462
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
463
+ const eventName = 'on' + name[0].toUpperCase() + name.slice(1);
291
464
  switch (name) {
292
465
  case 'error': {
293
466
  if (typeof taskId !== 'number' || typeof formId !== 'number') {
294
467
  break;
295
468
  }
296
- const r = (_a = exports.globalEvents.errorHandler) === null || _a === void 0 ? void 0 : _a.call(exports.globalEvents, taskId, formId, param1, param2);
297
- if (r && (r instanceof Promise)) {
298
- r.catch(function (e) {
299
- console.log(e);
300
- });
301
- }
469
+ exports.boot[eventName](taskId, formId, param1, param2);
302
470
  for (const tid in task.list) {
303
471
  const t = task.list[tid];
472
+ (_a = t.class) === null || _a === void 0 ? void 0 : _a[eventName](taskId, formId, param1, param2);
304
473
  for (const fid in t.forms) {
305
- const r = (_c = (_b = t.forms[fid].events)[name]) === null || _c === void 0 ? void 0 : _c.call(_b, taskId, formId, param1, param2);
306
- if (r instanceof Promise) {
307
- r.catch(function (e) {
308
- console.log(e);
309
- });
310
- }
474
+ (_c = (_b = t.forms[fid].vroot)[eventName]) === null || _c === void 0 ? void 0 : _c.call(_b, taskId, formId, param1, param2);
311
475
  }
312
476
  }
313
477
  break;
314
478
  }
315
479
  case 'screenResize': {
316
- const r = (_d = exports.globalEvents.screenResizeHandler) === null || _d === void 0 ? void 0 : _d.call(exports.globalEvents);
317
- if (r && (r instanceof Promise)) {
318
- r.catch(function (e) {
319
- console.log(e);
320
- });
321
- }
480
+ globalEvents.screenResize();
481
+ exports.boot[eventName]();
322
482
  for (const tid in task.list) {
323
483
  const t = task.list[tid];
484
+ (_d = t.class) === null || _d === void 0 ? void 0 : _d[eventName]();
324
485
  for (const fid in t.forms) {
325
- const r = (_f = (_e = t.forms[fid].events)[name]) === null || _f === void 0 ? void 0 : _f.call(_e);
326
- if (r instanceof Promise) {
327
- r.catch(function (e) {
328
- console.log(e);
329
- });
330
- }
486
+ (_f = (_e = t.forms[fid].vroot)[eventName]) === null || _f === void 0 ? void 0 : _f.call(_e);
331
487
  }
332
488
  }
333
489
  break;
@@ -336,53 +492,38 @@ function trigger(name, taskId = 0, formId = 0, param1 = '', param2 = '') {
336
492
  if ((typeof taskId !== 'string') || (typeof formId === 'number')) {
337
493
  break;
338
494
  }
339
- const r = (_g = exports.globalEvents.configChangedHandler) === null || _g === void 0 ? void 0 : _g.call(exports.globalEvents, taskId, formId);
340
- if (r && (r instanceof Promise)) {
341
- r.catch(function (e) {
342
- console.log(e);
343
- });
344
- }
495
+ exports.boot[eventName]();
345
496
  for (const tid in task.list) {
346
497
  const t = task.list[tid];
498
+ (_g = t.class) === null || _g === void 0 ? void 0 : _g[eventName](taskId, formId);
347
499
  for (const fid in t.forms) {
348
- const r = (_j = (_h = t.forms[fid].events)[name]) === null || _j === void 0 ? void 0 : _j.call(_h, taskId, formId);
349
- if (r instanceof Promise) {
350
- r.catch(function (e) {
351
- console.log(e);
352
- });
353
- }
500
+ (_j = (_h = t.forms[fid].vroot)[eventName]) === null || _j === void 0 ? void 0 : _j.call(_h, taskId, formId);
354
501
  }
355
502
  }
356
503
  break;
357
504
  }
358
505
  case 'formCreated':
359
506
  case 'formRemoved': {
360
- (_l = (_k = exports.globalEvents)[name + 'Handler']) === null || _l === void 0 ? void 0 : _l.call(_k, taskId, formId, param1, param2);
507
+ (_l = (_k = globalEvents)[name]) === null || _l === void 0 ? void 0 : _l.call(_k, taskId, formId, param1, param2);
508
+ exports.boot[eventName](taskId, formId, param1, param2);
361
509
  for (const tid in task.list) {
362
510
  const t = task.list[tid];
511
+ (_m = t.class) === null || _m === void 0 ? void 0 : _m[eventName](taskId, formId, param1, param2);
363
512
  for (const fid in t.forms) {
364
- const r = (_o = (_m = t.forms[fid].events)[name]) === null || _o === void 0 ? void 0 : _o.call(_m, taskId, formId, param1, param2);
365
- if (r instanceof Promise) {
366
- r.catch(function (e) {
367
- console.log(e);
368
- });
369
- }
513
+ (_p = (_o = t.forms[fid].vroot)[eventName]) === null || _p === void 0 ? void 0 : _p.call(_o, taskId, formId, param1, param2);
370
514
  }
371
515
  }
372
516
  break;
373
517
  }
374
518
  case 'formTitleChanged':
375
519
  case 'formIconChanged': {
376
- (_q = (_p = exports.globalEvents)[name + 'Handler']) === null || _q === void 0 ? void 0 : _q.call(_p, taskId, formId, param1);
520
+ (_r = (_q = globalEvents)[name]) === null || _r === void 0 ? void 0 : _r.call(_q, taskId, formId, param1);
521
+ exports.boot[eventName](taskId, formId, param1);
377
522
  for (const tid in task.list) {
378
523
  const t = task.list[tid];
524
+ (_s = t.class) === null || _s === void 0 ? void 0 : _s[eventName](taskId, formId, param1);
379
525
  for (const fid in t.forms) {
380
- const r = (_s = (_r = t.forms[fid].events)[name]) === null || _s === void 0 ? void 0 : _s.call(_r, taskId, formId, param1);
381
- if (r instanceof Promise) {
382
- r.catch(function (e) {
383
- console.log(e);
384
- });
385
- }
526
+ (_u = (_t = t.forms[fid].vroot)[eventName]) === null || _u === void 0 ? void 0 : _u.call(_t, taskId, formId, param1);
386
527
  }
387
528
  }
388
529
  break;
@@ -390,16 +531,13 @@ function trigger(name, taskId = 0, formId = 0, param1 = '', param2 = '') {
390
531
  case 'formStateMinChanged':
391
532
  case 'formStateMaxChanged':
392
533
  case 'formShowChanged': {
393
- (_u = (_t = exports.globalEvents)[name + 'Handler']) === null || _u === void 0 ? void 0 : _u.call(_t, taskId, formId, param1);
534
+ (_w = (_v = globalEvents)[name]) === null || _w === void 0 ? void 0 : _w.call(_v, taskId, formId, param1);
535
+ exports.boot[eventName](taskId, formId, param1);
394
536
  for (const tid in task.list) {
395
537
  const t = task.list[tid];
538
+ (_x = t.class) === null || _x === void 0 ? void 0 : _x[eventName](taskId, formId, param1);
396
539
  for (const fid in t.forms) {
397
- const r = (_w = (_v = t.forms[fid].events)[name]) === null || _w === void 0 ? void 0 : _w.call(_v, taskId, formId, param1);
398
- if (r instanceof Promise) {
399
- r.catch(function (e) {
400
- console.log(e);
401
- });
402
- }
540
+ (_z = (_y = t.forms[fid].vroot)[eventName]) === null || _z === void 0 ? void 0 : _z.call(_y, taskId, formId, param1);
403
541
  }
404
542
  }
405
543
  break;
@@ -407,32 +545,26 @@ function trigger(name, taskId = 0, formId = 0, param1 = '', param2 = '') {
407
545
  case 'formFocused':
408
546
  case 'formBlurred':
409
547
  case 'formFlash': {
410
- (_y = (_x = exports.globalEvents)[name + 'Handler']) === null || _y === void 0 ? void 0 : _y.call(_x, taskId, formId);
548
+ (_1 = (_0 = globalEvents)[name]) === null || _1 === void 0 ? void 0 : _1.call(_0, taskId, formId);
549
+ exports.boot[eventName](taskId, formId);
411
550
  for (const tid in task.list) {
412
551
  const t = task.list[tid];
552
+ (_2 = t.class) === null || _2 === void 0 ? void 0 : _2[eventName](taskId, formId);
413
553
  for (const fid in t.forms) {
414
- const r = (_0 = (_z = t.forms[fid].events)[name]) === null || _0 === void 0 ? void 0 : _0.call(_z, taskId, formId);
415
- if (r instanceof Promise) {
416
- r.catch(function (e) {
417
- console.log(e);
418
- });
419
- }
554
+ (_4 = (_3 = t.forms[fid].vroot)[eventName]) === null || _4 === void 0 ? void 0 : _4.call(_3, taskId, formId);
420
555
  }
421
556
  }
422
557
  break;
423
558
  }
424
559
  case 'taskStarted':
425
560
  case 'taskEnded': {
426
- (_2 = (_1 = exports.globalEvents)[name + 'Handler']) === null || _2 === void 0 ? void 0 : _2.call(_1, taskId, formId);
561
+ (_6 = (_5 = globalEvents)[name]) === null || _6 === void 0 ? void 0 : _6.call(_5, taskId, formId);
562
+ exports.boot[eventName](taskId, formId);
427
563
  for (const tid in task.list) {
428
564
  const t = task.list[tid];
565
+ (_7 = t.class) === null || _7 === void 0 ? void 0 : _7[eventName](taskId);
429
566
  for (const fid in t.forms) {
430
- const r = (_4 = (_3 = t.forms[fid].events)[name]) === null || _4 === void 0 ? void 0 : _4.call(_3, taskId);
431
- if (r instanceof Promise) {
432
- r.catch(function (e) {
433
- console.log(e);
434
- });
435
- }
567
+ (_9 = (_8 = t.forms[fid].vroot)[eventName]) === null || _9 === void 0 ? void 0 : _9.call(_8, taskId);
436
568
  }
437
569
  }
438
570
  break;
@@ -444,21 +576,12 @@ function trigger(name, taskId = 0, formId = 0, param1 = '', param2 = '') {
444
576
  if (typeof taskId === 'number') {
445
577
  taskId = taskId.toString();
446
578
  }
447
- const r = (_5 = exports.globalEvents.launcherFolderNameChangedHandler) === null || _5 === void 0 ? void 0 : _5.call(exports.globalEvents, taskId, formId);
448
- if (r && (r instanceof Promise)) {
449
- r.catch(function (e) {
450
- console.log(e);
451
- });
452
- }
579
+ exports.boot[eventName](taskId, formId);
453
580
  for (const tid in task.list) {
454
581
  const t = task.list[tid];
582
+ (_10 = t.class) === null || _10 === void 0 ? void 0 : _10[eventName](taskId, formId);
455
583
  for (const fid in t.forms) {
456
- const r = (_7 = (_6 = t.forms[fid].events)[name]) === null || _7 === void 0 ? void 0 : _7.call(_6, taskId, formId);
457
- if (r instanceof Promise) {
458
- r.catch(function (e) {
459
- console.log(e);
460
- });
461
- }
584
+ (_12 = (_11 = t.forms[fid].vroot)[eventName]) === null || _12 === void 0 ? void 0 : _12.call(_11, taskId, formId);
462
585
  }
463
586
  }
464
587
  break;
@@ -475,37 +598,30 @@ function readApp(blob) {
475
598
  return false;
476
599
  }
477
600
  const files = {};
478
- const configContent = yield z.getContent('/config.json');
479
- if (!configContent) {
480
- return false;
481
- }
482
- const config = JSON.parse(configContent);
483
- for (const file of config.files) {
484
- const mime = tool.getMimeByPath(file);
601
+ const list = z.readDir('/', {
602
+ 'hasChildren': true
603
+ });
604
+ for (const file of list) {
605
+ const mime = tool.getMimeByPath(file.name);
485
606
  if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
486
- const fab = yield z.getContent(file, 'string');
607
+ const fab = yield z.getContent(file.path + file.name, 'string');
487
608
  if (!fab) {
488
609
  continue;
489
610
  }
490
- files[file] = fab.replace(/^\ufeff/, '');
611
+ files[file.path + file.name] = fab.replace(/^\ufeff/, '');
491
612
  }
492
613
  else {
493
- const fab = yield z.getContent(file, 'arraybuffer');
614
+ const fab = yield z.getContent(file.path + file.name, 'arraybuffer');
494
615
  if (!fab) {
495
616
  continue;
496
617
  }
497
- files[file] = new Blob([fab], {
618
+ files[file.path + file.name] = new Blob([fab], {
498
619
  'type': mime.mime
499
620
  });
500
621
  }
501
622
  }
502
- if (!config) {
503
- return false;
504
- }
505
623
  return {
506
- 'type': 'app',
507
624
  'icon': icon,
508
- 'config': config,
509
625
  'files': files
510
626
  };
511
627
  });
@@ -523,18 +639,14 @@ function fetchApp(url, opt = {}) {
523
639
  }
524
640
  let current = '';
525
641
  if (opt.current) {
526
- if (!opt.current.endsWith('/')) {
527
- return null;
528
- }
529
- if (!url.startsWith('/')) {
530
- url = '/current/' + url;
531
- }
642
+ current = opt.current.endsWith('/') ? opt.current.slice(0, -1) : opt.current;
643
+ url = tool.urlResolve('/current/', url);
532
644
  }
533
645
  else {
534
646
  if (!url.startsWith('/clickgo/') && !url.startsWith('/storage/') && !url.startsWith('/mounted/')) {
535
647
  current = tool.urlResolve(window.location.href, url);
536
648
  if (cga) {
537
- current = current.slice(0, -cga.length);
649
+ current = current.slice(0, -cga.length - 1);
538
650
  url = '/current/' + cga;
539
651
  }
540
652
  else {
@@ -567,76 +679,49 @@ function fetchApp(url, opt = {}) {
567
679
  return null;
568
680
  }
569
681
  }
570
- let config;
571
- const files = {};
572
- try {
573
- const blob = yield fs.getContent(url + 'config.json', {
574
- 'current': current
575
- });
576
- if (blob === null || typeof blob === 'string') {
577
- return null;
578
- }
579
- config = JSON.parse(yield tool.blob2Text(blob));
580
- yield new Promise(function (resolve) {
581
- const total = config.files.length;
582
- let loaded = 0;
583
- for (const file of config.files) {
584
- fs.getContent(url + file.slice(1), {
585
- 'current': current
586
- }).then(function (blob) {
587
- var _a;
588
- return __awaiter(this, void 0, void 0, function* () {
589
- if (blob === null || typeof blob === 'string') {
590
- clickgo.form.notify({
591
- 'title': 'File not found',
592
- 'content': url + file.slice(1),
593
- 'type': 'danger'
594
- });
595
- return;
596
- }
597
- const mime = tool.getMimeByPath(file);
598
- if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
599
- files[file] = (yield tool.blob2Text(blob)).replace(/^\ufeff/, '');
600
- }
601
- else {
602
- files[file] = blob;
603
- }
604
- ++loaded;
605
- (_a = opt.progress) === null || _a === void 0 ? void 0 : _a.call(opt, loaded, total);
606
- if (opt.notifyId) {
607
- form.notifyProgress(opt.notifyId, loaded / total);
608
- }
609
- if (loaded < total) {
610
- return;
611
- }
612
- resolve();
613
- });
614
- }).catch(function () {
615
- var _a;
616
- ++loaded;
617
- (_a = opt.progress) === null || _a === void 0 ? void 0 : _a.call(opt, loaded, total);
618
- if (opt.notifyId) {
619
- form.notifyProgress(opt.notifyId, loaded / total);
620
- }
621
- if (loaded < total) {
622
- return;
623
- }
624
- resolve();
625
- });
682
+ let loaded = 0;
683
+ let total = 30;
684
+ const files = yield loader.sniffFiles(url + 'app.js', {
685
+ 'dir': '/',
686
+ adapter: (url) => __awaiter(this, void 0, void 0, function* () {
687
+ const r = yield fs.getContent(url, {
688
+ 'encoding': 'utf8',
689
+ 'current': current
690
+ });
691
+ return r;
692
+ }),
693
+ 'loaded': () => {
694
+ ++loaded;
695
+ if (loaded === total) {
696
+ ++total;
626
697
  }
627
- });
698
+ if (opt.notifyId) {
699
+ form.notifyProgress(opt.notifyId, (loaded / total) / 2);
700
+ }
701
+ if (opt.progress) {
702
+ opt.progress(loaded, total);
703
+ }
704
+ }
705
+ });
706
+ if (opt.notifyId) {
707
+ form.notifyProgress(opt.notifyId, 0.5);
628
708
  }
629
- catch (_b) {
709
+ if (Object.keys(files).length === 0) {
630
710
  return null;
631
711
  }
632
- let icon = '/clickgo/icon.png';
633
- if (config.icon && (files[config.icon] instanceof Blob)) {
634
- icon = yield tool.blob2DataUrl(files[config.icon]);
712
+ const ul = url.length - 1;
713
+ for (const fn in files) {
714
+ files[fn.slice(ul)] = files[fn];
715
+ delete files[fn];
635
716
  }
636
717
  return {
637
- 'type': 'app',
638
- 'icon': icon,
639
- 'config': config,
718
+ 'net': {
719
+ 'current': current,
720
+ 'notify': opt.notifyId,
721
+ 'url': url,
722
+ 'progress': opt.progress
723
+ },
724
+ 'icon': '',
640
725
  'files': files
641
726
  };
642
727
  });