clickgo-native 0.0.2-dev2 → 0.0.4-dev4

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  [![npm version](https://img.shields.io/npm/v/clickgo-native.svg?colorB=brightgreen)](https://www.npmjs.com/package/clickgo-native "Stable Version")
6
6
  [![npm version](https://img.shields.io/npm/v/clickgo-native/dev.svg)](https://www.npmjs.com/package/clickgo-native "Development Version")
7
7
  [![npm version](https://img.shields.io/npm/v/clickgo-native/beta.svg)](https://www.npmjs.com/package/clickgo-native "Beta Version")
8
- [![License](https://img.shields.io/github/license/maiyun/clickGo-native.svg)](https://github.com/maiyun/clickgo-native/blob/master/LICENSE)
8
+ [![License](https://img.shields.io/github/license/maiyun/clickgo-native.svg)](https://github.com/maiyun/clickgo-native/blob/master/LICENSE)
9
9
  [![GitHub issues](https://img.shields.io/github/issues/maiyun/clickgo-native.svg)](https://github.com/maiyun/clickgo-native/issues)
10
10
  [![GitHub Releases](https://img.shields.io/github/release/maiyun/clickgo-native.svg)](https://github.com/maiyun/clickgo-native/releases "Stable Release")
11
11
  [![GitHub Pre-Releases](https://img.shields.io/github/release/maiyun/clickgo-native/all.svg)](https://github.com/maiyun/clickgo-native/releases "Pre-Release")
@@ -17,46 +17,27 @@ The software developed with ClickGo will run in Windows, Mac OS, Linux.
17
17
  You can install directly using NPM:
18
18
 
19
19
  ```sh
20
- $ npm i clickgo --save
20
+ $ npm i clickgo-native --save
21
21
  ```
22
22
 
23
23
  Or install the developing (unstable) version for newest features:
24
24
 
25
25
  ```sh
26
- $ npm i clickgo@dev --save
27
- ```
28
-
29
- **index.html**
30
-
31
- ```html
32
- <script src="https://cdn.jsdelivr.net/npm/@litert/loader@3.2.0/dist/loader.min.js?path=index"></script>
33
- ```
34
-
35
- **index.js**
36
-
37
- ```typescript
38
- import * as clickgo from 'clickgo';
39
- async function run(): Promise<void> {
40
- await clickgo.init();
41
- await clickgo.task.run('app/');
42
- }
26
+ $ npm i clickgo-native@dev --save
43
27
  ```
44
28
 
45
29
  **Node**
46
30
 
47
31
  ```typescript
48
32
  import * as native from 'clickgo-native';
49
- native.ready().then(function() {
50
- native.run('./index.html');
51
- }).catch(function(e) {
52
- console.log(e);
53
- });
33
+ class Boot extends native.AbstractBoot {
34
+ public main(): void {
35
+ this.run('./index.html');
36
+ }
37
+ }
38
+ native.launcher(new Boot());
54
39
  ```
55
40
 
56
- ## Note
57
-
58
- ClickGo demand loading Vue, jszip, resize-observer, but **DO NOT** reference these JS and CSS files. ClickGo will automatically reference. You only need to import "clickgo" module.
59
-
60
41
  ## Demo
61
42
 
62
43
  Clone and `npm run native`.
package/dist/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,31 +32,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
32
  });
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.run = exports.ready = exports.verifyToken = exports.unbind = exports.once = exports.bind = void 0;
13
- const electron = require("electron");
14
- const path = require("path");
15
- electron.Menu.setApplicationMenu(null);
16
- let isReady = false;
17
- let isFrame = false;
18
- let isQuit = true;
19
- let win;
20
- const platform = process.platform;
35
+ exports.verifyToken = exports.launcher = exports.AbstractBoot = exports.tool = exports.fs = void 0;
36
+ const electron = __importStar(require("electron"));
37
+ const path = __importStar(require("path"));
38
+ const libFs = __importStar(require("./lib/fs"));
39
+ exports.fs = libFs;
40
+ const libTool = __importStar(require("./lib/tool"));
41
+ exports.tool = libTool;
42
+ let isImmersion = false;
43
+ let hasFrame = false;
44
+ let isNoFormQuit = true;
45
+ let form;
21
46
  let token = '';
47
+ const platform = process.platform;
22
48
  const methods = {
23
49
  'cg-init': {
24
50
  'once': true,
25
51
  handler: function (t) {
26
- if (!t || !win) {
52
+ if (!t || !form) {
27
53
  return;
28
54
  }
29
- win.resizable = true;
55
+ form.resizable = true;
30
56
  token = t;
31
57
  }
32
58
  },
33
59
  'cg-quit': {
34
60
  'once': false,
35
61
  handler: function (t) {
36
- if (!win || !t) {
62
+ if (!t || !form) {
37
63
  return;
38
64
  }
39
65
  if (!verifyToken(t)) {
@@ -45,20 +71,20 @@ const methods = {
45
71
  'cg-set-size': {
46
72
  'once': false,
47
73
  handler: function (t, width, height) {
48
- if (!win || !width || !height) {
74
+ if (isImmersion || !form || !width || !height) {
49
75
  return;
50
76
  }
51
77
  if (!verifyToken(t)) {
52
78
  return;
53
79
  }
54
- win.setSize(width, height);
55
- win.center();
80
+ form.setSize(width, height);
81
+ form.center();
56
82
  }
57
83
  },
58
84
  'cg-set-state': {
59
85
  'once': false,
60
86
  handler: function (t, state) {
61
- if (!win || !state) {
87
+ if (!hasFrame || !form || !state) {
62
88
  return;
63
89
  }
64
90
  if (!verifyToken(t)) {
@@ -66,67 +92,304 @@ const methods = {
66
92
  }
67
93
  switch (state) {
68
94
  case 'max': {
69
- win.maximize();
95
+ form.maximize();
70
96
  break;
71
97
  }
72
98
  case 'min': {
73
- win.minimize();
99
+ form.minimize();
74
100
  break;
75
101
  }
76
102
  default: {
77
- win.restore();
103
+ form.restore();
78
104
  }
79
105
  }
80
106
  }
81
107
  },
108
+ 'cg-activate': {
109
+ 'once': false,
110
+ handler: function (t) {
111
+ if (!form) {
112
+ return;
113
+ }
114
+ if (!verifyToken(t)) {
115
+ return;
116
+ }
117
+ if (form.isMinimized()) {
118
+ form.restore();
119
+ }
120
+ form.setAlwaysOnTop(true);
121
+ form.show();
122
+ form.focus();
123
+ form.setAlwaysOnTop(false);
124
+ },
125
+ },
82
126
  'cg-close': {
83
127
  'once': false,
84
128
  handler: function (t) {
85
- if (!win) {
129
+ if (!form) {
86
130
  return;
87
131
  }
88
132
  if (!verifyToken(t)) {
89
133
  return;
90
134
  }
91
- win.close();
135
+ form.close();
92
136
  }
93
137
  },
94
138
  'cg-mouse-ignore': {
95
139
  'once': false,
96
140
  handler: function (t, val) {
97
- if (!win) {
141
+ if (!isImmersion || !form) {
98
142
  return;
99
143
  }
100
144
  if (!verifyToken(t)) {
101
145
  return;
102
146
  }
103
147
  if (val) {
104
- win.setIgnoreMouseEvents(true, { 'forward': true });
148
+ form.setIgnoreMouseEvents(true, { 'forward': true });
105
149
  }
106
150
  else {
107
- win.setIgnoreMouseEvents(false);
151
+ form.setIgnoreMouseEvents(false);
108
152
  }
109
153
  }
154
+ },
155
+ 'cg-maximizable': {
156
+ 'once': false,
157
+ handler: function (t, val) {
158
+ if (isImmersion || !form) {
159
+ return;
160
+ }
161
+ if (!verifyToken(t)) {
162
+ return;
163
+ }
164
+ form.setMaximizable(val);
165
+ }
166
+ },
167
+ 'cg-fs-getContent': {
168
+ 'once': false,
169
+ handler: function (t, path, options) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ if (!verifyToken(t)) {
172
+ return null;
173
+ }
174
+ return libFs.getContent(path, options);
175
+ });
176
+ }
177
+ },
178
+ 'cg-fs-putContent': {
179
+ 'once': false,
180
+ handler: function (t, path, data, options) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ if (!verifyToken(t)) {
183
+ return false;
184
+ }
185
+ return exports.fs.putContent(path, data, options);
186
+ });
187
+ }
188
+ },
189
+ 'cg-fs-readLink': {
190
+ 'once': false,
191
+ handler: function (t, path, encoding) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ if (!verifyToken(t)) {
194
+ return null;
195
+ }
196
+ return exports.fs.readLink(path, encoding);
197
+ });
198
+ }
199
+ },
200
+ 'cg-fs-symlink': {
201
+ 'once': false,
202
+ handler: function (t, filePath, linkPath, type) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ if (!verifyToken(t)) {
205
+ return false;
206
+ }
207
+ return exports.fs.symlink(filePath, linkPath, type);
208
+ });
209
+ }
210
+ },
211
+ 'cg-fs-unlink': {
212
+ 'once': false,
213
+ handler: function (t, path) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ if (!verifyToken(t)) {
216
+ return false;
217
+ }
218
+ return exports.fs.unlink(path);
219
+ });
220
+ }
221
+ },
222
+ 'cg-fs-stats': {
223
+ 'once': false,
224
+ handler: function (t, path) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ if (!verifyToken(t)) {
227
+ return null;
228
+ }
229
+ return exports.fs.stats(path);
230
+ });
231
+ }
232
+ },
233
+ 'cg-fs-mkdir': {
234
+ 'once': false,
235
+ handler: function (t, path, mode) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ if (!verifyToken(t)) {
238
+ return false;
239
+ }
240
+ return exports.fs.mkdir(path, mode);
241
+ });
242
+ }
243
+ },
244
+ 'cg-fs-rmdir': {
245
+ 'once': false,
246
+ handler: function (t, path) {
247
+ return __awaiter(this, void 0, void 0, function* () {
248
+ if (!verifyToken(t)) {
249
+ return false;
250
+ }
251
+ return exports.fs.rmdir(path);
252
+ });
253
+ }
254
+ },
255
+ 'cg-fs-chmod': {
256
+ 'once': false,
257
+ handler: function (t, path, mod) {
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ if (!verifyToken(t)) {
260
+ return false;
261
+ }
262
+ return exports.fs.chmod(path, mod);
263
+ });
264
+ }
265
+ },
266
+ 'cg-fs-rename': {
267
+ 'once': false,
268
+ handler: function (t, oldPath, newPath) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ if (!verifyToken(t)) {
271
+ return false;
272
+ }
273
+ return exports.fs.rename(oldPath, newPath);
274
+ });
275
+ }
276
+ },
277
+ 'cg-fs-readDir': {
278
+ 'once': false,
279
+ handler: function (t, path, encoding) {
280
+ return __awaiter(this, void 0, void 0, function* () {
281
+ if (!verifyToken(t)) {
282
+ return [];
283
+ }
284
+ return exports.fs.readDir(path, encoding);
285
+ });
286
+ }
287
+ },
288
+ 'cg-fs-copyFile': {
289
+ 'once': false,
290
+ handler: function (t, src, dest) {
291
+ return __awaiter(this, void 0, void 0, function* () {
292
+ if (!verifyToken(t)) {
293
+ return false;
294
+ }
295
+ return exports.fs.copyFile(src, dest);
296
+ });
297
+ }
298
+ },
299
+ 'cg-ping': {
300
+ 'once': false,
301
+ handler: function (t) {
302
+ return 'pong: ' + t;
303
+ }
304
+ },
305
+ 'cg-is-max': {
306
+ 'once': false,
307
+ handler: function () {
308
+ return (form === null || form === void 0 ? void 0 : form.isMaximized) ? true : false;
309
+ }
110
310
  }
111
311
  };
112
- function bind(name, handler, once = false) {
113
- methods[name] = {
114
- 'once': once,
115
- 'handler': handler
116
- };
117
- }
118
- exports.bind = bind;
119
- function once(name, handler) {
120
- bind(name, handler, true);
312
+ class AbstractBoot {
313
+ get isImmersion() {
314
+ return isImmersion;
315
+ }
316
+ get hasFrame() {
317
+ return hasFrame;
318
+ }
319
+ get isNoFormQuit() {
320
+ return isNoFormQuit;
321
+ }
322
+ get platform() {
323
+ return platform;
324
+ }
325
+ get token() {
326
+ return token;
327
+ }
328
+ run(path, opt = {}) {
329
+ if (opt.frame !== undefined) {
330
+ hasFrame = opt.frame;
331
+ }
332
+ if (opt.quit !== undefined) {
333
+ isNoFormQuit = opt.quit;
334
+ }
335
+ if (platform === 'win32') {
336
+ if (!hasFrame) {
337
+ isImmersion = true;
338
+ }
339
+ }
340
+ createForm(path);
341
+ electron.app.on('window-all-closed', function () {
342
+ if (isNoFormQuit) {
343
+ electron.app.quit();
344
+ }
345
+ });
346
+ electron.app.on('activate', function () {
347
+ if (electron.BrowserWindow.getAllWindows().length > 0) {
348
+ return;
349
+ }
350
+ createForm(path);
351
+ methods['cg-init'] = {
352
+ 'once': true,
353
+ handler: function (t) {
354
+ if (!t || !form) {
355
+ return;
356
+ }
357
+ form.resizable = true;
358
+ token = t;
359
+ }
360
+ };
361
+ });
362
+ }
363
+ on(name, handler, once = false) {
364
+ methods[name] = {
365
+ 'once': once,
366
+ 'handler': handler
367
+ };
368
+ }
369
+ once(name, handler) {
370
+ this.on(name, handler, true);
371
+ }
372
+ off(name) {
373
+ if (!methods[name]) {
374
+ return;
375
+ }
376
+ delete methods[name];
377
+ }
121
378
  }
122
- exports.once = once;
123
- function unbind(name) {
124
- if (!methods[name]) {
379
+ exports.AbstractBoot = AbstractBoot;
380
+ function launcher(boot) {
381
+ (function () {
382
+ return __awaiter(this, void 0, void 0, function* () {
383
+ yield electron.app.whenReady();
384
+ yield exports.fs.refreshDrives();
385
+ yield boot.main();
386
+ });
387
+ })().catch(function () {
125
388
  return;
126
- }
127
- delete methods[name];
389
+ });
128
390
  }
129
- exports.unbind = unbind;
391
+ exports.launcher = launcher;
392
+ electron.Menu.setApplicationMenu(null);
130
393
  electron.ipcMain.handle('pre', function (e, name, ...param) {
131
394
  if (!methods[name]) {
132
395
  return;
@@ -144,13 +407,6 @@ function verifyToken(t) {
144
407
  return true;
145
408
  }
146
409
  exports.verifyToken = verifyToken;
147
- function ready() {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- yield electron.app.whenReady();
150
- isReady = true;
151
- });
152
- }
153
- exports.ready = ready;
154
410
  function createForm(p) {
155
411
  const op = {
156
412
  'webPreferences': {
@@ -158,73 +414,45 @@ function createForm(p) {
158
414
  'contextIsolation': true,
159
415
  'preload': path.join(__dirname, '/pre.js')
160
416
  },
161
- 'width': 500,
162
- 'height': 400,
163
- 'frame': isFrame,
417
+ 'width': hasFrame ? 800 : 500,
418
+ 'height': hasFrame ? 700 : 300,
419
+ 'frame': hasFrame,
164
420
  'resizable': false,
165
421
  'show': false,
166
422
  'center': true,
167
- 'transparent': isFrame ? undefined : true
423
+ 'transparent': isImmersion ? true : false
168
424
  };
169
- win = new electron.BrowserWindow(op);
170
- win.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch;
171
- win.once('ready-to-show', function () {
172
- if (!win) {
425
+ form = new electron.BrowserWindow(op);
426
+ form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0');
427
+ form.once('ready-to-show', function () {
428
+ if (!form) {
173
429
  return;
174
430
  }
175
- if (platform === 'win32') {
176
- win.maximize();
177
- win.setIgnoreMouseEvents(true, { 'forward': true });
431
+ if (isImmersion) {
432
+ form.maximize();
433
+ form.setIgnoreMouseEvents(true, { 'forward': true });
178
434
  }
179
435
  else {
180
436
  }
181
- win.show();
437
+ form.show();
182
438
  });
183
439
  const lio = p.indexOf('?');
184
440
  const search = lio === -1 ? '' : p.slice(lio + 1);
185
441
  if (lio !== -1) {
186
442
  p = p.slice(0, lio);
187
443
  }
188
- win.loadFile(p, {
444
+ form.loadFile(p, {
189
445
  'search': search
190
446
  }).catch(function (e) {
191
447
  throw e;
192
448
  });
193
- win.on('close', function () {
194
- win = undefined;
449
+ form.on('close', function () {
450
+ form = undefined;
195
451
  });
196
- }
197
- function run(path, opt = {}) {
198
- if (!isReady) {
199
- return;
200
- }
201
- if (opt.frame !== undefined) {
202
- isFrame = opt.frame;
203
- }
204
- if (opt.quit !== undefined) {
205
- isQuit = opt.quit;
206
- }
207
- createForm(path);
208
- electron.app.on('window-all-closed', function () {
209
- if (isQuit) {
210
- electron.app.quit();
211
- }
452
+ form.on('maximize', function () {
453
+ form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}');
212
454
  });
213
- electron.app.on('activate', function () {
214
- if (electron.BrowserWindow.getAllWindows().length > 0) {
215
- return;
216
- }
217
- createForm(path);
218
- methods['cg-init'] = {
219
- 'once': true,
220
- handler: function (t) {
221
- if (!t || !win) {
222
- return;
223
- }
224
- win.resizable = true;
225
- token = t;
226
- }
227
- };
455
+ form.on('unmaximize', function () {
456
+ form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}');
228
457
  });
229
458
  }
230
- exports.run = run;