clickgo-native 0.0.1-dev → 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 +387 -275
- package/dist/index.ts +452 -308
- 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 +31 -0
- package/dist/pre.ts +7 -0
- package/package.json +8 -9
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,320 +32,409 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
32
|
});
|
|
10
33
|
};
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const electron = require("electron");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
19
46
|
let token = '';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
isReady = true;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
exports.ready = ready;
|
|
34
|
-
const listeners = {};
|
|
35
|
-
function on(name, handler, once = false) {
|
|
36
|
-
if (!listeners[name]) {
|
|
37
|
-
listeners[name] = [];
|
|
38
|
-
}
|
|
39
|
-
listeners[name].push({
|
|
40
|
-
'once': once,
|
|
41
|
-
'handler': handler
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
exports.on = on;
|
|
45
|
-
function once(name, handler) {
|
|
46
|
-
on(name, handler, true);
|
|
47
|
-
}
|
|
48
|
-
exports.once = once;
|
|
49
|
-
function off(name, handler) {
|
|
50
|
-
if (!listeners[name]) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
for (let i = 0; i < listeners[name].length; ++i) {
|
|
54
|
-
if (listeners[name][i].handler !== handler) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
listeners[name].splice(i, 1);
|
|
58
|
-
if (listeners[name].length === 0) {
|
|
59
|
-
delete listeners[name];
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
--i;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.off = off;
|
|
66
|
-
let win;
|
|
67
|
-
function createForm(path) {
|
|
68
|
-
const op = {
|
|
69
|
-
'width': 500,
|
|
70
|
-
'height': 400,
|
|
71
|
-
'frame': isFrame,
|
|
72
|
-
'resizable': false,
|
|
73
|
-
'show': false,
|
|
74
|
-
'center': true,
|
|
75
|
-
'transparent': isFrame ? undefined : true
|
|
76
|
-
};
|
|
77
|
-
win = new electron.BrowserWindow(op);
|
|
78
|
-
win.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch;
|
|
79
|
-
win.once('ready-to-show', function () {
|
|
80
|
-
if (!win) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (platform === 'win32') {
|
|
84
|
-
win.maximize();
|
|
85
|
-
win.setIgnoreMouseEvents(true, { 'forward': true });
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
}
|
|
89
|
-
win.show();
|
|
90
|
-
const timerFunc = function () {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
if (!win) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
const rtn = yield win.webContents.executeJavaScript('window.clickGoNative && clickGoNative.isReady');
|
|
97
|
-
if (!rtn) {
|
|
98
|
-
setTimeout(function () {
|
|
99
|
-
timerFunc().catch(function (e) {
|
|
100
|
-
console.log(e);
|
|
101
|
-
});
|
|
102
|
-
}, 100);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (_a) {
|
|
107
|
-
setTimeout(function () {
|
|
108
|
-
timerFunc().catch(function (e) {
|
|
109
|
-
console.log(e);
|
|
110
|
-
});
|
|
111
|
-
}, 100);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const list = JSON.parse(yield win.webContents.executeJavaScript('clickGoNative.cgInnerGetSends()'));
|
|
115
|
-
for (const item of list) {
|
|
116
|
-
if (!listeners[item.name]) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
for (let i = 0; i < listeners[item.name].length; ++i) {
|
|
120
|
-
const it = listeners[item.name][i];
|
|
121
|
-
const result = it.handler(item.param);
|
|
122
|
-
if (it.once) {
|
|
123
|
-
listeners[item.name].splice(i, 1);
|
|
124
|
-
--i;
|
|
125
|
-
}
|
|
126
|
-
if (result instanceof Promise) {
|
|
127
|
-
result.then(function (result) {
|
|
128
|
-
if (!win) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
win.webContents.executeJavaScript(`clickGoNative.cgInnerReceive(${item.id}, "${item.name}", ${result !== undefined ? (', "' + result.replace(/"/g, '\\"') + '"') : ''})`).catch(function (e) {
|
|
132
|
-
console.log(e);
|
|
133
|
-
});
|
|
134
|
-
}).catch(function (e) {
|
|
135
|
-
console.log(e);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
if (!win) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
win.webContents.executeJavaScript(`clickGoNative.cgInnerReceive(${item.id}, "${item.name}", ${result !== undefined ? (', "' + result.replace(/"/g, '\\"') + '"') : ''})`).catch(function (e) {
|
|
143
|
-
console.log(e);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
if (it.once) {
|
|
147
|
-
listeners[item.name].splice(i, 1);
|
|
148
|
-
if (listeners[item.name].length === 0) {
|
|
149
|
-
delete listeners[item.name];
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
--i;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
setTimeout(function () {
|
|
157
|
-
timerFunc().catch(function (e) {
|
|
158
|
-
console.log(e);
|
|
159
|
-
});
|
|
160
|
-
}, 100);
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
timerFunc().catch(function (e) {
|
|
164
|
-
console.log(e);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
const lio = path.indexOf('?');
|
|
168
|
-
const search = lio === -1 ? '' : path.slice(lio + 1);
|
|
169
|
-
if (lio !== -1) {
|
|
170
|
-
path = path.slice(0, lio);
|
|
171
|
-
}
|
|
172
|
-
win.loadFile(path, {
|
|
173
|
-
'search': search
|
|
174
|
-
}).catch(function (e) {
|
|
175
|
-
throw e;
|
|
176
|
-
});
|
|
177
|
-
win.on('close', function () {
|
|
178
|
-
win = undefined;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
function run(path, opt = {}) {
|
|
182
|
-
if (!isReady) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
if (opt.frame !== undefined) {
|
|
186
|
-
isFrame = opt.frame;
|
|
187
|
-
}
|
|
188
|
-
if (opt.quit !== undefined) {
|
|
189
|
-
isQuit = opt.quit;
|
|
190
|
-
}
|
|
191
|
-
createForm(path);
|
|
192
|
-
once('cg-init', function (t) {
|
|
193
|
-
if (!t || !win) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
win.resizable = true;
|
|
197
|
-
token = t;
|
|
198
|
-
});
|
|
199
|
-
on('cg-quit', function (j) {
|
|
200
|
-
if (!win || !j) {
|
|
201
|
-
return;
|
|
47
|
+
const platform = process.platform;
|
|
48
|
+
const methods = {
|
|
49
|
+
'cg-init': {
|
|
50
|
+
'once': true,
|
|
51
|
+
handler: function (t) {
|
|
52
|
+
if (!t || !form) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
form.resizable = true;
|
|
56
|
+
token = t;
|
|
202
57
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
58
|
+
},
|
|
59
|
+
'cg-quit': {
|
|
60
|
+
'once': false,
|
|
61
|
+
handler: function (t) {
|
|
62
|
+
if (!t || !form) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!verifyToken(t)) {
|
|
206
66
|
return;
|
|
207
67
|
}
|
|
208
68
|
electron.app.quit();
|
|
209
69
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (!win || !j) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
const rtn = JSON.parse(j);
|
|
220
|
-
if (!verifyToken(rtn.token)) {
|
|
70
|
+
},
|
|
71
|
+
'cg-set-size': {
|
|
72
|
+
'once': false,
|
|
73
|
+
handler: function (t, width, height) {
|
|
74
|
+
if (isImmersion || !form || !width || !height) {
|
|
221
75
|
return;
|
|
222
76
|
}
|
|
223
|
-
if (!
|
|
77
|
+
if (!verifyToken(t)) {
|
|
224
78
|
return;
|
|
225
79
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
catch (e) {
|
|
230
|
-
console.log(e);
|
|
80
|
+
form.setSize(width, height);
|
|
81
|
+
form.center();
|
|
231
82
|
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (!verifyToken(
|
|
83
|
+
},
|
|
84
|
+
'cg-set-state': {
|
|
85
|
+
'once': false,
|
|
86
|
+
handler: function (t, state) {
|
|
87
|
+
if (hasFrame || !form || !state) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!verifyToken(t)) {
|
|
240
91
|
return;
|
|
241
92
|
}
|
|
242
|
-
switch (
|
|
93
|
+
switch (state) {
|
|
243
94
|
case 'max': {
|
|
244
|
-
|
|
95
|
+
form.maximize();
|
|
245
96
|
break;
|
|
246
97
|
}
|
|
247
98
|
case 'min': {
|
|
248
|
-
|
|
99
|
+
form.minimize();
|
|
249
100
|
break;
|
|
250
101
|
}
|
|
251
102
|
default: {
|
|
252
|
-
|
|
103
|
+
form.restore();
|
|
253
104
|
}
|
|
254
105
|
}
|
|
255
106
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
107
|
+
},
|
|
108
|
+
'cg-close': {
|
|
109
|
+
'once': false,
|
|
110
|
+
handler: function (t) {
|
|
111
|
+
if (!form) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (!verifyToken(t)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
form.close();
|
|
263
118
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
119
|
+
},
|
|
120
|
+
'cg-mouse-ignore': {
|
|
121
|
+
'once': false,
|
|
122
|
+
handler: function (t, val) {
|
|
123
|
+
if (!isImmersion || !form) {
|
|
267
124
|
return;
|
|
268
125
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
126
|
+
if (!verifyToken(t)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (val) {
|
|
130
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
271
131
|
}
|
|
272
132
|
else {
|
|
273
|
-
|
|
133
|
+
form.setIgnoreMouseEvents(false);
|
|
274
134
|
}
|
|
275
135
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (!win || !j) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
try {
|
|
285
|
-
const rtn = JSON.parse(j);
|
|
286
|
-
if (!verifyToken(rtn.token)) {
|
|
136
|
+
},
|
|
137
|
+
'cg-maximizable': {
|
|
138
|
+
'once': false,
|
|
139
|
+
handler: function (t, val) {
|
|
140
|
+
if (isImmersion || !form) {
|
|
287
141
|
return;
|
|
288
142
|
}
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
win.setIgnoreMouseEvents(false);
|
|
143
|
+
if (!verifyToken(t)) {
|
|
144
|
+
return;
|
|
294
145
|
}
|
|
146
|
+
form.setMaximizable(val);
|
|
295
147
|
}
|
|
296
|
-
|
|
297
|
-
|
|
148
|
+
},
|
|
149
|
+
'cg-fs-getContent': {
|
|
150
|
+
'once': false,
|
|
151
|
+
handler: function (t, path, options) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
if (!verifyToken(t)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return libFs.getContent(path, options);
|
|
157
|
+
});
|
|
298
158
|
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
159
|
+
},
|
|
160
|
+
'cg-fs-putContent': {
|
|
161
|
+
'once': false,
|
|
162
|
+
handler: function (t, path, data, options) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
if (!verifyToken(t)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return exports.fs.putContent(path, data, options);
|
|
168
|
+
});
|
|
303
169
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (!t
|
|
310
|
-
return;
|
|
170
|
+
},
|
|
171
|
+
'cg-fs-readLink': {
|
|
172
|
+
'once': false,
|
|
173
|
+
handler: function (t, path, encoding) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
if (!verifyToken(t)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return exports.fs.readLink(path, encoding);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
'cg-fs-symlink': {
|
|
183
|
+
'once': false,
|
|
184
|
+
handler: function (t, filePath, linkPath, type) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
if (!verifyToken(t)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return exports.fs.symlink(filePath, linkPath, type);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
'cg-fs-unlink': {
|
|
194
|
+
'once': false,
|
|
195
|
+
handler: function (t, path) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
if (!verifyToken(t)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return exports.fs.unlink(path);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
'cg-fs-stats': {
|
|
205
|
+
'once': false,
|
|
206
|
+
handler: function (t, path) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
if (!verifyToken(t)) {
|
|
209
|
+
return null;
|
|
311
210
|
}
|
|
312
|
-
|
|
313
|
-
token = t;
|
|
211
|
+
return exports.fs.stats(path);
|
|
314
212
|
});
|
|
315
213
|
}
|
|
214
|
+
},
|
|
215
|
+
'cg-fs-mkdir': {
|
|
216
|
+
'once': false,
|
|
217
|
+
handler: function (t, path, mode) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
if (!verifyToken(t)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return exports.fs.mkdir(path, mode);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
'cg-fs-rmdir': {
|
|
227
|
+
'once': false,
|
|
228
|
+
handler: function (t, path) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (!verifyToken(t)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
return exports.fs.rmdir(path);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
'cg-fs-chmod': {
|
|
238
|
+
'once': false,
|
|
239
|
+
handler: function (t, path, mod) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
if (!verifyToken(t)) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return exports.fs.chmod(path, mod);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
'cg-fs-rename': {
|
|
249
|
+
'once': false,
|
|
250
|
+
handler: function (t, oldPath, newPath) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
if (!verifyToken(t)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
return exports.fs.rename(oldPath, newPath);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
'cg-fs-readDir': {
|
|
260
|
+
'once': false,
|
|
261
|
+
handler: function (t, path, encoding) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
if (!verifyToken(t)) {
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
return exports.fs.readDir(path, encoding);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
'cg-fs-copyFile': {
|
|
271
|
+
'once': false,
|
|
272
|
+
handler: function (t, src, dest) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
if (!verifyToken(t)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return exports.fs.copyFile(src, dest);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
'cg-ping': {
|
|
282
|
+
'once': false,
|
|
283
|
+
handler: function (t) {
|
|
284
|
+
return 'pong: ' + t;
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
'cg-is-max': {
|
|
288
|
+
'once': false,
|
|
289
|
+
handler: function () {
|
|
290
|
+
return (form === null || form === void 0 ? void 0 : form.isMaximized) ? true : false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
class AbstractBoot {
|
|
295
|
+
get isImmersion() {
|
|
296
|
+
return isImmersion;
|
|
297
|
+
}
|
|
298
|
+
get hasFrame() {
|
|
299
|
+
return hasFrame;
|
|
300
|
+
}
|
|
301
|
+
get isNoFormQuit() {
|
|
302
|
+
return isNoFormQuit;
|
|
303
|
+
}
|
|
304
|
+
get platform() {
|
|
305
|
+
return platform;
|
|
306
|
+
}
|
|
307
|
+
get token() {
|
|
308
|
+
return token;
|
|
309
|
+
}
|
|
310
|
+
run(path, opt = {}) {
|
|
311
|
+
if (opt.frame !== undefined) {
|
|
312
|
+
hasFrame = opt.frame;
|
|
313
|
+
}
|
|
314
|
+
if (opt.quit !== undefined) {
|
|
315
|
+
isNoFormQuit = opt.quit;
|
|
316
|
+
}
|
|
317
|
+
if (platform === 'win32') {
|
|
318
|
+
if (!hasFrame) {
|
|
319
|
+
isImmersion = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
createForm(path);
|
|
323
|
+
electron.app.on('window-all-closed', function () {
|
|
324
|
+
if (isNoFormQuit) {
|
|
325
|
+
electron.app.quit();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
electron.app.on('activate', function () {
|
|
329
|
+
if (electron.BrowserWindow.getAllWindows().length > 0) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
createForm(path);
|
|
333
|
+
methods['cg-init'] = {
|
|
334
|
+
'once': true,
|
|
335
|
+
handler: function (t) {
|
|
336
|
+
if (!t || !form) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
form.resizable = true;
|
|
340
|
+
token = t;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
on(name, handler, once = false) {
|
|
346
|
+
methods[name] = {
|
|
347
|
+
'once': once,
|
|
348
|
+
'handler': handler
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
once(name, handler) {
|
|
352
|
+
this.on(name, handler, true);
|
|
353
|
+
}
|
|
354
|
+
off(name) {
|
|
355
|
+
if (!methods[name]) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
delete methods[name];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
exports.AbstractBoot = AbstractBoot;
|
|
362
|
+
function launcher(boot) {
|
|
363
|
+
(function () {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
yield electron.app.whenReady();
|
|
366
|
+
yield exports.fs.refreshDrives();
|
|
367
|
+
yield boot.main();
|
|
368
|
+
});
|
|
369
|
+
})().catch(function () {
|
|
370
|
+
return;
|
|
316
371
|
});
|
|
317
372
|
}
|
|
318
|
-
exports.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
373
|
+
exports.launcher = launcher;
|
|
374
|
+
electron.Menu.setApplicationMenu(null);
|
|
375
|
+
electron.ipcMain.handle('pre', function (e, name, ...param) {
|
|
376
|
+
if (!methods[name]) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const r = methods[name].handler(...param);
|
|
380
|
+
if (methods[name].once) {
|
|
381
|
+
delete methods[name];
|
|
325
382
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
383
|
+
return r;
|
|
384
|
+
});
|
|
385
|
+
function verifyToken(t) {
|
|
386
|
+
if (t !== token) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
exports.verifyToken = verifyToken;
|
|
392
|
+
function createForm(p) {
|
|
393
|
+
const op = {
|
|
394
|
+
'webPreferences': {
|
|
395
|
+
'nodeIntegration': false,
|
|
396
|
+
'contextIsolation': true,
|
|
397
|
+
'preload': path.join(__dirname, '/pre.js')
|
|
398
|
+
},
|
|
399
|
+
'width': hasFrame ? 800 : 500,
|
|
400
|
+
'height': hasFrame ? 600 : 300,
|
|
401
|
+
'frame': hasFrame,
|
|
402
|
+
'resizable': false,
|
|
403
|
+
'show': false,
|
|
404
|
+
'center': true,
|
|
405
|
+
'transparent': isImmersion ? true : false
|
|
406
|
+
};
|
|
407
|
+
form = new electron.BrowserWindow(op);
|
|
408
|
+
form.webContents.userAgent = 'electron/' + electron.app.getVersion() + ' ' + platform + '/' + process.arch + ' immersion/' + (isImmersion ? '1' : '0') + ' frame/' + (hasFrame ? '1' : '0');
|
|
409
|
+
form.once('ready-to-show', function () {
|
|
410
|
+
if (!form) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (isImmersion) {
|
|
414
|
+
form.maximize();
|
|
415
|
+
form.setIgnoreMouseEvents(true, { 'forward': true });
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
}
|
|
419
|
+
form.show();
|
|
420
|
+
});
|
|
421
|
+
const lio = p.indexOf('?');
|
|
422
|
+
const search = lio === -1 ? '' : p.slice(lio + 1);
|
|
423
|
+
if (lio !== -1) {
|
|
424
|
+
p = p.slice(0, lio);
|
|
425
|
+
}
|
|
426
|
+
form.loadFile(p, {
|
|
427
|
+
'search': search
|
|
428
|
+
}).catch(function (e) {
|
|
429
|
+
throw e;
|
|
430
|
+
});
|
|
431
|
+
form.on('close', function () {
|
|
432
|
+
form = undefined;
|
|
433
|
+
});
|
|
434
|
+
form.on('maximize', function () {
|
|
435
|
+
form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("maximize")}');
|
|
436
|
+
});
|
|
437
|
+
form.on('unmaximize', function () {
|
|
438
|
+
form === null || form === void 0 ? void 0 : form.webContents.executeJavaScript('if(window.clickgoNativeWeb){clickgoNativeWeb.invoke("unmaximize")}');
|
|
439
|
+
});
|
|
440
|
+
}
|