ee-core 1.1.5 → 1.1.8

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.
@@ -27,14 +27,6 @@ module.exports = appInfo => {
27
27
  */
28
28
  name: appInfo.name,
29
29
 
30
- /**
31
- * package.json
32
- * @member {Object} Config#pkg
33
- * @see {appInfo#pkg}
34
- * @since 1.0.0
35
- */
36
- pkg: appInfo.pkg,
37
-
38
30
  /**
39
31
  * The current directory of the application
40
32
  * @member {String} Config#baseDir
@@ -97,7 +89,31 @@ module.exports = appInfo => {
97
89
  * @default
98
90
  * @since 1.0.0
99
91
  */
100
- appUserDataDir: appInfo.appUserDataDir
92
+ appUserDataDir: appInfo.appUserDataDir,
93
+
94
+ /**
95
+ * system user home dir
96
+ * @member {String} Config#userHome
97
+ */
98
+ userHome: appInfo.userHome,
99
+
100
+ /**
101
+ * application version
102
+ * @member {String} Config#appVersion
103
+ */
104
+ appVersion: appInfo.appVersion,
105
+
106
+ /**
107
+ * application package status
108
+ * @member {boolean} Config#isPackaged
109
+ */
110
+ isPackaged: appInfo.isPackaged,
111
+
112
+ /**
113
+ * application exec file dir
114
+ * @member {String} Config#execDir
115
+ */
116
+ execDir: appInfo.execDir
101
117
  };
102
118
 
103
119
  /**
@@ -175,19 +191,11 @@ module.exports = appInfo => {
175
191
  },
176
192
  };
177
193
 
178
- /* egg服务 (待定) */
179
- config.egg = {
180
- enable: false, // 是否启用
181
- title: 'ee', // 进程的title属性标识(默认你的应用名称-英文)
182
- port: 7068,
183
- hostname: '127.0.0.1',
184
- workers: 1 // 工作进程数据
185
- };
186
-
187
- /* web渲染服务 */
188
- config.webServer = {
189
- port: 7068
190
- };
194
+ /* 内置socket服务 */
195
+ config.socketServer = {
196
+ port: 7070, // 默认端口
197
+ isDynamic: false // 如果值为false,框架默认使用port端口(如果默认端口被使用,则随机获取一个);如果为true,默认端口无效,框架随机生成
198
+ };
191
199
 
192
200
  return config;
193
201
  };
package/core/lib/ee.js CHANGED
@@ -88,15 +88,11 @@ class EeCore extends KoaApplication {
88
88
  */
89
89
  const Loader = this[EE_LOADER];
90
90
  assert(Loader, 'Symbol.for(\'ee#loader\') is required');
91
- this.loader = new Loader({
92
- baseDir: options.baseDir,
93
- homeDir: options.homeDir,
91
+ let loaderOptions = Object.assign({
94
92
  logger: this.console,
95
- app: this,
96
- env: options.env,
97
- appUserData: options.appUserData,
98
- isPackaged: options.isPackaged
99
- });
93
+ app:this
94
+ }, options);
95
+ this.loader = new Loader(loaderOptions);
100
96
  }
101
97
 
102
98
  /**
@@ -147,11 +147,7 @@ class EeLoader {
147
147
  */
148
148
  getAppInfo() {
149
149
  const env = this.serverEnv;
150
- const scope = this.serverScope;
151
- const home = this.getHomedir();
152
- const baseDir = this.options.baseDir;
153
- const appUserDataDir = this.options.appUserData;
154
-
150
+
155
151
  /**
156
152
  * Meta information of the application
157
153
  * @class AppInfo
@@ -167,7 +163,7 @@ class EeLoader {
167
163
  * The current directory, where the application code is.
168
164
  * @member {String} AppInfo#baseDir
169
165
  */
170
- baseDir,
166
+ baseDir: this.options.baseDir,
171
167
 
172
168
  /**
173
169
  * The environment of the application, **it's not NODE_ENV**
@@ -186,24 +182,18 @@ class EeLoader {
186
182
  * @member {String} AppInfo#env
187
183
  * @see https://Eejs.org/zh-cn/basics/env.html
188
184
  */
189
- env,
185
+ env: env,
190
186
 
191
187
  /**
192
188
  * @member {String} AppInfo#scope
193
189
  */
194
- scope,
190
+ scope: this.serverScope,
195
191
 
196
192
  /**
197
193
  * The use directory, same as `process.env.HOME`
198
194
  * @member {String} AppInfo#HOME
199
195
  */
200
- home: home,
201
-
202
- /**
203
- * parsed from `package.json`
204
- * @member {Object} AppInfo#pkg
205
- */
206
- pkg: this.pkg,
196
+ home: this.getHomedir(),
207
197
 
208
198
  /**
209
199
  * The directory whether is baseDir or HOME depend on env.
@@ -213,9 +203,37 @@ class EeLoader {
213
203
  * keep root directory in baseDir when local and unittest
214
204
  * @member {String} AppInfo#root
215
205
  */
216
- root: env === 'local' || env === 'unittest' ? home : appUserDataDir,
206
+ root: env === 'local' || env === 'unittest' ? this.getHomedir() : this.options.appUserData,
217
207
 
218
- appUserDataDir: appUserDataDir
208
+ /**
209
+ * electron application data dir
210
+ * @member {String} AppInfo#appUserDataDir
211
+ */
212
+ appUserDataDir: this.options.appUserData,
213
+
214
+ /**
215
+ * system user home dir
216
+ * @member {String} AppInfo#userHome
217
+ */
218
+ userHome: this.options.userHome,
219
+
220
+ /**
221
+ * application version
222
+ * @member {String} AppInfo#appVersion
223
+ */
224
+ appVersion: this.options.appVersion,
225
+
226
+ /**
227
+ * application package status
228
+ * @member {boolean} AppInfo#isPackaged
229
+ */
230
+ isPackaged: this.options.isPackaged,
231
+
232
+ /**
233
+ * application exec file dir
234
+ * @member {String} AppInfo#execDir
235
+ */
236
+ execDir: this.options.execDir
219
237
  };
220
238
  }
221
239
 
@@ -409,15 +427,9 @@ class EeLoader {
409
427
  }
410
428
 
411
429
  getPkg() {
412
- //let filePath = '';
413
- // let variablePath = 'build'; // 打包前路径
414
- // if (this.options.isPackaged) {
415
- // variablePath = '..'; // 打包后路径
416
- // }
417
- // filePath = path.join(app.getAppPath(), variablePath, "package.json");
418
-
419
- const content = utility.readJSONSync(path.join(this.options.homeDir, 'package.json'));
420
- return content;
430
+ const filePath = path.join(this.options.homeDir, 'package.json');
431
+ const json = utility.readJSONSync(filePath);
432
+ return json;
421
433
  }
422
434
  }
423
435
 
@@ -11,8 +11,6 @@ class Appliaction extends EeApp {
11
11
  const { env } = process;
12
12
 
13
13
  // 路径不能使用绝对,打包前后有问题
14
-
15
-
16
14
  let options = {
17
15
  env: 'prod',
18
16
  serverScope: '',
@@ -24,9 +22,10 @@ class Appliaction extends EeApp {
24
22
  userHome: app.getPath('home'),
25
23
  appData: app.getPath('appData'),
26
24
  appUserData: app.getPath('userData'),
27
- logsDir: app.getPath('logs'),
25
+ //logsDir: app.getPath('logs'),
28
26
  appVersion: app.getVersion(),
29
- isPackaged: app.isPackaged
27
+ isPackaged: app.isPackaged,
28
+ execDir: app.getAppPath()
30
29
  }
31
30
 
32
31
  // argv
@@ -37,8 +36,12 @@ class Appliaction extends EeApp {
37
36
  }
38
37
  }
39
38
 
40
- // normalize env
39
+ // exec directory (exe dmg dep) for prod
40
+ if (options.env == 'prod' && app.isPackaged) {
41
+ options.execDir = path.dirname(app.getPath('exe'));
42
+ }
41
43
 
44
+ // normalize env
42
45
  env.NODE_ENV = 'production';
43
46
  env.EE_HOME = options.homeDir;
44
47
  env.EE_SERVER_ENV = options.env;
@@ -47,7 +50,7 @@ class Appliaction extends EeApp {
47
50
  env.EE_APP_DATA = options.appData;
48
51
  env.EE_APP_USER_DATA = options.appUserData;
49
52
  env.EE_WEB_PORT = null;
50
- env.EE_IPC_PORT = null;
53
+ env.EE_SOCKET_PORT = null;
51
54
  env.EGG_SERVER_ENV = options.env;
52
55
  debug('options:%j', options)
53
56
 
package/lib/baseApp.js CHANGED
@@ -111,38 +111,26 @@ class BaseApp extends EeAppCore {
111
111
  /**
112
112
  * 调用 egg api
113
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
- /**
136
- * @class socket模块
137
- * @since 1.0.0
138
- */
139
- get socket () {
140
- const obj = {
141
- ipc: {},
142
- server: {}
143
- }
144
- return obj;
145
- }
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
+ // }
146
134
 
147
135
  /**
148
136
  * core app have been loaded
package/lib/constant.js CHANGED
@@ -23,8 +23,7 @@ module.exports = {
23
23
  },
24
24
  socketIo: {
25
25
  channel: {
26
- eggIoEe: 'c1',
27
- eggIoFrotend: 'c2'
26
+ partySoftware: 'c1',
28
27
  }
29
28
  }
30
29
  };
package/lib/eeApp.js CHANGED
@@ -20,16 +20,17 @@ class EeApp extends BaseApp {
20
20
  * 生成端口
21
21
  */
22
22
  async createPorts () {
23
- const ipcPort = await getPort();
24
- const webPort = this.config.env === 'prod' ? await getPort() : this.config.webServer.port;
25
- this.config.webServer.port = webPort;
26
- process.env.EE_IPC_PORT = ipcPort;
23
+ const socketPort = await getPort({port: this.config.socketServer.port});
24
+ //const webPort = this.config.env === 'prod' ? await getPort() : this.config.webServer.port;
25
+ const webPort = await getPort();
26
+
27
+ process.env.EE_SOCKET_PORT = socketPort;
27
28
  process.env.EE_WEB_PORT = webPort;
28
- this.coreLogger.info('[ee-core:EeApp] [createPorts] ipc port:', ipcPort);
29
+ this.coreLogger.info('[ee-core:EeApp] [createPorts] socket port:', socketPort);
29
30
  this.coreLogger.info('[ee-core:EeApp] [createPorts] web port:', webPort);
30
31
 
31
32
  // 更新db配置
32
- this.getCoreDB().setItem('ipc_port', ipcPort);
33
+ this.config.socketServer.port = socketPort;
33
34
  this.getCoreDB().setItem('config', this.config);
34
35
  }
35
36
 
@@ -78,6 +79,9 @@ class EeApp extends BaseApp {
78
79
  * 创建应用主窗口
79
80
  */
80
81
  async createWindow () {
82
+
83
+ await this.electronAppReady();
84
+
81
85
  const winOptions = this.config.windowsOption;
82
86
  this.electron.mainWindow = new BrowserWindow(winOptions);
83
87
 
@@ -86,15 +90,13 @@ class EeApp extends BaseApp {
86
90
  Menu.setApplicationMenu(null);
87
91
  }
88
92
 
89
- this.loadRemoreWeb();
90
-
91
93
  this.loadingView(winOptions);
92
94
 
93
95
  await this.windowReady();
94
96
 
95
97
  await this.loderPreload();
96
98
 
97
- this.loadLocalWeb();
99
+ this.selectAppType();
98
100
 
99
101
  // DevTools
100
102
  if (!app.isPackaged && this.config.openDevTools) {
@@ -102,38 +104,6 @@ class EeApp extends BaseApp {
102
104
  }
103
105
  }
104
106
 
105
- /**
106
- * 加载远程网址
107
- */
108
- loadRemoreWeb () {
109
- const remoteConfig = this.config.remoteUrl;
110
- if (remoteConfig.enable) {
111
- this.loadMainUrl('remote_web', remoteConfig.url);
112
- }
113
- }
114
-
115
- /**
116
- * 加载本地前端资源
117
- */
118
- loadLocalWeb () {
119
- // 如果加载了远程,则不能加载本地的
120
- const remoteConfig = this.config.remoteUrl;
121
- if (remoteConfig.enable) {
122
- return;
123
- }
124
-
125
- const self = this;
126
- const staticDir = path.join(this.config.homeDir, 'public', 'dist');
127
-
128
- const koaApp = new Koa();
129
- koaApp.use(koaServe(staticDir))
130
- const port = process.env.EE_WEB_PORT;
131
- koaApp.listen(port, () => {
132
- const url = 'http://127.0.0.1:' + port;
133
- self.loadMainUrl('local_web', url);
134
- });
135
- }
136
-
137
107
  /**
138
108
  * 加载已经实现的功能
139
109
  */
@@ -142,43 +112,10 @@ class EeApp extends BaseApp {
142
112
  return await preferences(this);
143
113
  }
144
114
 
145
- /**
146
- * 创建egg服务
147
- */
148
- // async startEggServer () {
149
- // // egg服务是否开启
150
- // if (this.config.egg.enable == false) {
151
- // return;
152
- // }
153
- // let eggConfig = this.config.egg;
154
- // const protocol = 'http://';
155
- // let startRes = null;
156
- // let url = protocol + eggConfig.hostname + ':' + eggConfig.port;
157
-
158
- // startRes = await this.startEgg(eggConfig).then((res) => res, (err) => err);
159
- // this.coreLogger.info('[ee-core:EeApp] [startEggServer] startRes:', startRes)
160
- // if (startRes === 'success') {
161
- // // 如果加载远程网址,则不能重复load
162
- // const remoteConfig = this.config.remoteUrl;
163
- // if (remoteConfig.enable) {
164
- // return;
165
- // }
166
- // this.loadMainUrl('egg', url);
167
- // } else {
168
- // // 失败后重启
169
- // app.relaunch();
170
- // }
171
- // }
172
-
173
115
  /**
174
116
  * 加载loading页面
175
117
  */
176
118
  loadingView (winOptions) {
177
- const remoteConfig = this.config.remoteUrl;
178
- if (remoteConfig.enable) {
179
- return;
180
- }
181
-
182
119
  if (!this.config.loadingPage) {
183
120
  return;
184
121
  }
@@ -204,55 +141,75 @@ class EeApp extends BaseApp {
204
141
  }
205
142
 
206
143
  /**
207
- * 加载主页面
144
+ * 应用类型 (远程、html、单页应用)
208
145
  */
209
- loadMainUrl (type, url) {
146
+ selectAppType () {
147
+ let type = '';
148
+ let url = '';
210
149
 
211
- // 环境模式 (远程模式,不加载dev)
150
+ // 远程模式
212
151
  const remoteConfig = this.config.remoteUrl;
213
- if (this.config.env !== 'prod' && remoteConfig.enable == false) {
214
- const protocol = 'http://';
215
- const developmentModeConfig = this.config.developmentMode;
216
- const selectMode = developmentModeConfig.default;
217
- const modeInfo = developmentModeConfig.mode[selectMode];
218
- url = protocol + modeInfo.hostname + ':' + modeInfo.port;
219
-
220
- this.coreLogger.info('[ee-core:EeApp] frontend server :', url)
152
+ if (remoteConfig.enable == true) {
153
+ type = 'remote_web';
154
+ url = remoteConfig.url;
155
+ this.loadMainUrl(type, url);
156
+ return;
221
157
  }
222
158
 
223
- this.logger.info('main page is env: %s, type: %s, url: %s', this.config.env, type, url);
224
- this.electron.mainWindow.loadURL(url);
159
+ const protocol = 'http://';
160
+ const developmentModeConfig = this.config.developmentMode;
161
+ const selectMode = developmentModeConfig.default;
162
+ const modeInfo = developmentModeConfig.mode[selectMode];
163
+ let staticDir = null;
164
+
165
+ // html模式
166
+ if (selectMode == 'html') {
167
+ if (this.config.env !== 'prod') {
168
+ staticDir = path.join(this.config.homeDir, 'frontend', 'dist');
169
+ }
170
+ this.loadLocalWeb('html', staticDir, modeInfo);
171
+ return;
172
+ }
173
+
174
+ // 单页应用
175
+ url = protocol + modeInfo.hostname + ':' + modeInfo.port;
176
+ if (this.config.env !== 'prod') {
177
+ this.loadMainUrl('spa', url);
178
+ } else {
179
+ this.loadLocalWeb('spa');
180
+ }
225
181
  }
226
182
 
227
183
  /**
228
- * egg
184
+ * 加载本地前端资源
229
185
  */
230
- // startEgg (argv) {
231
-
232
- // let homeDir = this.homeDir;
233
- // argv.baseDir = homeDir;
234
- // argv.framework = path.join(homeDir, 'node_modules', 'egg');
235
-
236
- // const appName = this.config.name;
237
- // argv.title = argv.title || `egg-server-${appName}`;
186
+ loadLocalWeb (mode, staticDir, hostInfo) {
187
+ const self = this;
188
+ if (!staticDir) {
189
+ staticDir = path.join(this.config.homeDir, 'public', 'dist')
190
+ }
238
191
 
192
+ const koaApp = new Koa();
193
+ koaApp.use(koaServe(staticDir))
194
+ const port = process.env.EE_WEB_PORT;
195
+ let url = 'http://127.0.0.1:' + port;
196
+ if (mode == 'html') {
197
+ url += '/' + hostInfo.indexPage;
198
+ }
239
199
 
240
- // // normalize env
241
- // // 目前没有用到,不用修改;想要修改的话,区分打包前后的路径?
242
- // // env.HOME = HOME; // 这个home不能修改,因为自动升级功能会用到(win没有问题,mac有权限问题)
243
- // //env.NODE_ENV = 'production';
200
+ koaApp.listen(port, () => {
201
+ self.loadMainUrl(mode, url);
202
+ });
203
+ }
244
204
 
245
- // // 更新缓存配置
246
- // this.getCoreDB().setItem('config', this.config);
205
+ /**
206
+ * 主页面
207
+ */
208
+ loadMainUrl (type, url) {
209
+ this.logger.info('main page is env: %s, type: %s, url: %s', this.config.env, type, url);
210
+ this.electron.mainWindow.loadURL(url);
211
+ }
247
212
 
248
- // const ignoreKeys = [ '_', '$0', 'env', 'daemon', 'stdout', 'stderr', 'timeout', 'ignore-stderr', 'node' ];
249
- // const clusterOptions = this.stringify(argv, ignoreKeys);
250
- // const options = JSON.parse(clusterOptions);
251
- // this.coreLogger.info('[ee-core:EeApp] [startEgg] options', options);
252
- // if (is.function(this.startEggCluster)) {
253
- // return this.startEggCluster(options);
254
- // }
255
- // }
256
213
 
257
214
  /**
258
215
  * 限制一个窗口
@@ -269,7 +226,17 @@ class EeApp extends BaseApp {
269
226
  */
270
227
  async appQuit () {
271
228
  await this.beforeClose();
229
+
230
+ // 窗口销毁
272
231
  this.electron.mainWindow.destroy();
232
+
233
+ //console.log('Exit now!');
234
+ // 托盘销毁
235
+ // if (this.electron.tray) {
236
+ // console.log('ssssssssssss');
237
+ // this.electron.tray.destroy();
238
+ // }
239
+
273
240
  app.quit();
274
241
  }
275
242
 
@@ -308,6 +275,20 @@ class EeApp extends BaseApp {
308
275
  process.on('uncaughtException', function(err) {
309
276
  self.logger.error(err);
310
277
  });
278
+
279
+ // process.on('SIGINT', function () {
280
+ // console.log('Exit now!');
281
+ // self.appQuit();
282
+ // process.exit();
283
+ // });
284
+ }
285
+
286
+ /**
287
+ * electron app已经准备好,主窗口还未创建
288
+ */
289
+ async electronAppReady () {
290
+ // do some things
291
+
311
292
  }
312
293
 
313
294
  /**
@@ -8,7 +8,7 @@ const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
8
8
  class SocketClient {
9
9
  constructor (port) {
10
10
  this.consoleLogger = new EggConsoleLogger();
11
- port = port ? port : this.getIpcPort();
11
+ port = port ? parseInt(port) : this.getSocketcPort();
12
12
 
13
13
  assert(typeof port === 'number', 'port required, and must be a number');
14
14
  this.consoleLogger.info('[ee-core:socket:client] start client');
@@ -29,7 +29,7 @@ class SocketClient {
29
29
  call (method = '', ...params) {
30
30
  return new Promise((resolve, reject) => {
31
31
  // 获取通信频道
32
- const channel = constant.socketIo.channel.eggIoEe;
32
+ const channel = constant.socketIo.channel.partySoftware;
33
33
  this.client.emit(channel, { cmd: method, params: params }, (response) => {
34
34
  resolve(response);
35
35
  });
@@ -41,10 +41,10 @@ class SocketClient {
41
41
  return coreDB;
42
42
  }
43
43
 
44
- getIpcPort () {
44
+ getSocketcPort () {
45
45
  const cdb = this.getCoreDB();
46
- const port = cdb.getItem('ipc_port');
47
- return port;
46
+ const port = cdb.getItem('config').socketServer.port;
47
+ return parseInt(port);
48
48
  }
49
49
  }
50
50
 
@@ -11,7 +11,7 @@ const is = require('is-type-of');
11
11
  */
12
12
  class SocketServer {
13
13
  constructor (app) {
14
- let port = process.env.EE_IPC_PORT ? parseInt(process.env.EE_IPC_PORT) : parseInt(this.getIpcPort());
14
+ let port = process.env.EE_SOCKET_PORT ? parseInt(process.env.EE_SOCKET_PORT) : parseInt(this.getSocketcPort());
15
15
 
16
16
  assert(typeof port === 'number', 'port required, and must be a number');
17
17
 
@@ -23,11 +23,12 @@ class SocketServer {
23
23
  }
24
24
 
25
25
  connec () {
26
+ const self = this;
26
27
  this.consoleLogger.info('[ee-core:socket:server] connection .....');
27
28
  this.io.on('connection', (socket) => {
28
- const channel = constant.socketIo.channel.eggIoEe;
29
+ const channel = constant.socketIo.channel.partySoftware;
29
30
  socket.on(channel, async (message, callback) => {
30
- this.consoleLogger.info('[ee-core:socket:server] socket id:' + socket.id + ' message cmd: ' + message.cmd);
31
+ self.consoleLogger.info('[ee-core:socket:server] socket id:' + socket.id + ' message cmd: ' + message.cmd);
31
32
 
32
33
  try {
33
34
  // 找函数
@@ -36,7 +37,7 @@ class SocketServer {
36
37
  let fn = null;
37
38
  if (is.string(cmd)) {
38
39
  const actions = cmd.split('.');
39
- let obj = this.app;
40
+ let obj = self.app;
40
41
  actions.forEach(key => {
41
42
  obj = obj[key];
42
43
  if (!obj) throw new Error(`class or function '${key}' not exists`);
@@ -45,12 +46,11 @@ class SocketServer {
45
46
  }
46
47
  if (!fn) throw new Error('function not exists');
47
48
 
48
- const result = await fn.call(this.app, args);
49
+ const result = await fn.call(self.app, args);
49
50
  callback(result);
50
51
  } catch (err) {
51
- this.app.logger.error('[ee:socket] throw error:', err);
52
+ self.app.logger.error('[ee:socket] throw error:', err);
52
53
  }
53
-
54
54
  });
55
55
  });
56
56
  }
@@ -60,9 +60,9 @@ class SocketServer {
60
60
  return coreDB;
61
61
  }
62
62
 
63
- getIpcPort () {
63
+ getSocketcPort () {
64
64
  const cdb = this.getCoreDB();
65
- const port = cdb.getItem('ipc_port');
65
+ const port = cdb.getItem('config').socketServer.port;
66
66
  return port;
67
67
  }
68
68
  }
@@ -11,7 +11,7 @@ const ipcServer = require('./ipcServer');
11
11
  // 启动 socket server
12
12
  new socketServer(app);
13
13
 
14
- // 启动 ipc server
14
+ // 启动 electron ipc server
15
15
  new ipcServer(app);
16
16
 
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.1.5",
3
+ "version": "1.1.8",
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",
@@ -47,6 +47,11 @@ const fsPro = require('fs-extra');
47
47
 
48
48
  // 复制到ee资源目录
49
49
  const eeResourceDir = path.join(homeDir, 'public', 'dist');
50
+
51
+ // 清空历史资源
52
+ fs.rmdirSync(eeResourceDir, {recursive: true});
53
+ console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
54
+
50
55
  fsPro.copySync(sourceDir, eeResourceDir);
51
56
  console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
52
57
 
package/utils/index.js CHANGED
@@ -6,6 +6,7 @@ const constant = require('../lib/constant');
6
6
  const convert = require('koa-convert');
7
7
  const is = require('is-type-of');
8
8
  const co = require('co');
9
+ const utility = require('utility');
9
10
 
10
11
  exports.mkdir = function(dirpath, dirname) {
11
12
  // 判断是否是第一次调用
@@ -52,8 +53,7 @@ exports.chmodPath = function(path, mode) {
52
53
  exports.getPackage = function() {
53
54
  const cdb = this.getCoreDB();
54
55
  const config = cdb.getItem('config');
55
- const filePath = path.join(config.homeDir, 'package.json');
56
- const json = require(filePath);
56
+ const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
57
57
 
58
58
  return json;
59
59
  };
@@ -118,16 +118,16 @@ exports.getLogDir = function() {
118
118
  /**
119
119
  * 获取 socketio port
120
120
  */
121
- exports.getIpcPort = function() {
121
+ exports.getSocketPort = function() {
122
122
  const cdb = this.getCoreDB();
123
- const port = cdb.getItem('ipc_port');
124
- return port;
123
+ const port = cdb.getItem('config').socketServer.port;
124
+ return parseInt(port);
125
125
  }
126
126
 
127
127
  /**
128
- * 获取 ipc channel
128
+ * 获取 socket channel
129
129
  */
130
- exports.getIpcChannel = function() {
130
+ exports.getSocketChannel = function() {
131
131
  return constant.socketIo.channel;
132
132
  }
133
133