ee-core 1.2.1 → 1.2.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.
@@ -224,5 +224,12 @@ 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
+
227
234
  return config;
228
235
  };
@@ -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/baseApp.js CHANGED
@@ -108,30 +108,6 @@ class BaseApp extends EeAppCore {
108
108
  return this[HTTPCLIENT];
109
109
  }
110
110
 
111
- /**
112
- * 调用 egg api
113
- */
114
- // async curlEgg (method, uri, params, timeout = 15000) {
115
- // let result = null;
116
- // try {
117
- // const port = this.config.egg.port;
118
- // const url = "http://127.0.0.1:" + port + uri;
119
- // // console.log('[ee:baseApp] [curlEgg] url:', url);
120
- // const response = await this.curl(url, {
121
- // method: method,
122
- // contentType: 'application/json',
123
- // data: params,
124
- // dataType: 'json',
125
- // timeout: timeout,
126
- // });
127
- // result = response.data;
128
- // } catch (err) {
129
- // this.logger.error('[ee:baseApp] [curlEgg] throw error:', err);
130
- // }
131
-
132
- // return result;
133
- // }
134
-
135
111
  /**
136
112
  * core app have been loaded
137
113
  */
package/lib/eeApp.js CHANGED
@@ -64,20 +64,13 @@ class EeApp extends BaseApp {
64
64
  }
65
65
 
66
66
  app.on('second-instance', (event) => {
67
- if (self.electron.mainWindow) {
68
- if (self.electron.mainWindow.isMinimized()) {
69
- self.electron.mainWindow.restore();
70
- }
71
- self.electron.mainWindow.focus()
72
- }
67
+ self.restoreMainWindow();
73
68
  })
74
69
 
75
70
  app.whenReady().then(() => {
76
71
  self.createWindow();
77
72
  app.on('activate', function () {
78
- if (BrowserWindow.getAllWindows().length === 0) {
79
- self.createWindow();
80
- }
73
+ self.restoreMainWindow();
81
74
  })
82
75
  })
83
76
 
@@ -91,21 +84,24 @@ class EeApp extends BaseApp {
91
84
  app.on('before-quit', () => {
92
85
  self.electron.extra.closeWindow = true;
93
86
  })
87
+ await this.electronAppReady();
94
88
  }
95
89
 
96
90
  /**
97
91
  * 创建应用主窗口
98
92
  */
99
93
  async createWindow () {
100
-
101
- await this.electronAppReady();
102
-
103
94
  const winOptions = this.config.windowsOption;
104
95
  this.electron.mainWindow = new BrowserWindow(winOptions);
105
96
 
106
- // 隐藏菜单
107
- if (!this.config.openAppMenu) {
97
+ // 菜单显示/隐藏
98
+ if (this.config.openAppMenu === 'dev-show'
99
+ && this.config.env == 'prod') {
108
100
  Menu.setApplicationMenu(null);
101
+ } else if (this.config.openAppMenu === false) {
102
+ Menu.setApplicationMenu(null);
103
+ } else {
104
+ // nothing
109
105
  }
110
106
 
111
107
  this.loadingView(winOptions);
@@ -122,6 +118,18 @@ class EeApp extends BaseApp {
122
118
  }
123
119
  }
124
120
 
121
+ /**
122
+ * 还原窗口
123
+ */
124
+ restoreMainWindow () {
125
+ if (this.electron.mainWindow) {
126
+ if (this.electron.mainWindow.isMinimized()) {
127
+ this.electron.mainWindow.restore();
128
+ }
129
+ this.electron.mainWindow.show()
130
+ }
131
+ }
132
+
125
133
  /**
126
134
  * 加载已经实现的功能
127
135
  */
@@ -232,12 +240,12 @@ class EeApp extends BaseApp {
232
240
  /**
233
241
  * 限制一个窗口
234
242
  */
235
- async limitOneWindow () {
236
- const gotTheLock = app.requestSingleInstanceLock();
237
- if (!gotTheLock) {
238
- await this.appQuit();
239
- }
240
- }
243
+ // async limitOneWindow () {
244
+ // const gotTheLock = app.requestSingleInstanceLock();
245
+ // if (!gotTheLock) {
246
+ // await this.appQuit();
247
+ // }
248
+ // }
241
249
 
242
250
  /**
243
251
  * electron app退出
@@ -246,7 +254,7 @@ class EeApp extends BaseApp {
246
254
  await this.beforeClose();
247
255
 
248
256
  // 窗口销毁
249
- this.electron.mainWindow.close();
257
+ //this.electron.mainWindow.close();
250
258
 
251
259
  //console.log('Exit now!');
252
260
  // 托盘销毁
@@ -288,17 +296,12 @@ class EeApp extends BaseApp {
288
296
  /**
289
297
  * 捕获异常
290
298
  */
291
- catchLog () {
299
+ async catchLog () {
292
300
  const self = this;
301
+
293
302
  process.on('uncaughtException', function(err) {
294
303
  self.logger.error(err);
295
304
  });
296
-
297
- // process.on('SIGINT', function () {
298
- // console.log('Exit now!');
299
- // self.appQuit();
300
- // process.exit();
301
- // });
302
305
  }
303
306
 
304
307
  /**
@@ -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
- ipcMain.on(channel, async (event, params) => {
84
+
85
+ function findFn (app, c) {
85
86
  try {
86
87
  // 找函数
87
- const cmd = channel;
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 = self.app;
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
- const result = await fn.call(self.app, args, event);
102
- event.reply(`${channel}`, result)
101
+ return fn;
103
102
  } catch (err) {
104
- self.app.logger.error('[ee:socket:ipcMain] throw error:', err);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.2.1",
3
+ "version": "1.2.4",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -128,7 +128,9 @@ class CodeCompress {
128
128
  * 移除备份
129
129
  */
130
130
  rmBackup () {
131
- fs.rmdirSync(this.backupCodeDir, {recursive: true});
131
+ if (fs.existsSync(this.backupCodeDir)) {
132
+ fs.rmSync(this.backupCodeDir, {recursive: true, force: true});
133
+ }
132
134
  return;
133
135
  }
134
136