ee-core 4.1.2 → 4.1.4
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/LICENSE +21 -21
- package/README.md +65 -65
- package/app/application.d.ts +5 -5
- package/app/application.js +30 -30
- package/app/boot.d.ts +5 -5
- package/app/boot.js +80 -80
- package/app/dir.d.ts +1 -1
- package/app/dir.js +26 -26
- package/app/events.d.ts +14 -14
- package/app/events.js +55 -55
- package/app/index.d.ts +2 -2
- package/app/index.js +6 -6
- package/config/config_loader.d.ts +13 -13
- package/config/config_loader.js +65 -65
- package/config/default_config.d.ts +95 -95
- package/config/default_config.js +111 -111
- package/config/index.d.ts +28 -28
- package/config/index.js +24 -24
- package/const/channel.d.ts +16 -16
- package/const/channel.js +27 -27
- package/controller/controller_loader.d.ts +9 -9
- package/controller/controller_loader.js +77 -77
- package/controller/index.d.ts +2 -2
- package/controller/index.js +24 -24
- package/core/index.d.ts +2 -2
- package/core/index.js +11 -11
- package/core/loader/file_loader.d.ts +66 -66
- package/core/loader/file_loader.js +211 -211
- package/core/utils/index.d.ts +12 -12
- package/core/utils/index.js +83 -83
- package/core/utils/timing.d.ts +22 -22
- package/core/utils/timing.js +78 -78
- package/cross/cross.d.ts +19 -19
- package/cross/cross.js +151 -151
- package/cross/crossProcess.d.ts +29 -29
- package/cross/crossProcess.js +172 -172
- package/cross/index.d.ts +2 -2
- package/cross/index.js +8 -8
- package/electron/app/index.d.ts +5 -5
- package/electron/app/index.js +48 -48
- package/electron/index.d.ts +3 -3
- package/electron/index.js +15 -15
- package/electron/window/index.d.ts +6 -6
- package/electron/window/index.js +268 -268
- package/exception/index.d.ts +9 -9
- package/exception/index.js +100 -100
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.d.ts +1 -1
- package/html/index.js +10 -10
- package/index.d.ts +2 -2
- package/index.js +6 -6
- package/jobs/child/app.d.ts +1 -1
- package/jobs/child/app.js +69 -69
- package/jobs/child/index.d.ts +13 -13
- package/jobs/child/index.js +85 -85
- package/jobs/child/jobProcess.d.ts +16 -16
- package/jobs/child/jobProcess.js +133 -133
- package/jobs/child-pool/index.d.ts +26 -26
- package/jobs/child-pool/index.js +190 -190
- package/jobs/index.d.ts +3 -3
- package/jobs/index.js +6 -6
- package/jobs/load-balancer/algorithm/index.d.ts +4 -4
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.d.ts +2 -2
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -2
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.d.ts +8 -8
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.d.ts +96 -96
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.d.ts +16 -16
- package/jobs/load-balancer/scheduler.js +31 -31
- package/loader/index.d.ts +9 -9
- package/loader/index.js +99 -98
- package/log/index.d.ts +5 -5
- package/log/index.js +85 -85
- package/log/logger.d.ts +1 -1
- package/log/logger.js +94 -94
- package/message/childMessage.d.ts +10 -10
- package/message/childMessage.js +43 -43
- package/message/index.d.ts +3 -3
- package/message/index.js +9 -9
- package/package.json +42 -42
- package/ps/index.d.ts +39 -39
- package/ps/index.js +294 -294
- package/socket/httpServer.d.ts +8 -8
- package/socket/httpServer.js +199 -199
- package/socket/index.d.ts +10 -10
- package/socket/index.js +64 -64
- package/socket/ipcServer.d.ts +9 -9
- package/socket/ipcServer.js +105 -105
- package/socket/socketServer.d.ts +10 -10
- package/socket/socketServer.js +81 -81
- package/storage/index.d.ts +4 -4
- package/storage/index.js +6 -6
- package/storage/sqliteStorage.d.ts +16 -16
- package/storage/sqliteStorage.js +123 -123
- package/tsconfig.json +13 -13
- package/utils/extend.d.ts +2 -2
- package/utils/extend.js +77 -77
- package/utils/helper.d.ts +14 -14
- package/utils/helper.js +206 -206
- package/utils/index.d.ts +10 -10
- package/utils/index.js +167 -167
- package/utils/ip.d.ts +2 -2
- package/utils/ip.js +221 -221
- package/utils/is.d.ts +14 -14
- package/utils/is.js +111 -111
- package/utils/json.d.ts +5 -5
- package/utils/json.js +79 -79
- package/utils/pargv.d.ts +3 -3
- package/utils/pargv.js +267 -267
- package/utils/port/index.d.ts +1 -1
- package/utils/port/index.js +125 -125
- package/utils/wrap.d.ts +4 -4
- package/utils/wrap.js +40 -40
package/electron/window/index.js
CHANGED
|
@@ -1,269 +1,269 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')('ee-core:electron:window');
|
|
4
|
-
const is = require('is-type-of');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const axios = require('axios');
|
|
7
|
-
const { BrowserWindow } = require('electron');
|
|
8
|
-
const { getConfig } = require('../../config');
|
|
9
|
-
const { eventBus, WindowReady } = require('../../app/events');
|
|
10
|
-
const { env, isDev, getBaseDir } = require('../../ps');
|
|
11
|
-
const { loadFile } = require('../../loader');
|
|
12
|
-
const { isFileProtocol } = require('../../utils');
|
|
13
|
-
const { getHtmlFilepath } = require('../../html');
|
|
14
|
-
const { fileIsExist, sleep } = require('../../utils/helper');
|
|
15
|
-
const { coreLogger } = require('../../log');
|
|
16
|
-
const { extend } = require('../../utils/extend');
|
|
17
|
-
const { cross } = require('../../cross');
|
|
18
|
-
|
|
19
|
-
const Instance = {
|
|
20
|
-
mainWindow: null,
|
|
21
|
-
closeAndQuit: true,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// getMainWindow
|
|
25
|
-
function getMainWindow() {
|
|
26
|
-
return Instance.mainWindow;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Create the main application window
|
|
30
|
-
function createMainWindow() {
|
|
31
|
-
const { openDevTools, windowsOption } = getConfig();
|
|
32
|
-
const win = new BrowserWindow(windowsOption);
|
|
33
|
-
Instance.mainWindow = win;
|
|
34
|
-
|
|
35
|
-
// DevTools
|
|
36
|
-
if (is.object(openDevTools)) {
|
|
37
|
-
win.webContents.openDevTools(openDevTools);
|
|
38
|
-
} else if (openDevTools === true) {
|
|
39
|
-
win.webContents.openDevTools({
|
|
40
|
-
mode: 'bottom'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
eventBus.emitLifecycle(WindowReady);
|
|
45
|
-
return win;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// restored window
|
|
49
|
-
function restoreMainWindow() {
|
|
50
|
-
if (Instance.mainWindow) {
|
|
51
|
-
if (Instance.mainWindow.isMinimized()) {
|
|
52
|
-
Instance.mainWindow.restore();
|
|
53
|
-
}
|
|
54
|
-
Instance.mainWindow.show();
|
|
55
|
-
Instance.mainWindow.focus();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Set the flag for exiting after close all windows
|
|
60
|
-
function setCloseAndQuit(flag) {
|
|
61
|
-
Instance.closeAndQuit = flag;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getCloseAndQuit() {
|
|
65
|
-
return Instance.closeAndQuit;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// load server
|
|
69
|
-
// type: remote | single
|
|
70
|
-
async function loadServer() {
|
|
71
|
-
let type = 'spa';
|
|
72
|
-
let url = '';
|
|
73
|
-
const { remote, mainServer } = getConfig();
|
|
74
|
-
const win = getMainWindow();
|
|
75
|
-
|
|
76
|
-
// remote model
|
|
77
|
-
if (remote.enable == true) {
|
|
78
|
-
type = 'remote';
|
|
79
|
-
url = remote.url;
|
|
80
|
-
loadMainUrl(type, url);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 开发环境
|
|
85
|
-
if (isDev()) {
|
|
86
|
-
let url;
|
|
87
|
-
let load = 'url';
|
|
88
|
-
|
|
89
|
-
const binFile = path.join(getBaseDir(), "./cmd/bin.js");
|
|
90
|
-
const binConfig = loadFile(binFile);
|
|
91
|
-
const { dev } = binConfig;
|
|
92
|
-
// tips: match with ee-bin
|
|
93
|
-
const frontendConf = extend(true, {
|
|
94
|
-
protocol: 'http://',
|
|
95
|
-
hostname: 'localhost',
|
|
96
|
-
port: 8080,
|
|
97
|
-
indexPath: 'index.html',
|
|
98
|
-
}, dev.frontend);
|
|
99
|
-
const electronConf = extend(true, {
|
|
100
|
-
loadingPage: '/public/html/loading.html',
|
|
101
|
-
}, dev.electron);
|
|
102
|
-
|
|
103
|
-
url = frontendConf.protocol + frontendConf.hostname + ':' + frontendConf.port;
|
|
104
|
-
if (isFileProtocol(frontendConf.protocol)) {
|
|
105
|
-
url = path.join(getBaseDir(), frontendConf.directory, frontendConf.indexPath);
|
|
106
|
-
load = 'file';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Check if UI serve is started, load a boot page first
|
|
110
|
-
if (load == 'url') {
|
|
111
|
-
// loading page
|
|
112
|
-
let lp = getHtmlFilepath('boot.html');
|
|
113
|
-
if (electronConf.hasOwnProperty('loadingPage') && electronConf.loadingPage != '') {
|
|
114
|
-
lp = path.join(getBaseDir(), electronConf.loadingPage);
|
|
115
|
-
}
|
|
116
|
-
_loadingPage(lp);
|
|
117
|
-
|
|
118
|
-
// check frontend is ready
|
|
119
|
-
const retryTimes = frontendConf.force === true ? 3 : 60;
|
|
120
|
-
let count = 0;
|
|
121
|
-
let frontendReady = false;
|
|
122
|
-
while(!frontendReady && count < retryTimes){
|
|
123
|
-
await sleep(1 * 1000);
|
|
124
|
-
try {
|
|
125
|
-
await axios({
|
|
126
|
-
method: 'get',
|
|
127
|
-
url,
|
|
128
|
-
timeout: 1000,
|
|
129
|
-
proxy: false,
|
|
130
|
-
headers: {
|
|
131
|
-
'Accept': 'text/html, application/json, text/plain, */*',
|
|
132
|
-
},
|
|
133
|
-
//responseType: 'text',
|
|
134
|
-
});
|
|
135
|
-
frontendReady = true;
|
|
136
|
-
} catch(err) {
|
|
137
|
-
// console.warn(err.stack)
|
|
138
|
-
}
|
|
139
|
-
count++;
|
|
140
|
-
}
|
|
141
|
-
debug('it takes %d seconds to start the frontend', count);
|
|
142
|
-
|
|
143
|
-
if (frontendReady == false && frontendConf.force !== true) {
|
|
144
|
-
const bootFailurePage = getHtmlFilepath('failure.html');
|
|
145
|
-
win.loadFile(bootFailurePage);
|
|
146
|
-
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
loadMainUrl(type, url, load);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 生产环境
|
|
156
|
-
// cross takeover web
|
|
157
|
-
if (mainServer.takeover.length > 0) {
|
|
158
|
-
await crossTakeover()
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 主进程
|
|
163
|
-
url = path.join(getBaseDir(), mainServer.indexPath);
|
|
164
|
-
loadMainUrl(type, url, 'file');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 主服务
|
|
169
|
-
* @params load <string> value: "url" 、 "file"
|
|
170
|
-
*/
|
|
171
|
-
function loadMainUrl(type, url, load = 'url') {
|
|
172
|
-
const { mainServer } = getConfig();
|
|
173
|
-
const mainWindow = getMainWindow();
|
|
174
|
-
coreLogger.info('[ee-core] Env: %s, Type: %s', env(), type);
|
|
175
|
-
coreLogger.info('[ee-core] App running at: %s', url);
|
|
176
|
-
if (load == 'file') {
|
|
177
|
-
mainWindow.loadFile(url, mainServer.options)
|
|
178
|
-
.then()
|
|
179
|
-
.catch((err)=>{
|
|
180
|
-
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
181
|
-
});
|
|
182
|
-
} else {
|
|
183
|
-
mainWindow.loadURL(url, mainServer.options)
|
|
184
|
-
.then()
|
|
185
|
-
.catch((err)=>{
|
|
186
|
-
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// loading page
|
|
192
|
-
function _loadingPage(name) {
|
|
193
|
-
if (!fileIsExist(name)) {
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
const win = getMainWindow();
|
|
197
|
-
win.loadFile(name);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* cross takeover web
|
|
202
|
-
*/
|
|
203
|
-
async function crossTakeover() {
|
|
204
|
-
const crossConf = getConfig().cross;
|
|
205
|
-
const mainConf = getConfig().mainServer;
|
|
206
|
-
|
|
207
|
-
// loading page
|
|
208
|
-
if (mainConf.loadingPage.length > 0) {
|
|
209
|
-
const lp = path.join(getBaseDir, mainConf.loadingPage);
|
|
210
|
-
_loadingPage(lp);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// cross service url
|
|
214
|
-
const service = mainConf.takeover;
|
|
215
|
-
if (!crossConf.hasOwnProperty(service)) {
|
|
216
|
-
throw new Error(`[ee-core] Please Check the value of mainServer.takeover in the config file !`);
|
|
217
|
-
}
|
|
218
|
-
// check service
|
|
219
|
-
if (crossConf[service].enable != true) {
|
|
220
|
-
throw new Error(`[ee-core] Please Check the value of cross.${service} enable is true !`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const entityName = crossConf[service].name;
|
|
224
|
-
const url = cross.getUrl(entityName);
|
|
225
|
-
|
|
226
|
-
// 循环检查
|
|
227
|
-
let count = 0;
|
|
228
|
-
let serviceReady = false;
|
|
229
|
-
const times = isDev() ? 20 : 100;
|
|
230
|
-
const sleeptime = isDev() ? 1000 : 200;
|
|
231
|
-
while(!serviceReady && count < times){
|
|
232
|
-
await sleep(sleeptime);
|
|
233
|
-
try {
|
|
234
|
-
await axios({
|
|
235
|
-
method: 'get',
|
|
236
|
-
url,
|
|
237
|
-
timeout: 100,
|
|
238
|
-
proxy: false,
|
|
239
|
-
headers: {
|
|
240
|
-
'Accept': 'text/html, application/json, text/plain, */*',
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
serviceReady = true;
|
|
244
|
-
} catch(err) {
|
|
245
|
-
// console.warn(err.stack)
|
|
246
|
-
}
|
|
247
|
-
count++;
|
|
248
|
-
}
|
|
249
|
-
debug('it takes %d seconds to start the cross serivce', count * sleeptime);
|
|
250
|
-
|
|
251
|
-
if (serviceReady == false) {
|
|
252
|
-
const bootFailurePage = getHtmlFilepath('cross-failure.html');
|
|
253
|
-
const mainWindow = getMainWindow();
|
|
254
|
-
mainWindow.loadFile(bootFailurePage);
|
|
255
|
-
throw new Error(`[ee-core] Please check cross service [${service}] ${url} !`)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
coreLogger.info(`[ee-core] cross service [${service}] is started successfully`);
|
|
259
|
-
loadMainUrl('spa', url);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
module.exports = {
|
|
263
|
-
getMainWindow,
|
|
264
|
-
createMainWindow,
|
|
265
|
-
restoreMainWindow,
|
|
266
|
-
setCloseAndQuit,
|
|
267
|
-
getCloseAndQuit,
|
|
268
|
-
loadServer
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:electron:window');
|
|
4
|
+
const is = require('is-type-of');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const axios = require('axios');
|
|
7
|
+
const { BrowserWindow } = require('electron');
|
|
8
|
+
const { getConfig } = require('../../config');
|
|
9
|
+
const { eventBus, WindowReady } = require('../../app/events');
|
|
10
|
+
const { env, isDev, getBaseDir } = require('../../ps');
|
|
11
|
+
const { loadFile } = require('../../loader');
|
|
12
|
+
const { isFileProtocol } = require('../../utils');
|
|
13
|
+
const { getHtmlFilepath } = require('../../html');
|
|
14
|
+
const { fileIsExist, sleep } = require('../../utils/helper');
|
|
15
|
+
const { coreLogger } = require('../../log');
|
|
16
|
+
const { extend } = require('../../utils/extend');
|
|
17
|
+
const { cross } = require('../../cross');
|
|
18
|
+
|
|
19
|
+
const Instance = {
|
|
20
|
+
mainWindow: null,
|
|
21
|
+
closeAndQuit: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// getMainWindow
|
|
25
|
+
function getMainWindow() {
|
|
26
|
+
return Instance.mainWindow;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create the main application window
|
|
30
|
+
function createMainWindow() {
|
|
31
|
+
const { openDevTools, windowsOption } = getConfig();
|
|
32
|
+
const win = new BrowserWindow(windowsOption);
|
|
33
|
+
Instance.mainWindow = win;
|
|
34
|
+
|
|
35
|
+
// DevTools
|
|
36
|
+
if (is.object(openDevTools)) {
|
|
37
|
+
win.webContents.openDevTools(openDevTools);
|
|
38
|
+
} else if (openDevTools === true) {
|
|
39
|
+
win.webContents.openDevTools({
|
|
40
|
+
mode: 'bottom'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
eventBus.emitLifecycle(WindowReady);
|
|
45
|
+
return win;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// restored window
|
|
49
|
+
function restoreMainWindow() {
|
|
50
|
+
if (Instance.mainWindow) {
|
|
51
|
+
if (Instance.mainWindow.isMinimized()) {
|
|
52
|
+
Instance.mainWindow.restore();
|
|
53
|
+
}
|
|
54
|
+
Instance.mainWindow.show();
|
|
55
|
+
Instance.mainWindow.focus();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Set the flag for exiting after close all windows
|
|
60
|
+
function setCloseAndQuit(flag) {
|
|
61
|
+
Instance.closeAndQuit = flag;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getCloseAndQuit() {
|
|
65
|
+
return Instance.closeAndQuit;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// load server
|
|
69
|
+
// type: remote | single
|
|
70
|
+
async function loadServer() {
|
|
71
|
+
let type = 'spa';
|
|
72
|
+
let url = '';
|
|
73
|
+
const { remote, mainServer } = getConfig();
|
|
74
|
+
const win = getMainWindow();
|
|
75
|
+
|
|
76
|
+
// remote model
|
|
77
|
+
if (remote.enable == true) {
|
|
78
|
+
type = 'remote';
|
|
79
|
+
url = remote.url;
|
|
80
|
+
loadMainUrl(type, url);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 开发环境
|
|
85
|
+
if (isDev()) {
|
|
86
|
+
let url;
|
|
87
|
+
let load = 'url';
|
|
88
|
+
|
|
89
|
+
const binFile = path.join(getBaseDir(), "./cmd/bin.js");
|
|
90
|
+
const binConfig = loadFile(binFile);
|
|
91
|
+
const { dev } = binConfig;
|
|
92
|
+
// tips: match with ee-bin
|
|
93
|
+
const frontendConf = extend(true, {
|
|
94
|
+
protocol: 'http://',
|
|
95
|
+
hostname: 'localhost',
|
|
96
|
+
port: 8080,
|
|
97
|
+
indexPath: 'index.html',
|
|
98
|
+
}, dev.frontend);
|
|
99
|
+
const electronConf = extend(true, {
|
|
100
|
+
loadingPage: '/public/html/loading.html',
|
|
101
|
+
}, dev.electron);
|
|
102
|
+
|
|
103
|
+
url = frontendConf.protocol + frontendConf.hostname + ':' + frontendConf.port;
|
|
104
|
+
if (isFileProtocol(frontendConf.protocol)) {
|
|
105
|
+
url = path.join(getBaseDir(), frontendConf.directory, frontendConf.indexPath);
|
|
106
|
+
load = 'file';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Check if UI serve is started, load a boot page first
|
|
110
|
+
if (load == 'url') {
|
|
111
|
+
// loading page
|
|
112
|
+
let lp = getHtmlFilepath('boot.html');
|
|
113
|
+
if (electronConf.hasOwnProperty('loadingPage') && electronConf.loadingPage != '') {
|
|
114
|
+
lp = path.join(getBaseDir(), electronConf.loadingPage);
|
|
115
|
+
}
|
|
116
|
+
_loadingPage(lp);
|
|
117
|
+
|
|
118
|
+
// check frontend is ready
|
|
119
|
+
const retryTimes = frontendConf.force === true ? 3 : 60;
|
|
120
|
+
let count = 0;
|
|
121
|
+
let frontendReady = false;
|
|
122
|
+
while(!frontendReady && count < retryTimes){
|
|
123
|
+
await sleep(1 * 1000);
|
|
124
|
+
try {
|
|
125
|
+
await axios({
|
|
126
|
+
method: 'get',
|
|
127
|
+
url,
|
|
128
|
+
timeout: 1000,
|
|
129
|
+
proxy: false,
|
|
130
|
+
headers: {
|
|
131
|
+
'Accept': 'text/html, application/json, text/plain, */*',
|
|
132
|
+
},
|
|
133
|
+
//responseType: 'text',
|
|
134
|
+
});
|
|
135
|
+
frontendReady = true;
|
|
136
|
+
} catch(err) {
|
|
137
|
+
// console.warn(err.stack)
|
|
138
|
+
}
|
|
139
|
+
count++;
|
|
140
|
+
}
|
|
141
|
+
debug('it takes %d seconds to start the frontend', count);
|
|
142
|
+
|
|
143
|
+
if (frontendReady == false && frontendConf.force !== true) {
|
|
144
|
+
const bootFailurePage = getHtmlFilepath('failure.html');
|
|
145
|
+
win.loadFile(bootFailurePage);
|
|
146
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
loadMainUrl(type, url, load);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 生产环境
|
|
156
|
+
// cross takeover web
|
|
157
|
+
if (mainServer.takeover.length > 0) {
|
|
158
|
+
await crossTakeover()
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 主进程
|
|
163
|
+
url = path.join(getBaseDir(), mainServer.indexPath);
|
|
164
|
+
loadMainUrl(type, url, 'file');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 主服务
|
|
169
|
+
* @params load <string> value: "url" 、 "file"
|
|
170
|
+
*/
|
|
171
|
+
function loadMainUrl(type, url, load = 'url') {
|
|
172
|
+
const { mainServer } = getConfig();
|
|
173
|
+
const mainWindow = getMainWindow();
|
|
174
|
+
coreLogger.info('[ee-core] Env: %s, Type: %s', env(), type);
|
|
175
|
+
coreLogger.info('[ee-core] App running at: %s', url);
|
|
176
|
+
if (load == 'file') {
|
|
177
|
+
mainWindow.loadFile(url, mainServer.options)
|
|
178
|
+
.then()
|
|
179
|
+
.catch((err)=>{
|
|
180
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
mainWindow.loadURL(url, mainServer.options)
|
|
184
|
+
.then()
|
|
185
|
+
.catch((err)=>{
|
|
186
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// loading page
|
|
192
|
+
function _loadingPage(name) {
|
|
193
|
+
if (!fileIsExist(name)) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
const win = getMainWindow();
|
|
197
|
+
win.loadFile(name);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* cross takeover web
|
|
202
|
+
*/
|
|
203
|
+
async function crossTakeover() {
|
|
204
|
+
const crossConf = getConfig().cross;
|
|
205
|
+
const mainConf = getConfig().mainServer;
|
|
206
|
+
|
|
207
|
+
// loading page
|
|
208
|
+
if (mainConf.loadingPage.length > 0) {
|
|
209
|
+
const lp = path.join(getBaseDir, mainConf.loadingPage);
|
|
210
|
+
_loadingPage(lp);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// cross service url
|
|
214
|
+
const service = mainConf.takeover;
|
|
215
|
+
if (!crossConf.hasOwnProperty(service)) {
|
|
216
|
+
throw new Error(`[ee-core] Please Check the value of mainServer.takeover in the config file !`);
|
|
217
|
+
}
|
|
218
|
+
// check service
|
|
219
|
+
if (crossConf[service].enable != true) {
|
|
220
|
+
throw new Error(`[ee-core] Please Check the value of cross.${service} enable is true !`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const entityName = crossConf[service].name;
|
|
224
|
+
const url = cross.getUrl(entityName);
|
|
225
|
+
|
|
226
|
+
// 循环检查
|
|
227
|
+
let count = 0;
|
|
228
|
+
let serviceReady = false;
|
|
229
|
+
const times = isDev() ? 20 : 100;
|
|
230
|
+
const sleeptime = isDev() ? 1000 : 200;
|
|
231
|
+
while(!serviceReady && count < times){
|
|
232
|
+
await sleep(sleeptime);
|
|
233
|
+
try {
|
|
234
|
+
await axios({
|
|
235
|
+
method: 'get',
|
|
236
|
+
url,
|
|
237
|
+
timeout: 100,
|
|
238
|
+
proxy: false,
|
|
239
|
+
headers: {
|
|
240
|
+
'Accept': 'text/html, application/json, text/plain, */*',
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
serviceReady = true;
|
|
244
|
+
} catch(err) {
|
|
245
|
+
// console.warn(err.stack)
|
|
246
|
+
}
|
|
247
|
+
count++;
|
|
248
|
+
}
|
|
249
|
+
debug('it takes %d seconds to start the cross serivce', count * sleeptime);
|
|
250
|
+
|
|
251
|
+
if (serviceReady == false) {
|
|
252
|
+
const bootFailurePage = getHtmlFilepath('cross-failure.html');
|
|
253
|
+
const mainWindow = getMainWindow();
|
|
254
|
+
mainWindow.loadFile(bootFailurePage);
|
|
255
|
+
throw new Error(`[ee-core] Please check cross service [${service}] ${url} !`)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
coreLogger.info(`[ee-core] cross service [${service}] is started successfully`);
|
|
259
|
+
loadMainUrl('spa', url);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = {
|
|
263
|
+
getMainWindow,
|
|
264
|
+
createMainWindow,
|
|
265
|
+
restoreMainWindow,
|
|
266
|
+
setCloseAndQuit,
|
|
267
|
+
getCloseAndQuit,
|
|
268
|
+
loadServer
|
|
269
269
|
};
|
package/exception/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Capture exceptions
|
|
2
|
-
export declare function loadException(): void;
|
|
3
|
-
// When an exception is thrown on a process without being caught, trigger the event and silence the exception
|
|
4
|
-
export declare function uncaughtExceptionHandler(): void;
|
|
5
|
-
// When the reject exception in the promise is not caught using catch in the synchronization task, it will trigger the event,
|
|
6
|
-
// Even if catch is used in asynchronous situations, it will trigger the event
|
|
7
|
-
export declare function unhandledRejectionHandler(): void;
|
|
8
|
-
// This event is triggered when an exception is thrown on the process without being caught.
|
|
9
|
-
export declare function uncaughtExceptionMonitorHandler(): void;
|
|
1
|
+
// Capture exceptions
|
|
2
|
+
export declare function loadException(): void;
|
|
3
|
+
// When an exception is thrown on a process without being caught, trigger the event and silence the exception
|
|
4
|
+
export declare function uncaughtExceptionHandler(): void;
|
|
5
|
+
// When the reject exception in the promise is not caught using catch in the synchronization task, it will trigger the event,
|
|
6
|
+
// Even if catch is used in asynchronous situations, it will trigger the event
|
|
7
|
+
export declare function unhandledRejectionHandler(): void;
|
|
8
|
+
// This event is triggered when an exception is thrown on the process without being caught.
|
|
9
|
+
export declare function uncaughtExceptionMonitorHandler(): void;
|