ee-core 1.2.2 → 1.2.5
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/config/config.default.js +17 -0
- package/lib/application.js +7 -3
- package/lib/eeApp.js +25 -31
- package/lib/socket/ipcServer.js +25 -8
- package/package.json +1 -1
- package/utils/common.js +30 -0
- package/utils/index.js +30 -0
package/config/config.default.js
CHANGED
|
@@ -224,5 +224,22 @@ module.exports = appInfo => {
|
|
|
224
224
|
port: 7072, // 默认端口(如果端口被使用,则随机获取一个)
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
+
/**
|
|
228
|
+
* 应用程序顶部菜单
|
|
229
|
+
* boolean | string
|
|
230
|
+
* true, false, 'dev-show'(dev环境显示,prod环境隐藏)
|
|
231
|
+
*/
|
|
232
|
+
config.openAppMenu = true;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 硬件加速
|
|
236
|
+
*/
|
|
237
|
+
config.hardGpu = false;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* loading页(废弃)
|
|
241
|
+
*/
|
|
242
|
+
config.loadingPage = false;
|
|
243
|
+
|
|
227
244
|
return config;
|
|
228
245
|
};
|
package/lib/application.js
CHANGED
|
@@ -29,10 +29,14 @@ class Appliaction extends EeApp {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// argv
|
|
32
|
+
let hotReload = false;
|
|
32
33
|
for (let i = 0; i < process.argv.length; i++) {
|
|
33
34
|
const tmpArgv = process.argv[i]
|
|
34
35
|
if (tmpArgv.indexOf('--env=') !== -1) {
|
|
35
|
-
options.env = tmpArgv.substring(6)
|
|
36
|
+
options.env = tmpArgv.substring(6);
|
|
37
|
+
}
|
|
38
|
+
if (tmpArgv.indexOf('--hot-reload=') !== -1) {
|
|
39
|
+
hotReload = tmpArgv.substring(13) == 1 ? true : false;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
|
|
@@ -52,7 +56,7 @@ class Appliaction extends EeApp {
|
|
|
52
56
|
env.EE_MAIN_PORT = null;
|
|
53
57
|
env.EE_SOCKET_PORT = null;
|
|
54
58
|
env.EE_HTTP_PORT = null;
|
|
55
|
-
env.
|
|
59
|
+
env.HOT_RELOAD = hotReload;
|
|
56
60
|
debug('options:%j', options)
|
|
57
61
|
|
|
58
62
|
super(options);
|
|
@@ -70,7 +74,7 @@ class Appliaction extends EeApp {
|
|
|
70
74
|
|
|
71
75
|
await this.createElectronApp();
|
|
72
76
|
|
|
73
|
-
this.catchLog();
|
|
77
|
+
await this.catchLog();
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|
package/lib/eeApp.js
CHANGED
|
@@ -5,6 +5,7 @@ const BaseApp = require('./baseApp');
|
|
|
5
5
|
const is = require('is-type-of');
|
|
6
6
|
const Koa = require('koa');
|
|
7
7
|
const koaServe = require('koa-static');
|
|
8
|
+
const utilsCommon = require('../utils/common');
|
|
8
9
|
|
|
9
10
|
class EeApp extends BaseApp {
|
|
10
11
|
constructor(options = {}) {
|
|
@@ -85,6 +86,10 @@ class EeApp extends BaseApp {
|
|
|
85
86
|
self.electron.extra.closeWindow = true;
|
|
86
87
|
})
|
|
87
88
|
|
|
89
|
+
if (this.config.hardGpu == false) {
|
|
90
|
+
app.disableHardwareAcceleration();
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
await this.electronAppReady();
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -94,10 +99,21 @@ class EeApp extends BaseApp {
|
|
|
94
99
|
async createWindow () {
|
|
95
100
|
const winOptions = this.config.windowsOption;
|
|
96
101
|
this.electron.mainWindow = new BrowserWindow(winOptions);
|
|
102
|
+
let win = this.electron.mainWindow;
|
|
103
|
+
if (winOptions.show === false) {
|
|
104
|
+
win.once('ready-to-show', () => {
|
|
105
|
+
win.show();
|
|
106
|
+
})
|
|
107
|
+
}
|
|
97
108
|
|
|
98
|
-
//
|
|
99
|
-
if (
|
|
109
|
+
// 菜单显示/隐藏
|
|
110
|
+
if (this.config.openAppMenu === 'dev-show'
|
|
111
|
+
&& this.config.env == 'prod') {
|
|
100
112
|
Menu.setApplicationMenu(null);
|
|
113
|
+
} else if (this.config.openAppMenu === false) {
|
|
114
|
+
Menu.setApplicationMenu(null);
|
|
115
|
+
} else {
|
|
116
|
+
// nothing
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
this.loadingView(winOptions);
|
|
@@ -110,7 +126,7 @@ class EeApp extends BaseApp {
|
|
|
110
126
|
|
|
111
127
|
// DevTools
|
|
112
128
|
if (!app.isPackaged && this.config.openDevTools) {
|
|
113
|
-
|
|
129
|
+
win.webContents.openDevTools();
|
|
114
130
|
}
|
|
115
131
|
}
|
|
116
132
|
|
|
@@ -138,10 +154,13 @@ class EeApp extends BaseApp {
|
|
|
138
154
|
* 加载loading页面
|
|
139
155
|
*/
|
|
140
156
|
loadingView (winOptions) {
|
|
157
|
+
let currentV = process.versions.electron;
|
|
158
|
+
if (utilsCommon.compareVersion(currentV, '12.2.3') == 1) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
141
161
|
if (!this.config.loadingPage) {
|
|
142
162
|
return;
|
|
143
163
|
}
|
|
144
|
-
|
|
145
164
|
const self = this;
|
|
146
165
|
const loadingBrowserView = new BrowserView();
|
|
147
166
|
this.electron.mainWindow.setBrowserView(loadingBrowserView);
|
|
@@ -233,31 +252,11 @@ class EeApp extends BaseApp {
|
|
|
233
252
|
this.electron.mainWindow.loadURL(url);
|
|
234
253
|
}
|
|
235
254
|
|
|
236
|
-
/**
|
|
237
|
-
* 限制一个窗口
|
|
238
|
-
*/
|
|
239
|
-
// async limitOneWindow () {
|
|
240
|
-
// const gotTheLock = app.requestSingleInstanceLock();
|
|
241
|
-
// if (!gotTheLock) {
|
|
242
|
-
// await this.appQuit();
|
|
243
|
-
// }
|
|
244
|
-
// }
|
|
245
|
-
|
|
246
255
|
/**
|
|
247
256
|
* electron app退出
|
|
248
257
|
*/
|
|
249
258
|
async appQuit () {
|
|
250
259
|
await this.beforeClose();
|
|
251
|
-
|
|
252
|
-
// 窗口销毁
|
|
253
|
-
//this.electron.mainWindow.close();
|
|
254
|
-
|
|
255
|
-
//console.log('Exit now!');
|
|
256
|
-
// 托盘销毁
|
|
257
|
-
// if (this.electron.tray) {
|
|
258
|
-
// console.log('ssssssssssss');
|
|
259
|
-
// this.electron.tray.destroy();
|
|
260
|
-
// }
|
|
261
260
|
|
|
262
261
|
app.quit();
|
|
263
262
|
}
|
|
@@ -292,17 +291,12 @@ class EeApp extends BaseApp {
|
|
|
292
291
|
/**
|
|
293
292
|
* 捕获异常
|
|
294
293
|
*/
|
|
295
|
-
catchLog () {
|
|
294
|
+
async catchLog () {
|
|
296
295
|
const self = this;
|
|
296
|
+
|
|
297
297
|
process.on('uncaughtException', function(err) {
|
|
298
298
|
self.logger.error(err);
|
|
299
299
|
});
|
|
300
|
-
|
|
301
|
-
// process.on('SIGINT', function () {
|
|
302
|
-
// console.log('Exit now!');
|
|
303
|
-
// self.appQuit();
|
|
304
|
-
// process.exit();
|
|
305
|
-
// });
|
|
306
300
|
}
|
|
307
301
|
|
|
308
302
|
/**
|
package/lib/socket/ipcServer.js
CHANGED
|
@@ -81,15 +81,15 @@ class IpcServer {
|
|
|
81
81
|
for (const key in fns) {
|
|
82
82
|
let channel = pathName + '.' + key;
|
|
83
83
|
debug('register channel %s', channel);
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
function findFn (app, c) {
|
|
85
86
|
try {
|
|
86
87
|
// 找函数
|
|
87
|
-
const cmd =
|
|
88
|
-
const args = params;
|
|
88
|
+
const cmd = c;
|
|
89
89
|
let fn = null;
|
|
90
90
|
if (is.string(cmd)) {
|
|
91
91
|
const actions = cmd.split('.');
|
|
92
|
-
let obj =
|
|
92
|
+
let obj = app;
|
|
93
93
|
actions.forEach(key => {
|
|
94
94
|
obj = obj[key];
|
|
95
95
|
if (!obj) throw new Error(`class or function '${key}' not exists`);
|
|
@@ -98,12 +98,29 @@ class IpcServer {
|
|
|
98
98
|
}
|
|
99
99
|
if (!fn) throw new Error('function not exists');
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
event.reply(`${channel}`, result)
|
|
101
|
+
return fn;
|
|
103
102
|
} catch (err) {
|
|
104
|
-
|
|
103
|
+
app.logger.error('[ee:socket:ipcMain] throw error:', err);
|
|
105
104
|
}
|
|
106
|
-
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// send/on 模型
|
|
109
|
+
ipcMain.on(channel, async (event, params) => {
|
|
110
|
+
const fn = findFn(self.app, channel);
|
|
111
|
+
const result = await fn.call(self.app, params, event);
|
|
112
|
+
|
|
113
|
+
event.returnValue = result;
|
|
114
|
+
event.reply(`${channel}`, result);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// invoke/handle 模型
|
|
118
|
+
ipcMain.handle(channel, async (event, params) => {
|
|
119
|
+
const fn = findFn(self.app, channel);
|
|
120
|
+
const result = await fn.call(self.app, params, event);
|
|
121
|
+
|
|
122
|
+
return result;
|
|
123
|
+
});
|
|
107
124
|
}
|
|
108
125
|
}
|
|
109
126
|
}
|
package/package.json
CHANGED
package/utils/common.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* 版本号比较
|
|
4
|
+
*/
|
|
5
|
+
exports.compareVersion = function (v1, v2) {
|
|
6
|
+
v1 = v1.split('.')
|
|
7
|
+
v2 = v2.split('.')
|
|
8
|
+
const len = Math.max(v1.length, v2.length)
|
|
9
|
+
|
|
10
|
+
while (v1.length < len) {
|
|
11
|
+
v1.push('0')
|
|
12
|
+
}
|
|
13
|
+
while (v2.length < len) {
|
|
14
|
+
v2.push('0')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < len; i++) {
|
|
18
|
+
const num1 = parseInt(v1[i])
|
|
19
|
+
const num2 = parseInt(v2[i])
|
|
20
|
+
|
|
21
|
+
if (num1 > num2) {
|
|
22
|
+
return 1
|
|
23
|
+
} else if (num1 < num2) {
|
|
24
|
+
return -1
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 0
|
|
29
|
+
}
|
|
30
|
+
|
package/utils/index.js
CHANGED
|
@@ -170,3 +170,33 @@ exports.callFn = async function (fn, args, ctx) {
|
|
|
170
170
|
exports.middleware = function (fn) {
|
|
171
171
|
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
172
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 版本号比较
|
|
176
|
+
*/
|
|
177
|
+
exports.compareVersion = function (v1, v2) {
|
|
178
|
+
v1 = v1.split('.')
|
|
179
|
+
v2 = v2.split('.')
|
|
180
|
+
const len = Math.max(v1.length, v2.length)
|
|
181
|
+
|
|
182
|
+
while (v1.length < len) {
|
|
183
|
+
v1.push('0')
|
|
184
|
+
}
|
|
185
|
+
while (v2.length < len) {
|
|
186
|
+
v2.push('0')
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < len; i++) {
|
|
190
|
+
const num1 = parseInt(v1[i])
|
|
191
|
+
const num2 = parseInt(v2[i])
|
|
192
|
+
|
|
193
|
+
if (num1 > num2) {
|
|
194
|
+
return 1
|
|
195
|
+
} else if (num1 < num2) {
|
|
196
|
+
return -1
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return 0
|
|
201
|
+
}
|
|
202
|
+
|