ee-core 1.1.6 → 1.1.9
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/lib/eeApp.js +15 -61
- package/lib/socket/io.js +3 -1
- package/package.json +2 -1
- package/utils/index.js +29 -0
package/lib/eeApp.js
CHANGED
|
@@ -26,8 +26,8 @@ class EeApp extends BaseApp {
|
|
|
26
26
|
|
|
27
27
|
process.env.EE_SOCKET_PORT = socketPort;
|
|
28
28
|
process.env.EE_WEB_PORT = webPort;
|
|
29
|
-
this.coreLogger.info('[ee-core:EeApp] [createPorts] socket port:', socketPort);
|
|
30
|
-
this.coreLogger.info('[ee-core:EeApp] [createPorts] web port:', webPort);
|
|
29
|
+
//this.coreLogger.info('[ee-core:EeApp] [createPorts] socket port:', socketPort);
|
|
30
|
+
//this.coreLogger.info('[ee-core:EeApp] [createPorts] web port:', webPort);
|
|
31
31
|
|
|
32
32
|
// 更新db配置
|
|
33
33
|
this.config.socketServer.port = socketPort;
|
|
@@ -79,6 +79,9 @@ class EeApp extends BaseApp {
|
|
|
79
79
|
* 创建应用主窗口
|
|
80
80
|
*/
|
|
81
81
|
async createWindow () {
|
|
82
|
+
|
|
83
|
+
await this.electronAppReady();
|
|
84
|
+
|
|
82
85
|
const winOptions = this.config.windowsOption;
|
|
83
86
|
this.electron.mainWindow = new BrowserWindow(winOptions);
|
|
84
87
|
|
|
@@ -109,34 +112,6 @@ class EeApp extends BaseApp {
|
|
|
109
112
|
return await preferences(this);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
/**
|
|
113
|
-
* 创建egg服务
|
|
114
|
-
*/
|
|
115
|
-
// async startEggServer () {
|
|
116
|
-
// // egg服务是否开启
|
|
117
|
-
// if (this.config.egg.enable == false) {
|
|
118
|
-
// return;
|
|
119
|
-
// }
|
|
120
|
-
// let eggConfig = this.config.egg;
|
|
121
|
-
// const protocol = 'http://';
|
|
122
|
-
// let startRes = null;
|
|
123
|
-
// let url = protocol + eggConfig.hostname + ':' + eggConfig.port;
|
|
124
|
-
|
|
125
|
-
// startRes = await this.startEgg(eggConfig).then((res) => res, (err) => err);
|
|
126
|
-
// this.coreLogger.info('[ee-core:EeApp] [startEggServer] startRes:', startRes)
|
|
127
|
-
// if (startRes === 'success') {
|
|
128
|
-
// // 如果加载远程网址,则不能重复load
|
|
129
|
-
// const remoteConfig = this.config.remoteUrl;
|
|
130
|
-
// if (remoteConfig.enable) {
|
|
131
|
-
// return;
|
|
132
|
-
// }
|
|
133
|
-
// this.loadMainUrl('egg', url);
|
|
134
|
-
// } else {
|
|
135
|
-
// // 失败后重启
|
|
136
|
-
// app.relaunch();
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
115
|
/**
|
|
141
116
|
* 加载loading页面
|
|
142
117
|
*/
|
|
@@ -231,39 +206,10 @@ class EeApp extends BaseApp {
|
|
|
231
206
|
* 主页面
|
|
232
207
|
*/
|
|
233
208
|
loadMainUrl (type, url) {
|
|
234
|
-
this.logger.info('main page is env: %s, type: %s,
|
|
209
|
+
this.logger.info('main page is env: %s, type: %s, App running at: %s', this.config.env, type, url);
|
|
235
210
|
this.electron.mainWindow.loadURL(url);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* egg
|
|
240
|
-
*/
|
|
241
|
-
// startEgg (argv) {
|
|
242
|
-
|
|
243
|
-
// let homeDir = this.homeDir;
|
|
244
|
-
// argv.baseDir = homeDir;
|
|
245
|
-
// argv.framework = path.join(homeDir, 'node_modules', 'egg');
|
|
246
|
-
|
|
247
|
-
// const appName = this.config.name;
|
|
248
|
-
// argv.title = argv.title || `egg-server-${appName}`;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// // normalize env
|
|
252
|
-
// // 目前没有用到,不用修改;想要修改的话,区分打包前后的路径?
|
|
253
|
-
// // env.HOME = HOME; // 这个home不能修改,因为自动升级功能会用到(win没有问题,mac有权限问题)
|
|
254
|
-
// //env.NODE_ENV = 'production';
|
|
255
|
-
|
|
256
|
-
// // 更新缓存配置
|
|
257
|
-
// this.getCoreDB().setItem('config', this.config);
|
|
211
|
+
}
|
|
258
212
|
|
|
259
|
-
// const ignoreKeys = [ '_', '$0', 'env', 'daemon', 'stdout', 'stderr', 'timeout', 'ignore-stderr', 'node' ];
|
|
260
|
-
// const clusterOptions = this.stringify(argv, ignoreKeys);
|
|
261
|
-
// const options = JSON.parse(clusterOptions);
|
|
262
|
-
// this.coreLogger.info('[ee-core:EeApp] [startEgg] options', options);
|
|
263
|
-
// if (is.function(this.startEggCluster)) {
|
|
264
|
-
// return this.startEggCluster(options);
|
|
265
|
-
// }
|
|
266
|
-
// }
|
|
267
213
|
|
|
268
214
|
/**
|
|
269
215
|
* 限制一个窗口
|
|
@@ -337,6 +283,14 @@ class EeApp extends BaseApp {
|
|
|
337
283
|
// });
|
|
338
284
|
}
|
|
339
285
|
|
|
286
|
+
/**
|
|
287
|
+
* electron app已经准备好,主窗口还未创建
|
|
288
|
+
*/
|
|
289
|
+
async electronAppReady () {
|
|
290
|
+
// do some things
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
340
294
|
/**
|
|
341
295
|
* 主应用窗口已经创建
|
|
342
296
|
*/
|
package/lib/socket/io.js
CHANGED
|
@@ -4,6 +4,7 @@ const IoServer = require('socket.io');
|
|
|
4
4
|
const IoClient = require('socket.io-client');
|
|
5
5
|
//const socketServer = require('./socketServer');
|
|
6
6
|
const socketClient = require('./socketClient');
|
|
7
|
+
const Koa = require('koa');
|
|
7
8
|
|
|
8
9
|
const EeSocket = {
|
|
9
10
|
getServer: () => {
|
|
@@ -18,5 +19,6 @@ const EeSocket = {
|
|
|
18
19
|
module.exports = {
|
|
19
20
|
IoServer,
|
|
20
21
|
IoClient,
|
|
21
|
-
EeSocket
|
|
22
|
+
EeSocket,
|
|
23
|
+
Koa
|
|
22
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"agentkeepalive": "^4.2.0",
|
|
16
|
+
"co": "^4.6.0",
|
|
16
17
|
"egg-errors": "^2.3.0",
|
|
17
18
|
"egg-logger": "^2.7.1",
|
|
18
19
|
"electron-is": "^3.0.0",
|
package/utils/index.js
CHANGED
|
@@ -8,6 +8,9 @@ const is = require('is-type-of');
|
|
|
8
8
|
const co = require('co');
|
|
9
9
|
const utility = require('utility');
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 创建文件夹
|
|
13
|
+
*/
|
|
11
14
|
exports.mkdir = function(dirpath, dirname) {
|
|
12
15
|
// 判断是否是第一次调用
|
|
13
16
|
if (typeof dirname === 'undefined') {
|
|
@@ -30,6 +33,9 @@ exports.mkdir = function(dirpath, dirname) {
|
|
|
30
33
|
}
|
|
31
34
|
};
|
|
32
35
|
|
|
36
|
+
/**
|
|
37
|
+
* 修改文件权限
|
|
38
|
+
*/
|
|
33
39
|
exports.chmodPath = function(path, mode) {
|
|
34
40
|
let files = [];
|
|
35
41
|
if (fs.existsSync(path)) {
|
|
@@ -131,6 +137,29 @@ exports.getSocketChannel = function() {
|
|
|
131
137
|
return constant.socketIo.channel;
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
/**
|
|
141
|
+
* 获取 额外资源目录
|
|
142
|
+
*/
|
|
143
|
+
exports.getExtraResourcesDir = function() {
|
|
144
|
+
const cdb = this.getCoreDB();
|
|
145
|
+
const config = cdb.getItem('config');
|
|
146
|
+
const execDir = config.execDir;
|
|
147
|
+
|
|
148
|
+
// 资源路径不同
|
|
149
|
+
let dir = '';
|
|
150
|
+
if (config.isPackaged) {
|
|
151
|
+
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
152
|
+
dir = path.join(execDir, "resources", "extraResources");
|
|
153
|
+
} else {
|
|
154
|
+
// 打包前
|
|
155
|
+
dir = path.join(execDir, "build", "extraResources");
|
|
156
|
+
}
|
|
157
|
+
return dir;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 执行一个函数
|
|
162
|
+
*/
|
|
134
163
|
exports.callFn = async function (fn, args, ctx) {
|
|
135
164
|
args = args || [];
|
|
136
165
|
if (!is.function(fn)) return;
|