ee-core 2.12.0 → 4.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/app/application.d.ts +5 -0
- package/app/application.js +31 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +74 -0
- package/app/dir.d.ts +1 -0
- package/app/dir.js +27 -0
- package/app/events.d.ts +14 -0
- package/app/events.js +56 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +7 -0
- package/config/config_loader.d.ts +13 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +111 -0
- package/config/index.d.ts +28 -0
- package/config/index.js +20 -37
- package/const/channel.d.ts +16 -0
- package/const/channel.js +26 -16
- package/controller/controller_loader.d.ts +9 -0
- package/controller/controller_loader.js +78 -0
- package/controller/index.d.ts +2 -0
- package/controller/index.js +18 -19
- package/core/index.d.ts +2 -0
- package/core/index.js +6 -5
- package/core/loader/file_loader.d.ts +66 -0
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.d.ts +12 -0
- package/core/utils/index.js +83 -0
- package/core/utils/timing.d.ts +22 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +152 -0
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +36 -53
- package/cross/index.d.ts +2 -0
- package/cross/index.js +6 -181
- package/electron/app/index.d.ts +5 -0
- package/electron/app/index.js +38 -54
- package/electron/index.d.ts +3 -0
- package/electron/index.js +13 -17
- package/electron/window/index.d.ts +6 -0
- package/electron/window/index.js +260 -65
- package/exception/index.d.ts +9 -0
- package/exception/index.js +42 -54
- package/html/index.d.ts +1 -0
- package/html/index.js +7 -10
- package/index.d.ts +2 -0
- package/index.js +4 -52
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/app.js +10 -10
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +14 -11
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +25 -48
- package/jobs/index.d.ts +3 -0
- package/jobs/index.js +2 -4
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +73 -143
- package/log/index.d.ts +5 -0
- package/log/index.js +74 -57
- package/log/logger.d.ts +2 -0
- package/log/logger.js +75 -80
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +15 -25
- package/message/index.d.ts +3 -0
- package/message/index.js +7 -16
- package/package.json +8 -2
- package/ps/index.d.ts +37 -0
- package/ps/index.js +135 -238
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +55 -45
- package/socket/index.d.ts +10 -0
- package/socket/index.js +52 -69
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +87 -94
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +37 -25
- package/storage/index.d.ts +5 -0
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +20 -20
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/extend.js +10 -5
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +39 -53
- package/utils/index.d.ts +10 -0
- package/utils/index.js +47 -40
- package/utils/ip.d.ts +2 -0
- package/utils/ip.js +5 -45
- package/utils/is.d.ts +14 -0
- package/utils/is.js +107 -141
- package/utils/json.d.ts +5 -0
- package/utils/json.js +15 -7
- package/utils/pargv.d.ts +3 -0
- package/utils/pargv.js +5 -1
- package/utils/port/index.d.ts +1 -0
- package/utils/{get-port → port}/index.js +4 -26
- package/utils/wrap.d.ts +4 -0
- package/utils/wrap.js +8 -3
- package/addon/index.js +0 -35
- package/addon/window/index.js +0 -99
- package/bin/tools.js +0 -8
- package/config/cache.js +0 -62
- package/config/config.default.js +0 -331
- package/const/index.js +0 -9
- package/controller/baseContextClass.js +0 -25
- package/core/lib/ee.js +0 -216
- package/core/lib/loader/context_loader.js +0 -106
- package/core/lib/loader/ee_loader.js +0 -435
- package/core/lib/loader/mixin/addon.js +0 -32
- package/core/lib/loader/mixin/config.js +0 -130
- package/core/lib/loader/mixin/controller.js +0 -125
- package/core/lib/loader/mixin/service.js +0 -28
- package/core/lib/utils/base_context_class.js +0 -34
- package/core/lib/utils/function.js +0 -30
- package/core/lib/utils/index.js +0 -133
- package/core/lib/utils/sequencify.js +0 -59
- package/ee/appLoader.js +0 -48
- package/ee/application.js +0 -101
- package/ee/baseApp.js +0 -99
- package/ee/eeApp.js +0 -406
- package/ee/index.js +0 -58
- package/electron/window/winState.js +0 -186
- package/httpclient/index.js +0 -161
- package/jobs/baseJobClass.js +0 -16
- package/jobs/renderer/index.js +0 -141
- package/jobs/renderer/loadView.js +0 -41
- package/jobs/unification.js +0 -64
- package/main/index.js +0 -57
- package/old-utils/index.js +0 -91
- package/services/baseContextClass.js +0 -24
- package/services/index.js +0 -41
- package/socket/io.js +0 -28
- package/storage/jsondb/adapters/Base.js +0 -23
- package/storage/jsondb/adapters/FileSync.js +0 -64
- package/storage/jsondb/main.js +0 -55
- package/storage/jsondbStorage.js +0 -196
- package/utils/co.js +0 -237
- package/utils/copyto.js +0 -161
- package/utils/depd/index.js +0 -538
- package/utils/depd/lib/browser/index.js +0 -77
- package/utils/get-port/index.d.ts +0 -64
- package/utils/time/index.js +0 -20
- package/utils/time/ms.js +0 -162
package/ee/eeApp.js
DELETED
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const is = require('is-type-of');
|
|
5
|
-
const Koa = require('koa');
|
|
6
|
-
const koaServe = require('koa-static');
|
|
7
|
-
const https = require('https');
|
|
8
|
-
const BaseApp = require('./baseApp');
|
|
9
|
-
const Log = require('../log');
|
|
10
|
-
const CoreElectron = require('../electron');
|
|
11
|
-
const CoreElectronApp = require('../electron/app');
|
|
12
|
-
const CoreElectronWindow = require('../electron/window');
|
|
13
|
-
const Conf = require('../config');
|
|
14
|
-
const Ps = require('../ps');
|
|
15
|
-
const Socket = require('../socket');
|
|
16
|
-
const GetPort = require('../utils/get-port');
|
|
17
|
-
const UtilsHelper = require('../utils/helper');
|
|
18
|
-
const HttpClient = require('../httpclient');
|
|
19
|
-
const Cross = require('../cross');
|
|
20
|
-
const Html = require('../html');
|
|
21
|
-
|
|
22
|
-
class EeApp extends BaseApp {
|
|
23
|
-
constructor(options = {}) {
|
|
24
|
-
super(options);
|
|
25
|
-
|
|
26
|
-
// 兼容旧的api
|
|
27
|
-
this.electron = CoreElectron;
|
|
28
|
-
this.mainWindow;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 生成端口
|
|
33
|
-
*/
|
|
34
|
-
async createPorts() {
|
|
35
|
-
if (Ps.isFrameworkMode() && Conf.isWebProtocol(this.config.mainServer)) {
|
|
36
|
-
const mainPort = await GetPort({port: parseInt(this.config.mainServer.port)});
|
|
37
|
-
process.env.EE_MAIN_PORT = mainPort;
|
|
38
|
-
this.config.mainServer.port = mainPort;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (this.config.socketServer.enable) {
|
|
42
|
-
const socketPort = await GetPort({port: parseInt(this.config.socketServer.port)});
|
|
43
|
-
process.env.EE_SOCKET_PORT = socketPort;
|
|
44
|
-
this.config.socketServer.port = socketPort;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (this.config.httpServer.enable) {
|
|
48
|
-
const httpPort = await GetPort({port: parseInt(this.config.httpServer.port)});
|
|
49
|
-
process.env.EE_HTTP_PORT = httpPort;
|
|
50
|
-
this.config.httpServer.port = httpPort;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 启动通信模块
|
|
56
|
-
*/
|
|
57
|
-
async startSocket() {
|
|
58
|
-
Socket.startAll(this);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 启动跨语言服务
|
|
63
|
-
*/
|
|
64
|
-
async crossService() {
|
|
65
|
-
Cross.create();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 创建electron应用
|
|
70
|
-
*/
|
|
71
|
-
async createElectronApp() {
|
|
72
|
-
if (!Ps.isFrameworkMode()) return;
|
|
73
|
-
const newApp = CoreElectronApp.create();
|
|
74
|
-
if (!newApp) {
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
await this.crossService();
|
|
79
|
-
|
|
80
|
-
await this.electronAppReady();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 创建应用主窗口
|
|
85
|
-
*/
|
|
86
|
-
async createWindow() {
|
|
87
|
-
|
|
88
|
-
// 初始化一个主窗口
|
|
89
|
-
this.mainWindow = CoreElectronWindow.getMainWindow();
|
|
90
|
-
|
|
91
|
-
await this.windowReady();
|
|
92
|
-
|
|
93
|
-
await this._loderAddons();
|
|
94
|
-
|
|
95
|
-
await this._loderPreload();
|
|
96
|
-
|
|
97
|
-
this.selectAppType();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 应用类型 (远程、html、单页应用)
|
|
102
|
-
*/
|
|
103
|
-
async selectAppType() {
|
|
104
|
-
let type = '';
|
|
105
|
-
let url = '';
|
|
106
|
-
|
|
107
|
-
// 远程模式
|
|
108
|
-
const remoteConfig = this.config.remoteUrl;
|
|
109
|
-
if (remoteConfig.enable == true) {
|
|
110
|
-
type = 'remote_web';
|
|
111
|
-
url = remoteConfig.url;
|
|
112
|
-
this.loadMainUrl(type, url);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const mainServer = this.config.mainServer;
|
|
117
|
-
|
|
118
|
-
// 开发环境
|
|
119
|
-
if (Ps.isDev()) {
|
|
120
|
-
let modeInfo;
|
|
121
|
-
let url;
|
|
122
|
-
let load = 'url';
|
|
123
|
-
const configFile = './electron/config/bin.js';
|
|
124
|
-
let electronCfg = {};
|
|
125
|
-
|
|
126
|
-
const isBin = UtilsHelper.checkConfig(configFile);
|
|
127
|
-
if (isBin) {
|
|
128
|
-
const binConfig = UtilsHelper.loadConfig(configFile);
|
|
129
|
-
modeInfo = binConfig.dev.frontend;
|
|
130
|
-
electronCfg = binConfig.dev.electron;
|
|
131
|
-
} else {
|
|
132
|
-
// 兼容旧的 developmentMode
|
|
133
|
-
const developmentModeConfig = this.config.developmentMode;
|
|
134
|
-
const selectMode = developmentModeConfig.default;
|
|
135
|
-
modeInfo = developmentModeConfig.mode[selectMode];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
url = modeInfo.protocol + modeInfo.hostname + ':' + modeInfo.port;
|
|
139
|
-
if (Conf.isFileProtocol(modeInfo)) {
|
|
140
|
-
url = path.join(this.config.homeDir, modeInfo.directory, modeInfo.indexPath);
|
|
141
|
-
load = 'file';
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// 检查 UI serve是否启动,先加载一个boot page
|
|
145
|
-
if (load == 'url') {
|
|
146
|
-
// loading page
|
|
147
|
-
let lp = Html.getFilepath('boot.html');
|
|
148
|
-
if (electronCfg.hasOwnProperty('loadingPage') && electronCfg.loadingPage != '') {
|
|
149
|
-
lp = path.join(this.config.homeDir, electronCfg.loadingPage);
|
|
150
|
-
}
|
|
151
|
-
this._loadingPage(lp);
|
|
152
|
-
|
|
153
|
-
const retryTimes = modeInfo.force === true ? 3 : 60;
|
|
154
|
-
let count = 0;
|
|
155
|
-
let frontendReady = false;
|
|
156
|
-
const hc = new HttpClient();
|
|
157
|
-
while(!frontendReady && count < retryTimes){
|
|
158
|
-
await UtilsHelper.sleep(1 * 1000);
|
|
159
|
-
try {
|
|
160
|
-
await hc.request(url, {
|
|
161
|
-
method: 'GET',
|
|
162
|
-
timeout: 1000,
|
|
163
|
-
});
|
|
164
|
-
frontendReady = true;
|
|
165
|
-
} catch(err) {
|
|
166
|
-
// console.log('The frontend service is starting');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
count++;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (frontendReady == false && modeInfo.force !== true) {
|
|
173
|
-
const bootFailurePage = Html.getFilepath('failure.html');
|
|
174
|
-
this.mainWindow.loadFile(bootFailurePage);
|
|
175
|
-
Log.coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
this.loadMainUrl('spa', url, load);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// 生产环境
|
|
185
|
-
// cross service takeover web
|
|
186
|
-
if (mainServer.hasOwnProperty('takeover')) {
|
|
187
|
-
await this._crossTakeover(mainServer)
|
|
188
|
-
return
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// 主进程
|
|
192
|
-
if (mainServer.protocol == "") {
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
if (Conf.isFileProtocol(mainServer)) {
|
|
196
|
-
url = path.join(this.config.homeDir, mainServer.indexPath);
|
|
197
|
-
this.loadMainUrl('spa', url, 'file');
|
|
198
|
-
} else {
|
|
199
|
-
this.loadLocalWeb('spa');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* cross service takeover web
|
|
205
|
-
*/
|
|
206
|
-
async _crossTakeover(mainCfg = {}) {
|
|
207
|
-
const crossConfig = this.config.cross;
|
|
208
|
-
|
|
209
|
-
// loading page
|
|
210
|
-
if (mainCfg.hasOwnProperty('loadingPage')) {
|
|
211
|
-
const lp = path.join(this.config.homeDir, mainCfg.loadingPage);
|
|
212
|
-
this._loadingPage(lp);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// cross service url
|
|
216
|
-
const service = mainCfg.takeover;
|
|
217
|
-
if (!crossConfig.hasOwnProperty(service)) {
|
|
218
|
-
throw new Error(`[ee-core] Please Check the value of mainServer.takeover in the config file !`);
|
|
219
|
-
}
|
|
220
|
-
// check service
|
|
221
|
-
if (crossConfig[service].enable != true) {
|
|
222
|
-
throw new Error(`[ee-core] Please Check the value of cross.${service} enable is true !`);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const entityName = crossConfig[service].name;
|
|
226
|
-
const url = Cross.getUrl(entityName);
|
|
227
|
-
|
|
228
|
-
let count = 0;
|
|
229
|
-
let serviceReady = false;
|
|
230
|
-
const hc = new HttpClient();
|
|
231
|
-
|
|
232
|
-
// 循环检查
|
|
233
|
-
const times = Ps.isDev() ? 20 : 100;
|
|
234
|
-
const sleeptime = Ps.isDev() ? 1000 : 100;
|
|
235
|
-
while(!serviceReady && count < times){
|
|
236
|
-
await UtilsHelper.sleep(sleeptime);
|
|
237
|
-
try {
|
|
238
|
-
await hc.request(url, {
|
|
239
|
-
method: 'GET',
|
|
240
|
-
timeout: 100,
|
|
241
|
-
});
|
|
242
|
-
serviceReady = true;
|
|
243
|
-
} catch(err) {
|
|
244
|
-
//console.log('The cross service is starting');
|
|
245
|
-
}
|
|
246
|
-
count++;
|
|
247
|
-
}
|
|
248
|
-
//console.log('count:', count)
|
|
249
|
-
if (serviceReady == false) {
|
|
250
|
-
const bootFailurePage = Html.getFilepath('cross-failure.html');
|
|
251
|
-
this.mainWindow.loadFile(bootFailurePage);
|
|
252
|
-
throw new Error(`[ee-core] Please check cross service [${service}] ${url} !`)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
Log.coreLogger.info(`[ee-core] cross service [${service}] is started successfully`);
|
|
256
|
-
this.loadMainUrl('spa', url);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* 加载本地前端资源
|
|
261
|
-
*/
|
|
262
|
-
loadLocalWeb(mode, staticDir) {
|
|
263
|
-
if (!staticDir) {
|
|
264
|
-
staticDir = path.join(this.config.homeDir, 'public', 'dist')
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const koaApp = new Koa();
|
|
268
|
-
koaApp.use(koaServe(staticDir));
|
|
269
|
-
|
|
270
|
-
const mainServer = this.config.mainServer;
|
|
271
|
-
let url = mainServer.protocol + mainServer.host + ':' + mainServer.port;
|
|
272
|
-
|
|
273
|
-
const isHttps = mainServer.protocol == 'https://' ? true : false;
|
|
274
|
-
if (isHttps) {
|
|
275
|
-
const keyFile = path.join(this.config.homeDir, mainServer.ssl.key);
|
|
276
|
-
const certFile = path.join(this.config.homeDir, mainServer.ssl.cert);
|
|
277
|
-
assert(fs.existsSync(keyFile), 'ssl key file is required');
|
|
278
|
-
assert(fs.existsSync(certFile), 'ssl cert file is required');
|
|
279
|
-
|
|
280
|
-
const sslOpt = {
|
|
281
|
-
key: fs.readFileSync(keyFile),
|
|
282
|
-
cert: fs.readFileSync(certFile)
|
|
283
|
-
};
|
|
284
|
-
https.createServer(sslOpt, koaApp.callback()).listen(mainServer.port, (err) => {
|
|
285
|
-
if (err) {
|
|
286
|
-
Log.coreLogger.info('[ee-core] [lib/eeApp] createServer error: ', err);
|
|
287
|
-
return
|
|
288
|
-
}
|
|
289
|
-
this.loadMainUrl(mode, url);
|
|
290
|
-
});
|
|
291
|
-
} else {
|
|
292
|
-
// 使用 host port
|
|
293
|
-
const koaOpt = {
|
|
294
|
-
host: mainServer.open ? undefined : mainServer.host, // 根据配置是否开放0.0.0.0,默认关闭,避免绑定到0.0.0.0
|
|
295
|
-
port: mainServer.port
|
|
296
|
-
}
|
|
297
|
-
koaApp.listen(koaOpt, () => {
|
|
298
|
-
this.loadMainUrl(mode, url);
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* 主服务
|
|
305
|
-
* @params load <string> value: "url" 、 "file"
|
|
306
|
-
*/
|
|
307
|
-
loadMainUrl(type, url, load = 'url') {
|
|
308
|
-
const mainServer = this.config.mainServer;
|
|
309
|
-
Log.coreLogger.info('[ee-core] Env: %s, Type: %s', this.config.env, type);
|
|
310
|
-
Log.coreLogger.info('[ee-core] App running at: %s', url);
|
|
311
|
-
if (load == 'file') {
|
|
312
|
-
this.mainWindow.loadFile(url, mainServer.options)
|
|
313
|
-
.then()
|
|
314
|
-
.catch((err)=>{
|
|
315
|
-
Log.coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
316
|
-
});
|
|
317
|
-
} else {
|
|
318
|
-
this.mainWindow.loadURL(url, mainServer.options)
|
|
319
|
-
.then()
|
|
320
|
-
.catch((err)=>{
|
|
321
|
-
Log.coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* loading page
|
|
328
|
-
*/
|
|
329
|
-
_loadingPage(name) {
|
|
330
|
-
if (!UtilsHelper.fileIsExist(name)) {
|
|
331
|
-
return
|
|
332
|
-
}
|
|
333
|
-
this.mainWindow.loadFile(name);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* electron app退出
|
|
338
|
-
*/
|
|
339
|
-
async appQuit() {
|
|
340
|
-
await this.beforeClose();
|
|
341
|
-
CoreElectronApp.quit();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* 加载插件
|
|
346
|
-
*/
|
|
347
|
-
async _loderAddons() {
|
|
348
|
-
this.loader.loadAddons();
|
|
349
|
-
|
|
350
|
-
// 注册主窗口Contents id
|
|
351
|
-
const addonsCfg = this.config.addons;
|
|
352
|
-
if (addonsCfg.window.enable && Ps.isFrameworkMode()) {
|
|
353
|
-
const win = this.mainWindow;
|
|
354
|
-
const addonWindow = this.addon.window;
|
|
355
|
-
addonWindow.registerWCid('main', win.webContents.id);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* 预加载模块
|
|
361
|
-
*/
|
|
362
|
-
async _loderPreload() {
|
|
363
|
-
let filepath = this.loader.resolveModule(path.join(this.config.baseDir, 'preload', 'index'));
|
|
364
|
-
if (!filepath) return;
|
|
365
|
-
const fileObj = this.loader.loadFile(filepath);
|
|
366
|
-
if (is.function(fileObj) && !is.generatorFunction(fileObj) && !is.asyncFunction(fileObj)) {
|
|
367
|
-
fileObj();
|
|
368
|
-
} else if (is.asyncFunction(fileObj)) {
|
|
369
|
-
await fileObj();
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* module模式初始化
|
|
375
|
-
*/
|
|
376
|
-
async InitModuleMode() {
|
|
377
|
-
if (!Ps.isModuleMode()) return;
|
|
378
|
-
|
|
379
|
-
await this._loderAddons();
|
|
380
|
-
|
|
381
|
-
await this._loderPreload();
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* electron app已经准备好,主窗口还未创建
|
|
386
|
-
*/
|
|
387
|
-
async electronAppReady() {
|
|
388
|
-
// do some things
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* 主应用窗口已经创建
|
|
393
|
-
*/
|
|
394
|
-
async windowReady() {
|
|
395
|
-
// do some things
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* app关闭之前
|
|
400
|
-
*/
|
|
401
|
-
async beforeClose() {
|
|
402
|
-
// do some things
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
module.exports = EeApp;
|
package/ee/index.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const Utils = require('../utils');
|
|
2
|
-
const EEApplication = Symbol('Ee#Application');
|
|
3
|
-
const BuiltInApp = Symbol('Ee#BuiltInApp');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* EE
|
|
7
|
-
*/
|
|
8
|
-
const EE = {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 兼容1.x版本api
|
|
12
|
-
*/
|
|
13
|
-
get Application() {
|
|
14
|
-
const appClass = require('./application');
|
|
15
|
-
return appClass;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 设置实例化app对象
|
|
20
|
-
*/
|
|
21
|
-
set app(appObject) {
|
|
22
|
-
if (!this[EEApplication]) {
|
|
23
|
-
this[EEApplication] = appObject;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 获取实例化app对象
|
|
29
|
-
*/
|
|
30
|
-
get app() {
|
|
31
|
-
return this[EEApplication] || null;
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 设置全局this到CoreApp (eeApp)
|
|
36
|
-
*/
|
|
37
|
-
set CoreApp(obj) {
|
|
38
|
-
if (!this[BuiltInApp]) {
|
|
39
|
-
this[BuiltInApp] = obj;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 获取 CoreApp (eeApp)
|
|
45
|
-
*/
|
|
46
|
-
get CoreApp() {
|
|
47
|
-
return this[BuiltInApp] || null;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 是否加密
|
|
52
|
-
*/
|
|
53
|
-
isEncrypt(basePath) {
|
|
54
|
-
return Utils.isEncrypt(basePath);
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = EE;
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const electron = require('electron');
|
|
5
|
-
const jsonfile = require('jsonfile');
|
|
6
|
-
const mkdirp = require('mkdirp');
|
|
7
|
-
|
|
8
|
-
module.exports = function (options) {
|
|
9
|
-
const app = electron.app || electron.remote.app;
|
|
10
|
-
const screen = electron.screen || electron.remote.screen;
|
|
11
|
-
let state;
|
|
12
|
-
let winRef;
|
|
13
|
-
let stateChangeTimer;
|
|
14
|
-
const eventHandlingDelay = 100;
|
|
15
|
-
const config = Object.assign({
|
|
16
|
-
file: 'window-state.json',
|
|
17
|
-
path: app.getPath('userData'),
|
|
18
|
-
maximize: true,
|
|
19
|
-
fullScreen: true
|
|
20
|
-
}, options);
|
|
21
|
-
const fullStoreFileName = path.join(config.path, config.file);
|
|
22
|
-
|
|
23
|
-
function isNormal(win) {
|
|
24
|
-
return !win.isMaximized() && !win.isMinimized() && !win.isFullScreen();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function hasBounds() {
|
|
28
|
-
return state &&
|
|
29
|
-
Number.isInteger(state.x) &&
|
|
30
|
-
Number.isInteger(state.y) &&
|
|
31
|
-
Number.isInteger(state.width) && state.width > 0 &&
|
|
32
|
-
Number.isInteger(state.height) && state.height > 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function resetStateToDefault() {
|
|
36
|
-
const displayBounds = screen.getPrimaryDisplay().bounds;
|
|
37
|
-
|
|
38
|
-
// Reset state to default values on the primary display
|
|
39
|
-
state = {
|
|
40
|
-
width: config.defaultWidth || 800,
|
|
41
|
-
height: config.defaultHeight || 600,
|
|
42
|
-
x: 0,
|
|
43
|
-
y: 0,
|
|
44
|
-
displayBounds
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function windowWithinBounds(bounds) {
|
|
49
|
-
return (
|
|
50
|
-
state.x >= bounds.x &&
|
|
51
|
-
state.y >= bounds.y &&
|
|
52
|
-
state.x + state.width <= bounds.x + bounds.width &&
|
|
53
|
-
state.y + state.height <= bounds.y + bounds.height
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function ensureWindowVisibleOnSomeDisplay() {
|
|
58
|
-
const visible = screen.getAllDisplays().some(display => {
|
|
59
|
-
return windowWithinBounds(display.bounds);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (!visible) {
|
|
63
|
-
// Window is partially or fully not visible now.
|
|
64
|
-
// Reset it to safe defaults.
|
|
65
|
-
return resetStateToDefault();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function validateState() {
|
|
70
|
-
const isValid = state && (hasBounds() || state.isMaximized || state.isFullScreen);
|
|
71
|
-
if (!isValid) {
|
|
72
|
-
state = null;
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (hasBounds() && state.displayBounds) {
|
|
77
|
-
ensureWindowVisibleOnSomeDisplay();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function updateState(win) {
|
|
82
|
-
win = win || winRef;
|
|
83
|
-
if (!win) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// Don't throw an error when window was closed
|
|
87
|
-
try {
|
|
88
|
-
const winBounds = win.getBounds();
|
|
89
|
-
if (isNormal(win)) {
|
|
90
|
-
state.x = winBounds.x;
|
|
91
|
-
state.y = winBounds.y;
|
|
92
|
-
state.width = winBounds.width;
|
|
93
|
-
state.height = winBounds.height;
|
|
94
|
-
}
|
|
95
|
-
state.isMaximized = win.isMaximized();
|
|
96
|
-
state.isFullScreen = win.isFullScreen();
|
|
97
|
-
state.displayBounds = screen.getDisplayMatching(winBounds).bounds;
|
|
98
|
-
} catch (err) {}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function saveState(win) {
|
|
102
|
-
// Update window state only if it was provided
|
|
103
|
-
if (win) {
|
|
104
|
-
updateState(win);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Save state
|
|
108
|
-
try {
|
|
109
|
-
mkdirp.sync(path.dirname(fullStoreFileName));
|
|
110
|
-
jsonfile.writeFileSync(fullStoreFileName, state);
|
|
111
|
-
} catch (err) {
|
|
112
|
-
// Don't care
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function stateChangeHandler() {
|
|
117
|
-
// Handles both 'resize' and 'move'
|
|
118
|
-
clearTimeout(stateChangeTimer);
|
|
119
|
-
stateChangeTimer = setTimeout(updateState, eventHandlingDelay);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function closeHandler() {
|
|
123
|
-
updateState();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function closedHandler() {
|
|
127
|
-
// Unregister listeners and save state
|
|
128
|
-
unmanage();
|
|
129
|
-
saveState();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function manage(win) {
|
|
133
|
-
if (config.maximize && state.isMaximized) {
|
|
134
|
-
win.maximize();
|
|
135
|
-
}
|
|
136
|
-
if (config.fullScreen && state.isFullScreen) {
|
|
137
|
-
win.setFullScreen(true);
|
|
138
|
-
}
|
|
139
|
-
win.on('resize', stateChangeHandler);
|
|
140
|
-
win.on('move', stateChangeHandler);
|
|
141
|
-
win.on('close', closeHandler);
|
|
142
|
-
win.on('closed', closedHandler);
|
|
143
|
-
winRef = win;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function unmanage() {
|
|
147
|
-
if (winRef) {
|
|
148
|
-
winRef.removeListener('resize', stateChangeHandler);
|
|
149
|
-
winRef.removeListener('move', stateChangeHandler);
|
|
150
|
-
clearTimeout(stateChangeTimer);
|
|
151
|
-
winRef.removeListener('close', closeHandler);
|
|
152
|
-
winRef.removeListener('closed', closedHandler);
|
|
153
|
-
winRef = null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Load previous state
|
|
158
|
-
try {
|
|
159
|
-
state = jsonfile.readFileSync(fullStoreFileName);
|
|
160
|
-
} catch (err) {
|
|
161
|
-
// Don't care
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Check state validity
|
|
165
|
-
validateState();
|
|
166
|
-
|
|
167
|
-
// Set state fallback values
|
|
168
|
-
state = Object.assign({
|
|
169
|
-
width: config.defaultWidth || 800,
|
|
170
|
-
height: config.defaultHeight || 600
|
|
171
|
-
}, state);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
get x() { return state.x; },
|
|
175
|
-
get y() { return state.y; },
|
|
176
|
-
get width() { return state.width; },
|
|
177
|
-
get height() { return state.height; },
|
|
178
|
-
get displayBounds() { return state.displayBounds; },
|
|
179
|
-
get isMaximized() { return state.isMaximized; },
|
|
180
|
-
get isFullScreen() { return state.isFullScreen; },
|
|
181
|
-
saveState,
|
|
182
|
-
unmanage,
|
|
183
|
-
manage,
|
|
184
|
-
resetStateToDefault
|
|
185
|
-
};
|
|
186
|
-
};
|