clickgo-native 0.0.18 → 1.0.0

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