clickgo-native 0.0.19 → 1.0.1

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/index.js CHANGED
@@ -1,73 +1,23 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.AbstractBoot = exports.tool = exports.fs = void 0;
46
- exports.launcher = launcher;
47
- exports.verifyToken = verifyToken;
48
- const electron = __importStar(require("electron"));
49
- const path = __importStar(require("path"));
50
- const libFs = __importStar(require("./lib/fs"));
51
- exports.fs = libFs;
52
- const libTool = __importStar(require("./lib/tool"));
53
- exports.tool = libTool;
54
- let isImmersion = false;
55
- let hasFrame = false;
1
+ import * as electron from 'electron';
2
+ import * as nodePath from 'path';
3
+ import * as lFs from './lib/fs.js';
4
+ import * as lTool from './lib/tool.js';
5
+ // npm publish --tag dev --access public
6
+ // --- sass --watch dist/:dist/ --style compressed --no-source-map ---
7
+ /** --- 窗体是否含有 border 边框,有的话将不是沉浸式,也不会绑定任何窗体的大小的相关事件 --- */
8
+ let hasFrame = true;
9
+ /** --- 是否没有物理窗体时就主动退出软件(进程结束),如果不要窗体只有 node 的话,会用到 false 的情况 --- */
56
10
  let isNoFormQuit = true;
11
+ /** --- 主窗体 --- */
57
12
  let form;
13
+ /** --- 当前设定的通讯 token --- */
58
14
  let token = '';
15
+ /** --- 当前系统平台 --- */
59
16
  const platform = process.platform;
17
+ // const platform: NodeJS.Platform = 'darwin';
18
+ /** --- 监听前台的执行的方法,内置的方法,用户可调用方法自行添加 --- */
60
19
  const methods = {
61
- 'cg-init': {
62
- 'once': true,
63
- handler: function (t) {
64
- if (!t || !form) {
65
- return;
66
- }
67
- form.resizable = true;
68
- token = t;
69
- }
70
- },
20
+ // --- 完全退出软件进程 ---
71
21
  'cg-quit': {
72
22
  'once': false,
73
23
  handler: function (t) {
@@ -80,10 +30,11 @@ const methods = {
80
30
  electron.app.quit();
81
31
  }
82
32
  },
33
+ // --- 设置实体窗体大小 ---
83
34
  'cg-set-size': {
84
35
  'once': false,
85
36
  handler: function (t, width, height) {
86
- if (isImmersion || !form || !width || !height) {
37
+ if (!form || !width || !height) {
87
38
  return;
88
39
  }
89
40
  if (!verifyToken(t)) {
@@ -93,6 +44,7 @@ const methods = {
93
44
  form.center();
94
45
  }
95
46
  },
47
+ // --- 设置窗体最大化、最小化、还原(从最大化还原) ---
96
48
  'cg-set-state': {
97
49
  'once': false,
98
50
  handler: function (t, state) {
@@ -111,12 +63,19 @@ const methods = {
111
63
  form.minimize();
112
64
  break;
113
65
  }
114
- default: {
66
+ case 'restore': {
67
+ // --- 最小化还原 ---
115
68
  form.restore();
69
+ break;
70
+ }
71
+ default: {
72
+ // --- 从最大化还原 ---
73
+ form.unmaximize();
116
74
  }
117
75
  }
118
76
  }
119
77
  },
78
+ // --- 激活窗体 ---
120
79
  'cg-activate': {
121
80
  'once': false,
122
81
  handler: function (t) {
@@ -135,6 +94,7 @@ const methods = {
135
94
  form.setAlwaysOnTop(false);
136
95
  },
137
96
  },
97
+ // --- 关闭窗体(可能软件进程不会被退出) ---
138
98
  'cg-close': {
139
99
  'once': false,
140
100
  handler: function (t) {
@@ -147,27 +107,11 @@ const methods = {
147
107
  form.close();
148
108
  }
149
109
  },
150
- 'cg-mouse-ignore': {
151
- 'once': false,
152
- handler: function (t, val) {
153
- if (!isImmersion || !form) {
154
- return;
155
- }
156
- if (!verifyToken(t)) {
157
- return;
158
- }
159
- if (val) {
160
- form.setIgnoreMouseEvents(true, { 'forward': true });
161
- }
162
- else {
163
- form.setIgnoreMouseEvents(false);
164
- }
165
- }
166
- },
110
+ // --- 是否允许最大化 ---
167
111
  'cg-maximizable': {
168
112
  'once': false,
169
113
  handler: function (t, val) {
170
- if (isImmersion || !form) {
114
+ if (!form) {
171
115
  return;
172
116
  }
173
117
  if (!verifyToken(t)) {
@@ -176,156 +120,132 @@ const methods = {
176
120
  form.setMaximizable(val);
177
121
  }
178
122
  },
123
+ // --- fs 相关操作 ---
179
124
  'cg-fs-getContent': {
180
125
  'once': false,
181
- handler: function (t, path, options) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- if (!verifyToken(t)) {
184
- return null;
185
- }
186
- return libFs.getContent(path, options);
187
- });
126
+ handler: async function (t, path, options) {
127
+ if (!verifyToken(t)) {
128
+ return null;
129
+ }
130
+ return lFs.getContent(path, options);
188
131
  }
189
132
  },
190
133
  'cg-fs-putContent': {
191
134
  'once': false,
192
- handler: function (t, path, data, options) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- if (!verifyToken(t)) {
195
- return false;
196
- }
197
- return exports.fs.putContent(path, data, options);
198
- });
135
+ handler: async function (t, path, data, options) {
136
+ if (!verifyToken(t)) {
137
+ return false;
138
+ }
139
+ return lFs.putContent(path, data, options);
199
140
  }
200
141
  },
201
142
  'cg-fs-readLink': {
202
143
  'once': false,
203
- handler: function (t, path, encoding) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- if (!verifyToken(t)) {
206
- return null;
207
- }
208
- return exports.fs.readLink(path, encoding);
209
- });
144
+ handler: async function (t, path, encoding) {
145
+ if (!verifyToken(t)) {
146
+ return null;
147
+ }
148
+ return lFs.readLink(path, encoding);
210
149
  }
211
150
  },
212
151
  'cg-fs-symlink': {
213
152
  'once': false,
214
- handler: function (t, filePath, linkPath, type) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- if (!verifyToken(t)) {
217
- return false;
218
- }
219
- return exports.fs.symlink(filePath, linkPath, type);
220
- });
153
+ handler: async function (t, filePath, linkPath, type) {
154
+ if (!verifyToken(t)) {
155
+ return false;
156
+ }
157
+ return lFs.symlink(filePath, linkPath, type);
221
158
  }
222
159
  },
223
160
  'cg-fs-unlink': {
224
161
  'once': false,
225
- handler: function (t, path) {
226
- return __awaiter(this, void 0, void 0, function* () {
227
- if (!verifyToken(t)) {
228
- return false;
229
- }
230
- return exports.fs.unlink(path);
231
- });
162
+ handler: async function (t, path) {
163
+ if (!verifyToken(t)) {
164
+ return false;
165
+ }
166
+ return lFs.unlink(path);
232
167
  }
233
168
  },
234
169
  'cg-fs-stats': {
235
170
  'once': false,
236
- handler: function (t, path) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- if (!verifyToken(t)) {
239
- return null;
240
- }
241
- return exports.fs.stats(path);
242
- });
171
+ handler: async function (t, path) {
172
+ if (!verifyToken(t)) {
173
+ return null;
174
+ }
175
+ return lFs.stats(path);
243
176
  }
244
177
  },
245
178
  'cg-fs-mkdir': {
246
179
  'once': false,
247
- handler: function (t, path, mode) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- if (!verifyToken(t)) {
250
- return false;
251
- }
252
- return exports.fs.mkdir(path, mode);
253
- });
180
+ handler: async function (t, path, mode) {
181
+ if (!verifyToken(t)) {
182
+ return false;
183
+ }
184
+ return lFs.mkdir(path, mode);
254
185
  }
255
186
  },
256
187
  'cg-fs-rmdir': {
257
188
  'once': false,
258
- handler: function (t, path) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- if (!verifyToken(t)) {
261
- return false;
262
- }
263
- return exports.fs.rmdir(path);
264
- });
189
+ handler: async function (t, path) {
190
+ if (!verifyToken(t)) {
191
+ return false;
192
+ }
193
+ return lFs.rmdir(path);
265
194
  }
266
195
  },
267
196
  'cg-fs-chmod': {
268
197
  'once': false,
269
- handler: function (t, path, mod) {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- if (!verifyToken(t)) {
272
- return false;
273
- }
274
- return exports.fs.chmod(path, mod);
275
- });
198
+ handler: async function (t, path, mod) {
199
+ if (!verifyToken(t)) {
200
+ return false;
201
+ }
202
+ return lFs.chmod(path, mod);
276
203
  }
277
204
  },
278
205
  'cg-fs-rename': {
279
206
  'once': false,
280
- handler: function (t, oldPath, newPath) {
281
- return __awaiter(this, void 0, void 0, function* () {
282
- if (!verifyToken(t)) {
283
- return false;
284
- }
285
- return exports.fs.rename(oldPath, newPath);
286
- });
207
+ handler: async function (t, oldPath, newPath) {
208
+ if (!verifyToken(t)) {
209
+ return false;
210
+ }
211
+ return lFs.rename(oldPath, newPath);
287
212
  }
288
213
  },
289
214
  'cg-fs-readDir': {
290
215
  'once': false,
291
- handler: function (t, path, encoding) {
292
- return __awaiter(this, void 0, void 0, function* () {
293
- if (!verifyToken(t)) {
294
- return [];
295
- }
296
- return exports.fs.readDir(path, encoding);
297
- });
216
+ handler: async function (t, path, encoding) {
217
+ if (!verifyToken(t)) {
218
+ return [];
219
+ }
220
+ return lFs.readDir(path, encoding);
298
221
  }
299
222
  },
300
223
  'cg-fs-copyFile': {
301
224
  'once': false,
302
- handler: function (t, src, dest) {
303
- return __awaiter(this, void 0, void 0, function* () {
304
- if (!verifyToken(t)) {
305
- return false;
306
- }
307
- return exports.fs.copyFile(src, dest);
308
- });
225
+ handler: async function (t, src, dest) {
226
+ if (!verifyToken(t)) {
227
+ return false;
228
+ }
229
+ return lFs.copyFile(src, dest);
309
230
  }
310
231
  },
232
+ // --- form ---
311
233
  'cg-form-open': {
312
234
  'once': false,
313
235
  handler: function (t, options = {}) {
314
- var _a, _b, _c, _d, _e;
315
- var _f, _g, _h;
316
236
  if (!t || !form) {
317
237
  return null;
318
238
  }
319
239
  if (!verifyToken(t)) {
320
240
  return null;
321
241
  }
322
- (_a = options.filters) !== null && _a !== void 0 ? _a : (options.filters = []);
323
- (_b = options.props) !== null && _b !== void 0 ? _b : (options.props = {});
324
- (_c = (_f = options.props).file) !== null && _c !== void 0 ? _c : (_f.file = true);
325
- (_d = (_g = options.props).directory) !== null && _d !== void 0 ? _d : (_g.directory = false);
326
- (_e = (_h = options.props).multi) !== null && _e !== void 0 ? _e : (_h.multi = false);
242
+ options.filters ??= [];
243
+ options.props ??= {};
244
+ options.props.file ??= true;
245
+ options.props.directory ??= false;
246
+ options.props.multi ??= false;
327
247
  const paths = electron.dialog.showOpenDialogSync(form, {
328
- 'defaultPath': options.path ? exports.tool.formatPath(options.path) : undefined,
248
+ 'defaultPath': options.path ? lTool.formatPath(options.path) : undefined,
329
249
  'filters': options.filters.map((item) => {
330
250
  return {
331
251
  'name': item.name,
@@ -341,22 +261,21 @@ const methods = {
341
261
  if (!paths) {
342
262
  return null;
343
263
  }
344
- return paths.map(item => exports.tool.parsePath(item));
264
+ return paths.map(item => lTool.parsePath(item));
345
265
  }
346
266
  },
347
267
  'cg-form-save': {
348
268
  'once': false,
349
269
  handler: function (t, options = {}) {
350
- var _a;
351
270
  if (!t || !form) {
352
271
  return null;
353
272
  }
354
273
  if (!verifyToken(t)) {
355
274
  return null;
356
275
  }
357
- (_a = options.filters) !== null && _a !== void 0 ? _a : (options.filters = []);
276
+ options.filters ??= [];
358
277
  const path = electron.dialog.showSaveDialogSync(form, {
359
- 'defaultPath': options.path ? exports.tool.formatPath(options.path) : undefined,
278
+ 'defaultPath': options.path ? lTool.formatPath(options.path) : undefined,
360
279
  'filters': options.filters.map((item) => {
361
280
  return {
362
281
  'name': item.name,
@@ -367,13 +286,12 @@ const methods = {
367
286
  if (!path) {
368
287
  return null;
369
288
  }
370
- return exports.tool.parsePath(path);
289
+ return lTool.parsePath(path);
371
290
  }
372
291
  },
373
292
  'cg-form-dialog': {
374
293
  'once': false,
375
294
  handler: function (t, options = {}) {
376
- var _a, _b;
377
295
  if (!t || !form) {
378
296
  return -1;
379
297
  }
@@ -385,8 +303,8 @@ const methods = {
385
303
  'message': options
386
304
  };
387
305
  }
388
- (_a = options.title) !== null && _a !== void 0 ? _a : (options.title = 'ClickGo');
389
- (_b = options.message) !== null && _b !== void 0 ? _b : (options.message = '');
306
+ options.title ??= 'ClickGo';
307
+ options.message ??= '';
390
308
  return electron.dialog.showMessageBoxSync(form, {
391
309
  'type': options.type,
392
310
  'title': options.title,
@@ -396,93 +314,130 @@ const methods = {
396
314
  });
397
315
  }
398
316
  },
317
+ // --- 无需校验码 ---
318
+ // --- 测试与 native 的连通性 ---
399
319
  'cg-ping': {
400
320
  'once': false,
401
321
  handler: function (t) {
322
+ // --- t 不是 token,传过来什么就会传回去 ---
402
323
  return 'pong: ' + t;
403
324
  }
404
325
  },
326
+ // --- 判断窗体是否是最大化状态 ---
405
327
  'cg-is-max': {
406
328
  'once': false,
407
329
  handler: function () {
408
- return (form === null || form === void 0 ? void 0 : form.isMaximized) ? true : false;
330
+ return form?.isMaximized() ? true : false;
409
331
  }
410
- }
332
+ },
411
333
  };
412
- class AbstractBoot {
413
- get isImmersion() {
414
- return isImmersion;
415
- }
334
+ /** --- 全局类 --- */
335
+ export class AbstractBoot {
336
+ /**
337
+ * --- 是否含有实体窗体边框和标题 ---
338
+ */
416
339
  get hasFrame() {
417
340
  return hasFrame;
418
341
  }
342
+ /**
343
+ * --- 没有实体窗体时整个实体进程是不是会被结束 ---
344
+ */
419
345
  get isNoFormQuit() {
420
346
  return isNoFormQuit;
421
347
  }
348
+ /**
349
+ * --- 当前系统代号 ---
350
+ */
422
351
  get platform() {
423
352
  return platform;
424
353
  }
354
+ /**
355
+ * --- 当前的通讯 token ---
356
+ */
425
357
  get token() {
426
358
  return token;
427
359
  }
360
+ /**
361
+ * --- 开始运行起来一个主实体窗体,整个进程本方法只能执行一次 ---
362
+ * @param path 实体窗体网页路径
363
+ * @param opt 参数
364
+ */
428
365
  run(path, opt = {}) {
429
366
  if (opt.frame !== undefined) {
367
+ // --- 默认 true ---
430
368
  hasFrame = opt.frame;
431
369
  }
432
370
  if (opt.quit !== undefined) {
371
+ // --- 默认 true ---
433
372
  isNoFormQuit = opt.quit;
434
373
  }
435
- if (platform === 'win32') {
436
- if (!hasFrame) {
437
- isImmersion = true;
438
- }
439
- }
440
- createForm(path);
441
- if (form && opt.dev) {
442
- form.webContents.openDevTools();
443
- }
374
+ // --- 创建实体窗体 ---
375
+ showMainForm(path, {
376
+ 'dev': opt.dev,
377
+ 'width': opt.width,
378
+ 'height': opt.height,
379
+ 'max': opt.max,
380
+ 'stateMax': opt.stateMax,
381
+ 'background': opt.background,
382
+ });
383
+ // --- 监听所有实体窗体关闭事件 ---
444
384
  electron.app.on('window-all-closed', function () {
445
385
  if (isNoFormQuit) {
446
386
  electron.app.quit();
387
+ return;
447
388
  }
389
+ form = undefined;
448
390
  });
391
+ // --- 软件被活动性激活的事件 ---
449
392
  electron.app.on('activate', function () {
450
393
  if (electron.BrowserWindow.getAllWindows().length > 0) {
451
394
  return;
452
395
  }
453
- createForm(path);
454
- if (form && opt.dev) {
455
- form.webContents.openDevTools();
456
- }
457
- methods['cg-init'] = {
458
- 'once': true,
459
- handler: function (t) {
460
- if (!t || !form) {
461
- return;
462
- }
463
- form.resizable = true;
464
- token = t;
465
- }
466
- };
396
+ showMainForm(path, {
397
+ 'dev': opt.dev,
398
+ 'width': opt.width,
399
+ 'height': opt.height,
400
+ 'max': opt.max,
401
+ 'stateMax': opt.stateMax,
402
+ 'background': opt.background,
403
+ });
467
404
  });
468
405
  }
406
+ /**
407
+ * --- 绑定监听网页调用方法的方法 ---
408
+ * @param name 方法名
409
+ * @param handler 要执行的函数
410
+ * @param once 是否只执行一次
411
+ */
469
412
  on(name, handler, once = false) {
470
413
  methods[name] = {
471
414
  'once': once,
472
415
  'handler': handler
473
416
  };
474
417
  }
418
+ /**
419
+ * --- 绑定监听网页调用方法的方法但只会执行一次 ---
420
+ * @param name 方法名
421
+ * @param handler 要执行的函数
422
+ */
475
423
  once(name, handler) {
476
424
  this.on(name, handler, true);
477
425
  }
426
+ /**
427
+ * --- 解绑监听的方法 ---
428
+ * @param name 方法名
429
+ */
478
430
  off(name) {
479
431
  if (!methods[name]) {
480
432
  return;
481
433
  }
482
434
  delete methods[name];
483
435
  }
436
+ /**
437
+ * --- 显示一个 dialog ---
438
+ * @param opt 选项或者一段文字
439
+ */
484
440
  dialog(options = {}) {
485
- var _a, _b;
486
441
  if (!form) {
487
442
  return -1;
488
443
  }
@@ -491,8 +446,8 @@ class AbstractBoot {
491
446
  'message': options
492
447
  };
493
448
  }
494
- (_a = options.title) !== null && _a !== void 0 ? _a : (options.title = 'ClickGo');
495
- (_b = options.message) !== null && _b !== void 0 ? _b : (options.message = '');
449
+ options.title ??= 'ClickGo';
450
+ options.message ??= '';
496
451
  return electron.dialog.showMessageBoxSync(form, {
497
452
  'type': options.type,
498
453
  'title': options.title,
@@ -502,19 +457,61 @@ class AbstractBoot {
502
457
  });
503
458
  }
504
459
  }
505
- exports.AbstractBoot = AbstractBoot;
506
- function launcher(boot) {
507
- (function () {
508
- return __awaiter(this, void 0, void 0, function* () {
509
- yield electron.app.whenReady();
510
- yield exports.fs.refreshDrives();
511
- yield boot.main();
512
- });
460
+ /**
461
+ * --- 加载本地路径需要使用本函数加载 ---
462
+ * @param importUrl 传入 import.meta.url
463
+ * @param p 要加载的相对路径,如 ./index.html
464
+ */
465
+ export function path(importUrl, p) {
466
+ let url = importUrl.replace('file:///', '');
467
+ const lio = url.lastIndexOf('/');
468
+ url = url.slice(0, lio + 1);
469
+ return nodePath.join(url, p);
470
+ }
471
+ export function showMainForm(path, opt = {}) {
472
+ if (form) {
473
+ // --- 有主窗体了就不能创建了 ---
474
+ return;
475
+ }
476
+ // --- 成功运行一个 task 后再次添加 init ---
477
+ methods['cg-init'] = {
478
+ 'once': true,
479
+ handler: function (t) {
480
+ // --- t 是网页传来的 token ---
481
+ if (!t || !form) {
482
+ return;
483
+ }
484
+ form.resizable = true;
485
+ token = t;
486
+ },
487
+ };
488
+ const frm = createForm(path, {
489
+ 'width': opt.width,
490
+ 'height': opt.height,
491
+ 'max': opt.max,
492
+ 'stateMax': opt.stateMax,
493
+ 'background': opt.background,
494
+ });
495
+ if (opt.dev) {
496
+ // --- 开发模式 ---
497
+ frm.webContents.openDevTools();
498
+ }
499
+ }
500
+ /** --- 用户调用运行 boot 类 --- */
501
+ export function launcher(boot) {
502
+ (async function () {
503
+ // --- 等到 native 环境装载完毕 ---
504
+ await electron.app.whenReady();
505
+ await lFs.refreshDrives();
506
+ // --- 执行回调 ---
507
+ await boot.main();
513
508
  })().catch(function () {
514
509
  return;
515
510
  });
516
511
  }
512
+ // --- 系统启动 ---
517
513
  electron.Menu.setApplicationMenu(null);
514
+ // --- 实际用来监听网页传输过来的数据 ---
518
515
  electron.ipcMain.handle('pre', function (e, name, ...param) {
519
516
  if (!methods[name]) {
520
517
  return;
@@ -525,47 +522,60 @@ electron.ipcMain.handle('pre', function (e, name, ...param) {
525
522
  }
526
523
  return r;
527
524
  });
528
- function verifyToken(t) {
525
+ /**
526
+ * --- 验证 token 是否正确 ---
527
+ * @param t 要验证的 token
528
+ */
529
+ export function verifyToken(t) {
529
530
  if (t !== token) {
530
531
  return false;
531
532
  }
532
533
  return true;
533
534
  }
534
- function createForm(p) {
535
+ /**
536
+ * --- 内部调用用来创建实体窗体的函数 ---
537
+ * @param p 窗体网页路径
538
+ */
539
+ function createForm(p, opt = {}) {
540
+ let pre = new URL('./pre.js', import.meta.url).pathname.replace(/^\/(\w:)/, '$1');
535
541
  const op = {
536
542
  'webPreferences': {
537
543
  'nodeIntegration': false,
538
544
  'contextIsolation': true,
539
- 'preload': path.join(__dirname, '/pre.js'),
545
+ 'preload': pre,
540
546
  },
541
- 'width': hasFrame ? 800 : 500,
542
- 'height': hasFrame ? 700 : 300,
547
+ 'width': opt.width ?? (hasFrame ? 800 : 600),
548
+ 'height': opt.height ?? (hasFrame ? 700 : 350),
543
549
  'frame': hasFrame,
544
550
  'resizable': false,
545
551
  'show': false,
546
552
  'center': true,
547
- 'transparent': isImmersion ? true : false,
553
+ 'maximizable': opt.max ?? true,
554
+ 'backgroundColor': opt.background ?? 'rgba(0, 0, 0, 1)',
555
+ 'transparent': opt.transparent,
548
556
  };
549
557
  form = new electron.BrowserWindow(op);
550
- form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0') + ' chrome/' + process.versions.chrome;
558
+ form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' frame/' + (hasFrame ? '1' : '0') + ' chrome/' + process.versions.chrome;
551
559
  form.once('ready-to-show', function () {
552
560
  if (!form) {
553
561
  return;
554
562
  }
555
- if (isImmersion) {
556
- form.maximize();
557
- form.setIgnoreMouseEvents(true, { 'forward': true });
558
- }
559
- else {
563
+ if (opt.background) {
564
+ form.setBackgroundColor(opt.transparent ? 'rgba(0, 0, 0, 0)' : 'rgba(0, 0, 0, 1)');
560
565
  }
561
566
  form.show();
567
+ if (opt.stateMax) {
568
+ form.maximize();
569
+ }
562
570
  });
563
571
  if (p.startsWith('https://') || p.startsWith('http://')) {
572
+ // --- 加载网页 ---
564
573
  form.loadURL(p).catch(function (e) {
565
574
  throw e;
566
575
  });
567
576
  }
568
577
  else {
578
+ // --- 加载本地文件 ---
569
579
  const lio = p.indexOf('?');
570
580
  const search = lio === -1 ? '' : p.slice(lio + 1);
571
581
  if (lio !== -1) {
@@ -580,10 +590,13 @@ function createForm(p) {
580
590
  form.on('close', function () {
581
591
  form = undefined;
582
592
  });
593
+ // --- 最大化事件 ---
583
594
  form.on('maximize', function () {
584
- form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}');
595
+ form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}');
585
596
  });
597
+ // --- 最大化还原 ---
586
598
  form.on('unmaximize', function () {
587
- form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}');
599
+ form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}');
588
600
  });
601
+ return form;
589
602
  }