ee-core 1.2.3 → 1.2.6

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.
@@ -224,5 +224,24 @@ 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 = {
238
+ enable: false
239
+ };
240
+
241
+ /**
242
+ * loading页(废弃)
243
+ */
244
+ config.loadingPage = false;
245
+
227
246
  return config;
228
247
  };
@@ -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.EGG_SERVER_ENV = options.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.enable == 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 (!this.config.openAppMenu) {
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
- this.electron.mainWindow.webContents.openDevTools();
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.2.3",
3
+ "version": "1.2.6",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
+