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 +9 -28
- package/dist/index.js +321 -93
- package/dist/index.ts +379 -126
- package/dist/lib/fs.js +324 -0
- package/dist/lib/fs.ts +284 -0
- package/dist/lib/tool.js +11 -0
- package/dist/lib/tool.ts +11 -0
- package/dist/pre.js +24 -1
- package/dist/pre.ts +1 -1
- package/package.json +8 -9
package/dist/index.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
// npm publish --tag dev --access public
|
|
2
|
-
// --- sass --watch dist/:dist/ --style compressed --no-source-map ---
|
|
3
1
|
import * as electron from 'electron';
|
|
4
2
|
import * as path from 'path';
|
|
3
|
+
import * as libFs from './lib/fs';
|
|
4
|
+
export const fs = libFs;
|
|
5
|
+
import * as libTool from './lib/tool';
|
|
6
|
+
export const tool = libTool;
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
// npm publish --tag dev --access public
|
|
9
|
+
// --- sass --watch dist/:dist/ --style compressed --no-source-map ---
|
|
10
|
+
|
|
11
|
+
/** --- 是否是沉浸式的 --- */
|
|
12
|
+
let isImmersion: boolean = false;
|
|
13
|
+
// --- windows 下是且只会是沉浸式,其他系统以启动的第一个窗体为准绑定大小最小化最大化关闭等功能 ---
|
|
14
|
+
|
|
15
|
+
/** --- 窗体是否含有 border 边框,有的话将不是沉浸式,也不会绑定任何窗体的大小和相关事件 --- */
|
|
16
|
+
let hasFrame: boolean = false;
|
|
17
|
+
|
|
18
|
+
/** --- 是否没有物理窗体时就主动退出软件(进程结束),如果不要窗体只有 node 的话,会用到 false 的情况 --- */
|
|
19
|
+
let isNoFormQuit: boolean = true;
|
|
7
20
|
|
|
8
|
-
/** --- 环境是否已经准备好了 --- */
|
|
9
|
-
let isReady: boolean = false;
|
|
10
|
-
/** --- 窗体是否显示边框 --- */
|
|
11
|
-
let isFrame: boolean = false;
|
|
12
|
-
/** --- 是否关闭窗口就退出 --- */
|
|
13
|
-
let isQuit: boolean = true;
|
|
14
21
|
/** --- 主窗体 --- */
|
|
15
|
-
let
|
|
22
|
+
let form: electron.BrowserWindow | undefined;
|
|
23
|
+
|
|
24
|
+
/** --- 当前设定的通讯 token --- */
|
|
25
|
+
let token: string = '';
|
|
26
|
+
|
|
16
27
|
/** --- 当前系统平台 --- */
|
|
17
28
|
const platform: NodeJS.Platform = process.platform;
|
|
18
29
|
// const platform: NodeJS.Platform = 'darwin';
|
|
19
|
-
/** --- 当前设定的 token --- */
|
|
20
|
-
let token: string = '';
|
|
21
30
|
|
|
22
|
-
/** ---
|
|
31
|
+
/** --- 监听前台的执行的方法,内置的方法,用户可调用方法自行添加 --- */
|
|
23
32
|
const methods: Record<string, {
|
|
24
33
|
'once': boolean;
|
|
25
34
|
'handler': (...param: any[]) => any | Promise<any>;
|
|
@@ -28,18 +37,19 @@ const methods: Record<string, {
|
|
|
28
37
|
'cg-init': {
|
|
29
38
|
'once': true,
|
|
30
39
|
handler: function(t: string) {
|
|
31
|
-
|
|
40
|
+
// --- t 是网页传来的 token ---
|
|
41
|
+
if (!t || !form) {
|
|
32
42
|
return;
|
|
33
43
|
}
|
|
34
|
-
|
|
44
|
+
form.resizable = true;
|
|
35
45
|
token = t;
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
|
-
// ---
|
|
48
|
+
// --- 完全退出软件进程 ---
|
|
39
49
|
'cg-quit': {
|
|
40
50
|
'once': false,
|
|
41
51
|
handler: function(t: string): void {
|
|
42
|
-
if (!
|
|
52
|
+
if (!t || !form) {
|
|
43
53
|
return;
|
|
44
54
|
}
|
|
45
55
|
if (!verifyToken(t)) {
|
|
@@ -48,25 +58,25 @@ const methods: Record<string, {
|
|
|
48
58
|
electron.app.quit();
|
|
49
59
|
}
|
|
50
60
|
},
|
|
51
|
-
// ---
|
|
61
|
+
// --- 设置实体窗体大小,仅非沉浸式可设置 ---
|
|
52
62
|
'cg-set-size': {
|
|
53
63
|
'once': false,
|
|
54
64
|
handler: function(t: string, width: number, height: number): void {
|
|
55
|
-
if (!
|
|
65
|
+
if (isImmersion || !form || !width || !height) {
|
|
56
66
|
return;
|
|
57
67
|
}
|
|
58
68
|
if (!verifyToken(t)) {
|
|
59
69
|
return;
|
|
60
70
|
}
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
form.setSize(width, height);
|
|
72
|
+
form.center();
|
|
63
73
|
}
|
|
64
74
|
},
|
|
65
|
-
// ---
|
|
75
|
+
// --- 设置窗体最大化、最小化、还原,仅非 frame 可设置 ---
|
|
66
76
|
'cg-set-state': {
|
|
67
77
|
'once': false,
|
|
68
78
|
handler: function(t: string, state: string): void {
|
|
69
|
-
if (!
|
|
79
|
+
if (!hasFrame || !form || !state) {
|
|
70
80
|
return;
|
|
71
81
|
}
|
|
72
82
|
if (!verifyToken(t)) {
|
|
@@ -74,90 +84,369 @@ const methods: Record<string, {
|
|
|
74
84
|
}
|
|
75
85
|
switch (state) {
|
|
76
86
|
case 'max': {
|
|
77
|
-
|
|
87
|
+
form.maximize();
|
|
78
88
|
break;
|
|
79
89
|
}
|
|
80
90
|
case 'min': {
|
|
81
|
-
|
|
91
|
+
form.minimize();
|
|
82
92
|
break;
|
|
83
93
|
}
|
|
84
94
|
default: {
|
|
85
|
-
|
|
95
|
+
form.restore();
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
99
|
},
|
|
90
|
-
// ---
|
|
100
|
+
// --- 激活窗体 ---
|
|
101
|
+
'cg-activate': {
|
|
102
|
+
'once': false,
|
|
103
|
+
handler: function(t: string): void {
|
|
104
|
+
if (!form) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!verifyToken(t)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (form.isMinimized()) {
|
|
111
|
+
form.restore();
|
|
112
|
+
}
|
|
113
|
+
form.setAlwaysOnTop(true);
|
|
114
|
+
form.show();
|
|
115
|
+
form.focus();
|
|
116
|
+
form.setAlwaysOnTop(false);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
// --- 关闭窗体(可能软件进程不会被退出) ---
|
|
91
120
|
'cg-close': {
|
|
92
121
|
'once': false,
|
|
93
122
|
handler: function(t: string): void {
|
|
94
|
-
if (!
|
|
123
|
+
if (!form) {
|
|
95
124
|
return;
|
|
96
125
|
}
|
|
97
126
|
if (!verifyToken(t)) {
|
|
98
127
|
return;
|
|
99
128
|
}
|
|
100
|
-
|
|
129
|
+
form.close();
|
|
101
130
|
}
|
|
102
131
|
},
|
|
103
|
-
// --- 设置 IgnoreMouseEvents
|
|
132
|
+
// --- 设置 IgnoreMouseEvents,仅限沉浸式 ---
|
|
104
133
|
'cg-mouse-ignore': {
|
|
105
134
|
'once': false,
|
|
106
135
|
handler: function(t: string, val: boolean): void {
|
|
107
|
-
if (!
|
|
136
|
+
if (!isImmersion || !form) {
|
|
108
137
|
return;
|
|
109
138
|
}
|
|
110
139
|
if (!verifyToken(t)) {
|
|
111
140
|
return;
|
|
112
141
|
}
|
|
113
142
|
if (val) {
|
|
114
|
-
|
|
143
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
115
144
|
}
|
|
116
145
|
else {
|
|
117
|
-
|
|
146
|
+
form.setIgnoreMouseEvents(false);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
// --- 是否允许最大化 ---
|
|
151
|
+
'cg-maximizable': {
|
|
152
|
+
'once': false,
|
|
153
|
+
handler: function(t: string, val: boolean): void {
|
|
154
|
+
if (isImmersion || !form) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!verifyToken(t)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
form.setMaximizable(val);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
// --- fs 相关操作 ---
|
|
165
|
+
|
|
166
|
+
'cg-fs-getContent': {
|
|
167
|
+
'once': false,
|
|
168
|
+
handler: async function(
|
|
169
|
+
t: string,
|
|
170
|
+
path: string,
|
|
171
|
+
options: Record<string, any>
|
|
172
|
+
): Promise<string | Buffer | null> {
|
|
173
|
+
if (!verifyToken(t)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return libFs.getContent(path, options);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
'cg-fs-putContent': {
|
|
180
|
+
'once': false,
|
|
181
|
+
handler: async function(
|
|
182
|
+
t: string, path: string, data: string | Buffer, options: Record<string, any>
|
|
183
|
+
): Promise<boolean> {
|
|
184
|
+
if (!verifyToken(t)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return fs.putContent(path, data, options);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
'cg-fs-readLink': {
|
|
191
|
+
'once': false,
|
|
192
|
+
handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<string | null> {
|
|
193
|
+
if (!verifyToken(t)) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return fs.readLink(path, encoding);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
'cg-fs-symlink': {
|
|
200
|
+
'once': false,
|
|
201
|
+
handler: async function(t: string, filePath: string, linkPath: string, type?: 'dir' | 'file' | 'junction'): Promise<boolean> {
|
|
202
|
+
if (!verifyToken(t)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return fs.symlink(filePath, linkPath, type);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
'cg-fs-unlink': {
|
|
209
|
+
'once': false,
|
|
210
|
+
handler: async function(t: string, path: string): Promise<boolean> {
|
|
211
|
+
if (!verifyToken(t)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return fs.unlink(path);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
'cg-fs-stats': {
|
|
218
|
+
'once': false,
|
|
219
|
+
handler: async function(t: string, path: string): Promise<Record<string, any> | null> {
|
|
220
|
+
if (!verifyToken(t)) {
|
|
221
|
+
return null;
|
|
118
222
|
}
|
|
223
|
+
return fs.stats(path);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
'cg-fs-mkdir': {
|
|
227
|
+
'once': false,
|
|
228
|
+
handler: async function(t: string, path: string, mode: number): Promise<boolean> {
|
|
229
|
+
if (!verifyToken(t)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
return fs.mkdir(path, mode);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
'cg-fs-rmdir': {
|
|
236
|
+
'once': false,
|
|
237
|
+
handler: async function(t: string, path: string): Promise<boolean> {
|
|
238
|
+
if (!verifyToken(t)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
return fs.rmdir(path);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
'cg-fs-chmod': {
|
|
245
|
+
'once': false,
|
|
246
|
+
handler: async function(t: string, path: string, mod: string | number): Promise<boolean> {
|
|
247
|
+
if (!verifyToken(t)) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return fs.chmod(path, mod);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
'cg-fs-rename': {
|
|
254
|
+
'once': false,
|
|
255
|
+
handler: async function(t: string, oldPath: string, newPath: string): Promise<boolean> {
|
|
256
|
+
if (!verifyToken(t)) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
return fs.rename(oldPath, newPath);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
'cg-fs-readDir': {
|
|
263
|
+
'once': false,
|
|
264
|
+
handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<any[]> {
|
|
265
|
+
if (!verifyToken(t)) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
return fs.readDir(path, encoding);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
'cg-fs-copyFile': {
|
|
272
|
+
'once': false,
|
|
273
|
+
handler: async function(t: string, src: string, dest: string): Promise<boolean> {
|
|
274
|
+
if (!verifyToken(t)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return fs.copyFile(src, dest);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
// --- 无需校验码 ---
|
|
282
|
+
|
|
283
|
+
// --- 测试与 native 的连通性 ---
|
|
284
|
+
'cg-ping': {
|
|
285
|
+
'once': false,
|
|
286
|
+
handler: function(t: string): string {
|
|
287
|
+
// --- t 不是 token,传过来什么就会传回去 ---
|
|
288
|
+
return 'pong: ' + t;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
// --- 判断窗体是否是最大化状态 ---
|
|
292
|
+
'cg-is-max': {
|
|
293
|
+
'once': false,
|
|
294
|
+
handler: function(): boolean {
|
|
295
|
+
return form?.isMaximized ? true : false;
|
|
119
296
|
}
|
|
120
297
|
}
|
|
121
298
|
};
|
|
122
299
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
300
|
+
/** --- 全局类 --- */
|
|
301
|
+
export abstract class AbstractBoot {
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* --- 是否是沉浸式运行 ---
|
|
305
|
+
*/
|
|
306
|
+
public get isImmersion(): boolean {
|
|
307
|
+
return isImmersion;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* --- 是否含有实体窗体边框和标题 ---
|
|
312
|
+
*/
|
|
313
|
+
public get hasFrame(): boolean {
|
|
314
|
+
return hasFrame;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* --- 没有实体窗体时整个实体进程是不是会被结束 ---
|
|
319
|
+
*/
|
|
320
|
+
public get isNoFormQuit(): boolean {
|
|
321
|
+
return isNoFormQuit;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* --- 当前系统代号 ---
|
|
326
|
+
*/
|
|
327
|
+
public get platform(): NodeJS.Platform {
|
|
328
|
+
return platform;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* --- 当前的通讯 token ---
|
|
333
|
+
*/
|
|
334
|
+
public get token(): string {
|
|
335
|
+
return token;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** --- 入口方法 --- */
|
|
339
|
+
public abstract main(): void | Promise<void>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* --- 开始运行起来一个主实体窗体,整个进程本方法只能执行一次 ---
|
|
343
|
+
* @param path 实体窗体网页路径
|
|
344
|
+
* @param opt 参数
|
|
345
|
+
*/
|
|
346
|
+
public run(path: string, opt: { 'frame'?: boolean; 'quit'?: boolean; } = {}): void {
|
|
347
|
+
if (opt.frame !== undefined) {
|
|
348
|
+
// --- 默认 false ---
|
|
349
|
+
hasFrame = opt.frame;
|
|
350
|
+
}
|
|
351
|
+
if (opt.quit !== undefined) {
|
|
352
|
+
// --- 默认 true ---
|
|
353
|
+
isNoFormQuit = opt.quit;
|
|
354
|
+
}
|
|
355
|
+
// --- 判断是否是沉浸式 ---
|
|
356
|
+
if (platform === 'win32') {
|
|
357
|
+
// --- 是 Windows 才有可能是沉浸式 ---
|
|
358
|
+
if (!hasFrame) {
|
|
359
|
+
// --- 实体窗体没有边框,一定是沉浸式 ---
|
|
360
|
+
isImmersion = true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// --- 创建实体窗体 ---
|
|
364
|
+
createForm(path);
|
|
365
|
+
// --- 监听所有实体窗体关闭事件 ---
|
|
366
|
+
electron.app.on('window-all-closed', function(): void {
|
|
367
|
+
if (isNoFormQuit) {
|
|
368
|
+
electron.app.quit();
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
// --- 软件被活动性激活的事件 ---
|
|
372
|
+
electron.app.on('activate', function(): void {
|
|
373
|
+
if (electron.BrowserWindow.getAllWindows().length > 0) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
createForm(path);
|
|
377
|
+
// --- 成功运行一个 task 后再次添加 init ---
|
|
378
|
+
methods['cg-init'] = {
|
|
379
|
+
'once': true,
|
|
380
|
+
handler: function(t: string) {
|
|
381
|
+
// --- t 是网页传来的 token ---
|
|
382
|
+
if (!t || !form) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
form.resizable = true;
|
|
386
|
+
token = t;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* --- 绑定监听网页调用方法的方法 ---
|
|
394
|
+
* @param name 方法名
|
|
395
|
+
* @param handler 要执行的函数
|
|
396
|
+
* @param once 是否只执行一次
|
|
397
|
+
*/
|
|
398
|
+
public on(
|
|
399
|
+
name: string,
|
|
400
|
+
handler: (...param: any[]) => any | Promise<any>,
|
|
401
|
+
once: boolean = false
|
|
402
|
+
): void {
|
|
403
|
+
methods[name] = {
|
|
404
|
+
'once': once,
|
|
405
|
+
'handler': handler
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* --- 绑定监听网页调用方法的方法但只会执行一次 ---
|
|
411
|
+
* @param name 方法名
|
|
412
|
+
* @param handler 要执行的函数
|
|
413
|
+
*/
|
|
414
|
+
public once(name: string, handler: (...param: any[]) => any | Promise<any>): void {
|
|
415
|
+
this.on(name, handler, true);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* --- 解绑监听的方法 ---
|
|
420
|
+
* @param name 方法名
|
|
421
|
+
*/
|
|
422
|
+
public off(name: string): void {
|
|
423
|
+
if (!methods[name]) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
delete methods[name];
|
|
427
|
+
}
|
|
139
428
|
|
|
140
|
-
/**
|
|
141
|
-
* --- node 端绑定前端来调用的方法只执行一次 ---
|
|
142
|
-
* @param name 方法名
|
|
143
|
-
* @param handler 执行的函数
|
|
144
|
-
*/
|
|
145
|
-
export function once(name: string, handler: (...param: any[]) => any | Promise<any>): void {
|
|
146
|
-
bind(name, handler, true);
|
|
147
429
|
}
|
|
148
430
|
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
431
|
+
/** --- 用户调用运行 boot 类 --- */
|
|
432
|
+
export function launcher(boot: AbstractBoot): void {
|
|
433
|
+
(async function() {
|
|
434
|
+
// --- 等到 native 环境装载完毕 ---
|
|
435
|
+
await electron.app.whenReady();
|
|
436
|
+
await fs.refreshDrives();
|
|
437
|
+
// --- 执行回调 ---
|
|
438
|
+
await boot.main();
|
|
439
|
+
})().catch(function() {
|
|
155
440
|
return;
|
|
156
|
-
}
|
|
157
|
-
delete methods[name];
|
|
441
|
+
});
|
|
158
442
|
}
|
|
159
443
|
|
|
160
|
-
|
|
444
|
+
// --- 系统启动 ---
|
|
445
|
+
|
|
446
|
+
electron.Menu.setApplicationMenu(null);
|
|
447
|
+
|
|
448
|
+
// --- 实际用来监听网页传输过来的数据 ---
|
|
449
|
+
electron.ipcMain.handle('pre', function(e: electron.IpcMainInvokeEvent, name: string, ...param: any[]): any {
|
|
161
450
|
if (!methods[name]) {
|
|
162
451
|
return;
|
|
163
452
|
}
|
|
@@ -180,13 +469,9 @@ export function verifyToken(t: string): boolean {
|
|
|
180
469
|
}
|
|
181
470
|
|
|
182
471
|
/**
|
|
183
|
-
* ---
|
|
472
|
+
* --- 内部调用用来创建实体窗体的函数 ---
|
|
473
|
+
* @param p 窗体网页路径
|
|
184
474
|
*/
|
|
185
|
-
export async function ready(): Promise<void> {
|
|
186
|
-
await electron.app.whenReady();
|
|
187
|
-
isReady = true;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
475
|
function createForm(p: string): void {
|
|
191
476
|
const op: Electron.BrowserWindowConstructorOptions = {
|
|
192
477
|
'webPreferences': {
|
|
@@ -194,82 +479,50 @@ function createForm(p: string): void {
|
|
|
194
479
|
'contextIsolation': true,
|
|
195
480
|
'preload': path.join(__dirname, '/pre.js')
|
|
196
481
|
},
|
|
197
|
-
'width': 500,
|
|
198
|
-
'height':
|
|
199
|
-
'frame':
|
|
482
|
+
'width': hasFrame ? 800 : 500,
|
|
483
|
+
'height': hasFrame ? 700 : 300,
|
|
484
|
+
'frame': hasFrame,
|
|
200
485
|
'resizable': false,
|
|
201
486
|
'show': false,
|
|
202
487
|
'center': true,
|
|
203
|
-
'transparent':
|
|
488
|
+
'transparent': isImmersion ? true : false
|
|
204
489
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
if (!
|
|
490
|
+
form = new electron.BrowserWindow(op);
|
|
491
|
+
form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0');
|
|
492
|
+
// form.webContents.openDevTools();
|
|
493
|
+
form.once('ready-to-show', function(): void {
|
|
494
|
+
if (!form) {
|
|
210
495
|
return;
|
|
211
496
|
}
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
497
|
+
if (isImmersion) {
|
|
498
|
+
// --- 沉浸式默认最大化 ---
|
|
499
|
+
form.maximize();
|
|
500
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
215
501
|
}
|
|
216
502
|
else {
|
|
217
503
|
// --- 设置为第一个窗体的大小 ---
|
|
218
504
|
}
|
|
219
|
-
|
|
505
|
+
form.show();
|
|
220
506
|
});
|
|
221
507
|
const lio = p.indexOf('?');
|
|
222
508
|
const search = lio === -1 ? '' : p.slice(lio + 1);
|
|
223
509
|
if (lio !== -1) {
|
|
224
510
|
p = p.slice(0, lio);
|
|
225
511
|
}
|
|
226
|
-
|
|
512
|
+
form.loadFile(p, {
|
|
227
513
|
'search': search
|
|
228
514
|
}).catch(function(e): void {
|
|
229
515
|
throw e;
|
|
230
516
|
});
|
|
231
|
-
|
|
232
|
-
|
|
517
|
+
form.on('close', function() {
|
|
518
|
+
form = undefined;
|
|
233
519
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (!isReady) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (opt.frame !== undefined) {
|
|
241
|
-
isFrame = opt.frame;
|
|
242
|
-
}
|
|
243
|
-
if (opt.quit !== undefined) {
|
|
244
|
-
isQuit = opt.quit;
|
|
245
|
-
}
|
|
246
|
-
createForm(path);
|
|
247
|
-
electron.app.on('window-all-closed', function(): void {
|
|
248
|
-
/*
|
|
249
|
-
// --- MAC ---
|
|
250
|
-
if (platform !== 'darwin') {
|
|
251
|
-
electron.app.quit();
|
|
252
|
-
}
|
|
253
|
-
*/
|
|
254
|
-
if (isQuit) {
|
|
255
|
-
electron.app.quit();
|
|
256
|
-
}
|
|
520
|
+
// --- 最大化事件 ---
|
|
521
|
+
form.on('maximize', function() {
|
|
522
|
+
form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}') as any;
|
|
257
523
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
createForm(path);
|
|
263
|
-
// --- 成功运行一个 task 后 init ---
|
|
264
|
-
methods['cg-init'] = {
|
|
265
|
-
'once': true,
|
|
266
|
-
handler: function(t: string) {
|
|
267
|
-
if (!t || !win) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
win.resizable = true;
|
|
271
|
-
token = t;
|
|
272
|
-
}
|
|
273
|
-
};
|
|
524
|
+
// --- 最大化还原 ---
|
|
525
|
+
form.on('unmaximize', function() {
|
|
526
|
+
form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}') as any;
|
|
274
527
|
});
|
|
275
528
|
}
|