clickgo-native 0.0.2-dev2 → 0.0.3-dev3
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 +303 -93
- package/dist/index.ts +360 -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,350 @@ 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
|
+
// --- 关闭窗体(可能软件进程不会被退出) ---
|
|
91
101
|
'cg-close': {
|
|
92
102
|
'once': false,
|
|
93
103
|
handler: function(t: string): void {
|
|
94
|
-
if (!
|
|
104
|
+
if (!form) {
|
|
95
105
|
return;
|
|
96
106
|
}
|
|
97
107
|
if (!verifyToken(t)) {
|
|
98
108
|
return;
|
|
99
109
|
}
|
|
100
|
-
|
|
110
|
+
form.close();
|
|
101
111
|
}
|
|
102
112
|
},
|
|
103
|
-
// --- 设置 IgnoreMouseEvents
|
|
113
|
+
// --- 设置 IgnoreMouseEvents,仅限沉浸式 ---
|
|
104
114
|
'cg-mouse-ignore': {
|
|
105
115
|
'once': false,
|
|
106
116
|
handler: function(t: string, val: boolean): void {
|
|
107
|
-
if (!
|
|
117
|
+
if (!isImmersion || !form) {
|
|
108
118
|
return;
|
|
109
119
|
}
|
|
110
120
|
if (!verifyToken(t)) {
|
|
111
121
|
return;
|
|
112
122
|
}
|
|
113
123
|
if (val) {
|
|
114
|
-
|
|
124
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
115
125
|
}
|
|
116
126
|
else {
|
|
117
|
-
|
|
127
|
+
form.setIgnoreMouseEvents(false);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
// --- 是否允许最大化 ---
|
|
132
|
+
'cg-maximizable': {
|
|
133
|
+
'once': false,
|
|
134
|
+
handler: function(t: string, val: boolean): void {
|
|
135
|
+
if (isImmersion || !form) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!verifyToken(t)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
form.setMaximizable(val);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
// --- fs 相关操作 ---
|
|
146
|
+
|
|
147
|
+
'cg-fs-getContent': {
|
|
148
|
+
'once': false,
|
|
149
|
+
handler: async function(
|
|
150
|
+
t: string,
|
|
151
|
+
path: string,
|
|
152
|
+
options: Record<string, any>
|
|
153
|
+
): Promise<string | Buffer | null> {
|
|
154
|
+
if (!verifyToken(t)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return libFs.getContent(path, options);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
'cg-fs-putContent': {
|
|
161
|
+
'once': false,
|
|
162
|
+
handler: async function(
|
|
163
|
+
t: string, path: string, data: string | Buffer, options: Record<string, any>
|
|
164
|
+
): Promise<boolean> {
|
|
165
|
+
if (!verifyToken(t)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return fs.putContent(path, data, options);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
'cg-fs-readLink': {
|
|
172
|
+
'once': false,
|
|
173
|
+
handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<string | null> {
|
|
174
|
+
if (!verifyToken(t)) {
|
|
175
|
+
return null;
|
|
118
176
|
}
|
|
177
|
+
return fs.readLink(path, encoding);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
'cg-fs-symlink': {
|
|
181
|
+
'once': false,
|
|
182
|
+
handler: async function(t: string, filePath: string, linkPath: string, type?: 'dir' | 'file' | 'junction'): Promise<boolean> {
|
|
183
|
+
if (!verifyToken(t)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
return fs.symlink(filePath, linkPath, type);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
'cg-fs-unlink': {
|
|
190
|
+
'once': false,
|
|
191
|
+
handler: async function(t: string, path: string): Promise<boolean> {
|
|
192
|
+
if (!verifyToken(t)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
return fs.unlink(path);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
'cg-fs-stats': {
|
|
199
|
+
'once': false,
|
|
200
|
+
handler: async function(t: string, path: string): Promise<Record<string, any> | null> {
|
|
201
|
+
if (!verifyToken(t)) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return fs.stats(path);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
'cg-fs-mkdir': {
|
|
208
|
+
'once': false,
|
|
209
|
+
handler: async function(t: string, path: string, mode: number): Promise<boolean> {
|
|
210
|
+
if (!verifyToken(t)) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
return fs.mkdir(path, mode);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
'cg-fs-rmdir': {
|
|
217
|
+
'once': false,
|
|
218
|
+
handler: async function(t: string, path: string): Promise<boolean> {
|
|
219
|
+
if (!verifyToken(t)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return fs.rmdir(path);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
'cg-fs-chmod': {
|
|
226
|
+
'once': false,
|
|
227
|
+
handler: async function(t: string, path: string, mod: string | number): Promise<boolean> {
|
|
228
|
+
if (!verifyToken(t)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return fs.chmod(path, mod);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
'cg-fs-rename': {
|
|
235
|
+
'once': false,
|
|
236
|
+
handler: async function(t: string, oldPath: string, newPath: string): Promise<boolean> {
|
|
237
|
+
if (!verifyToken(t)) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return fs.rename(oldPath, newPath);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
'cg-fs-readDir': {
|
|
244
|
+
'once': false,
|
|
245
|
+
handler: async function(t: string, path: string, encoding?: BufferEncoding): Promise<any[]> {
|
|
246
|
+
if (!verifyToken(t)) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
return fs.readDir(path, encoding);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
'cg-fs-copyFile': {
|
|
253
|
+
'once': false,
|
|
254
|
+
handler: async function(t: string, src: string, dest: string): Promise<boolean> {
|
|
255
|
+
if (!verifyToken(t)) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
return fs.copyFile(src, dest);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
// --- 无需校验码 ---
|
|
263
|
+
|
|
264
|
+
// --- 测试与 native 的连通性 ---
|
|
265
|
+
'cg-ping': {
|
|
266
|
+
'once': false,
|
|
267
|
+
handler: function(t: string): string {
|
|
268
|
+
// --- t 不是 token,传过来什么就会传回去 ---
|
|
269
|
+
return 'pong: ' + t;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
// --- 判断窗体是否是最大化状态 ---
|
|
273
|
+
'cg-is-max': {
|
|
274
|
+
'once': false,
|
|
275
|
+
handler: function(): boolean {
|
|
276
|
+
return form?.isMaximized ? true : false;
|
|
119
277
|
}
|
|
120
278
|
}
|
|
121
279
|
};
|
|
122
280
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
281
|
+
/** --- 全局类 --- */
|
|
282
|
+
export abstract class AbstractBoot {
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* --- 是否是沉浸式运行 ---
|
|
286
|
+
*/
|
|
287
|
+
public get isImmersion(): boolean {
|
|
288
|
+
return isImmersion;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* --- 是否含有实体窗体边框和标题 ---
|
|
293
|
+
*/
|
|
294
|
+
public get hasFrame(): boolean {
|
|
295
|
+
return hasFrame;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* --- 没有实体窗体时整个实体进程是不是会被结束 ---
|
|
300
|
+
*/
|
|
301
|
+
public get isNoFormQuit(): boolean {
|
|
302
|
+
return isNoFormQuit;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* --- 当前系统代号 ---
|
|
307
|
+
*/
|
|
308
|
+
public get platform(): NodeJS.Platform {
|
|
309
|
+
return platform;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* --- 当前的通讯 token ---
|
|
314
|
+
*/
|
|
315
|
+
public get token(): string {
|
|
316
|
+
return token;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** --- 入口方法 --- */
|
|
320
|
+
public abstract main(): void | Promise<void>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* --- 开始运行起来一个主实体窗体,整个进程本方法只能执行一次 ---
|
|
324
|
+
* @param path 实体窗体网页路径
|
|
325
|
+
* @param opt 参数
|
|
326
|
+
*/
|
|
327
|
+
public run(path: string, opt: { 'frame'?: boolean; 'quit'?: boolean; } = {}): void {
|
|
328
|
+
if (opt.frame !== undefined) {
|
|
329
|
+
// --- 默认 false ---
|
|
330
|
+
hasFrame = opt.frame;
|
|
331
|
+
}
|
|
332
|
+
if (opt.quit !== undefined) {
|
|
333
|
+
// --- 默认 true ---
|
|
334
|
+
isNoFormQuit = opt.quit;
|
|
335
|
+
}
|
|
336
|
+
// --- 判断是否是沉浸式 ---
|
|
337
|
+
if (platform === 'win32') {
|
|
338
|
+
// --- 是 Windows 才有可能是沉浸式 ---
|
|
339
|
+
if (!hasFrame) {
|
|
340
|
+
// --- 实体窗体没有边框,一定是沉浸式 ---
|
|
341
|
+
isImmersion = true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// --- 创建实体窗体 ---
|
|
345
|
+
createForm(path);
|
|
346
|
+
// --- 监听所有实体窗体关闭事件 ---
|
|
347
|
+
electron.app.on('window-all-closed', function(): void {
|
|
348
|
+
if (isNoFormQuit) {
|
|
349
|
+
electron.app.quit();
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
// --- 软件被活动性激活的事件 ---
|
|
353
|
+
electron.app.on('activate', function(): void {
|
|
354
|
+
if (electron.BrowserWindow.getAllWindows().length > 0) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
createForm(path);
|
|
358
|
+
// --- 成功运行一个 task 后再次添加 init ---
|
|
359
|
+
methods['cg-init'] = {
|
|
360
|
+
'once': true,
|
|
361
|
+
handler: function(t: string) {
|
|
362
|
+
// --- t 是网页传来的 token ---
|
|
363
|
+
if (!t || !form) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
form.resizable = true;
|
|
367
|
+
token = t;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* --- 绑定监听网页调用方法的方法 ---
|
|
375
|
+
* @param name 方法名
|
|
376
|
+
* @param handler 要执行的函数
|
|
377
|
+
* @param once 是否只执行一次
|
|
378
|
+
*/
|
|
379
|
+
public on(
|
|
380
|
+
name: string,
|
|
381
|
+
handler: (...param: any[]) => any | Promise<any>,
|
|
382
|
+
once: boolean = false
|
|
383
|
+
): void {
|
|
384
|
+
methods[name] = {
|
|
385
|
+
'once': once,
|
|
386
|
+
'handler': handler
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* --- 绑定监听网页调用方法的方法但只会执行一次 ---
|
|
392
|
+
* @param name 方法名
|
|
393
|
+
* @param handler 要执行的函数
|
|
394
|
+
*/
|
|
395
|
+
public once(name: string, handler: (...param: any[]) => any | Promise<any>): void {
|
|
396
|
+
this.on(name, handler, true);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* --- 解绑监听的方法 ---
|
|
401
|
+
* @param name 方法名
|
|
402
|
+
*/
|
|
403
|
+
public off(name: string): void {
|
|
404
|
+
if (!methods[name]) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
delete methods[name];
|
|
408
|
+
}
|
|
139
409
|
|
|
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
410
|
}
|
|
148
411
|
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
412
|
+
/** --- 用户调用运行 boot 类 --- */
|
|
413
|
+
export function launcher(boot: AbstractBoot): void {
|
|
414
|
+
(async function() {
|
|
415
|
+
// --- 等到 native 环境装载完毕 ---
|
|
416
|
+
await electron.app.whenReady();
|
|
417
|
+
await fs.refreshDrives();
|
|
418
|
+
// --- 执行回调 ---
|
|
419
|
+
await boot.main();
|
|
420
|
+
})().catch(function() {
|
|
155
421
|
return;
|
|
156
|
-
}
|
|
157
|
-
delete methods[name];
|
|
422
|
+
});
|
|
158
423
|
}
|
|
159
424
|
|
|
160
|
-
|
|
425
|
+
// --- 系统启动 ---
|
|
426
|
+
|
|
427
|
+
electron.Menu.setApplicationMenu(null);
|
|
428
|
+
|
|
429
|
+
// --- 实际用来监听网页传输过来的数据 ---
|
|
430
|
+
electron.ipcMain.handle('pre', function(e: electron.IpcMainInvokeEvent, name: string, ...param: any[]): any {
|
|
161
431
|
if (!methods[name]) {
|
|
162
432
|
return;
|
|
163
433
|
}
|
|
@@ -180,13 +450,9 @@ export function verifyToken(t: string): boolean {
|
|
|
180
450
|
}
|
|
181
451
|
|
|
182
452
|
/**
|
|
183
|
-
* ---
|
|
453
|
+
* --- 内部调用用来创建实体窗体的函数 ---
|
|
454
|
+
* @param p 窗体网页路径
|
|
184
455
|
*/
|
|
185
|
-
export async function ready(): Promise<void> {
|
|
186
|
-
await electron.app.whenReady();
|
|
187
|
-
isReady = true;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
456
|
function createForm(p: string): void {
|
|
191
457
|
const op: Electron.BrowserWindowConstructorOptions = {
|
|
192
458
|
'webPreferences': {
|
|
@@ -194,82 +460,50 @@ function createForm(p: string): void {
|
|
|
194
460
|
'contextIsolation': true,
|
|
195
461
|
'preload': path.join(__dirname, '/pre.js')
|
|
196
462
|
},
|
|
197
|
-
'width': 500,
|
|
198
|
-
'height':
|
|
199
|
-
'frame':
|
|
463
|
+
'width': hasFrame ? 800 : 500,
|
|
464
|
+
'height': hasFrame ? 600 : 300,
|
|
465
|
+
'frame': hasFrame,
|
|
200
466
|
'resizable': false,
|
|
201
467
|
'show': false,
|
|
202
468
|
'center': true,
|
|
203
|
-
'transparent':
|
|
469
|
+
'transparent': isImmersion ? true : false
|
|
204
470
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
if (!
|
|
471
|
+
form = new electron.BrowserWindow(op);
|
|
472
|
+
form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0');
|
|
473
|
+
// form.webContents.openDevTools();
|
|
474
|
+
form.once('ready-to-show', function(): void {
|
|
475
|
+
if (!form) {
|
|
210
476
|
return;
|
|
211
477
|
}
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
478
|
+
if (isImmersion) {
|
|
479
|
+
// --- 沉浸式默认最大化 ---
|
|
480
|
+
form.maximize();
|
|
481
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
215
482
|
}
|
|
216
483
|
else {
|
|
217
484
|
// --- 设置为第一个窗体的大小 ---
|
|
218
485
|
}
|
|
219
|
-
|
|
486
|
+
form.show();
|
|
220
487
|
});
|
|
221
488
|
const lio = p.indexOf('?');
|
|
222
489
|
const search = lio === -1 ? '' : p.slice(lio + 1);
|
|
223
490
|
if (lio !== -1) {
|
|
224
491
|
p = p.slice(0, lio);
|
|
225
492
|
}
|
|
226
|
-
|
|
493
|
+
form.loadFile(p, {
|
|
227
494
|
'search': search
|
|
228
495
|
}).catch(function(e): void {
|
|
229
496
|
throw e;
|
|
230
497
|
});
|
|
231
|
-
|
|
232
|
-
|
|
498
|
+
form.on('close', function() {
|
|
499
|
+
form = undefined;
|
|
233
500
|
});
|
|
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
|
-
}
|
|
501
|
+
// --- 最大化事件 ---
|
|
502
|
+
form.on('maximize', function() {
|
|
503
|
+
form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}') as any;
|
|
257
504
|
});
|
|
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
|
-
};
|
|
505
|
+
// --- 最大化还原 ---
|
|
506
|
+
form.on('unmaximize', function() {
|
|
507
|
+
form?.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}') as any;
|
|
274
508
|
});
|
|
275
509
|
}
|