ee-core 1.1.3 → 1.1.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.
@@ -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,5 +191,11 @@ module.exports = appInfo => {
175
191
  },
176
192
  };
177
193
 
194
+ /* 内置socket服务 */
195
+ config.socketServer = {
196
+ port: 7070, // 默认端口
197
+ isDynamic: false // 如果值为false,框架默认使用port端口(如果默认端口被使用,则随机获取一个);如果为true,默认端口无效,框架随机生成
198
+ };
199
+
178
200
  return config;
179
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;
@@ -46,8 +49,8 @@ class Appliaction extends EeApp {
46
49
  env.EE_USER_HOME = options.userHome;
47
50
  env.EE_APP_DATA = options.appData;
48
51
  env.EE_APP_USER_DATA = options.appUserData;
49
- env.EE_EGG_PORT = null;
50
- env.EE_IPC_PORT = null;
52
+ env.EE_WEB_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 eggPort = this.config.env === 'prod' ? await getPort() : this.config.egg.port;
25
- this.config.egg.port = eggPort;
26
- process.env.EE_IPC_PORT = ipcPort;
27
- process.env.EE_EGG_PORT = eggPort;
28
- this.coreLogger.info('[ee-core:EeApp] [createPorts] ipc port:', ipcPort);
29
- this.coreLogger.info('[ee-core:EeApp] [createPorts] egg port:', eggPort);
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;
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);
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
 
@@ -86,17 +87,13 @@ class EeApp extends BaseApp {
86
87
  Menu.setApplicationMenu(null);
87
88
  }
88
89
 
89
- this.loadRemoreWeb();
90
-
91
90
  this.loadingView(winOptions);
92
91
 
93
92
  await this.windowReady();
94
93
 
95
94
  await this.loderPreload();
96
95
 
97
- this.loadLocalWeb();
98
-
99
- await this.startEggServer();
96
+ this.selectAppType();
100
97
 
101
98
  // DevTools
102
99
  if (!app.isPackaged && this.config.openDevTools) {
@@ -104,42 +101,6 @@ class EeApp extends BaseApp {
104
101
  }
105
102
  }
106
103
 
107
- /**
108
- * 加载远程网址
109
- */
110
- loadRemoreWeb () {
111
- const remoteConfig = this.config.remoteUrl;
112
- if (remoteConfig.enable) {
113
- this.loadMainUrl('remote_web', remoteConfig.url);
114
- }
115
- }
116
-
117
- /**
118
- * 加载本地前端资源
119
- */
120
- loadLocalWeb () {
121
- // 如果加载了远程,则不能加载本地的
122
- const remoteConfig = this.config.remoteUrl;
123
- if (remoteConfig.enable) {
124
- return;
125
- }
126
-
127
- // 如果egg服务开启,则不能加载本地的
128
- if (this.config.egg.enable == true) {
129
- return;
130
- }
131
- const self = this;
132
- const staticDir = path.join(this.config.homeDir, 'public', 'dist');
133
-
134
- const koaApp = new Koa();
135
- koaApp.use(koaServe(staticDir))
136
- const port = process.env.EE_EGG_PORT;
137
- koaApp.listen(port, () => {
138
- const url = 'http://127.0.0.1:' + port;
139
- self.loadMainUrl('local_web', url);
140
- });
141
- }
142
-
143
104
  /**
144
105
  * 加载已经实现的功能
145
106
  */
@@ -151,40 +112,35 @@ class EeApp extends BaseApp {
151
112
  /**
152
113
  * 创建egg服务
153
114
  */
154
- async startEggServer () {
155
- // egg服务是否开启
156
- if (this.config.egg.enable == false) {
157
- return;
158
- }
159
- let eggConfig = this.config.egg;
160
- const protocol = 'http://';
161
- let startRes = null;
162
- let url = protocol + eggConfig.hostname + ':' + eggConfig.port;
163
-
164
- startRes = await this.startEgg(eggConfig).then((res) => res, (err) => err);
165
- this.coreLogger.info('[ee-core:EeApp] [startEggServer] startRes:', startRes)
166
- if (startRes === 'success') {
167
- // 如果加载远程网址,则不能重复load
168
- const remoteConfig = this.config.remoteUrl;
169
- if (remoteConfig.enable) {
170
- return;
171
- }
172
- this.loadMainUrl('egg', url);
173
- } else {
174
- // 失败后重启
175
- app.relaunch();
176
- }
177
- }
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
+ // }
178
139
 
179
140
  /**
180
141
  * 加载loading页面
181
142
  */
182
143
  loadingView (winOptions) {
183
- const remoteConfig = this.config.remoteUrl;
184
- if (remoteConfig.enable) {
185
- return;
186
- }
187
-
188
144
  if (!this.config.loadingPage) {
189
145
  return;
190
146
  }
@@ -210,55 +166,104 @@ class EeApp extends BaseApp {
210
166
  }
211
167
 
212
168
  /**
213
- * 加载主页面
169
+ * 应用类型 (远程、html、单页应用)
214
170
  */
215
- loadMainUrl (type, url) {
171
+ selectAppType () {
172
+ let type = '';
173
+ let url = '';
216
174
 
217
- // 环境模式 (远程模式,不加载dev)
175
+ // 远程模式
218
176
  const remoteConfig = this.config.remoteUrl;
219
- if (this.config.env !== 'prod' && remoteConfig.enable == false) {
220
- const protocol = 'http://';
221
- const developmentModeConfig = this.config.developmentMode;
222
- const selectMode = developmentModeConfig.default;
223
- const modeInfo = developmentModeConfig.mode[selectMode];
224
- url = protocol + modeInfo.hostname + ':' + modeInfo.port;
225
-
226
- this.coreLogger.info('[ee-core:EeApp] frontend server :', url)
177
+ if (remoteConfig.enable == true) {
178
+ type = 'remote_web';
179
+ url = remoteConfig.url;
180
+ this.loadMainUrl(type, url);
181
+ return;
182
+ }
183
+
184
+ const protocol = 'http://';
185
+ const developmentModeConfig = this.config.developmentMode;
186
+ const selectMode = developmentModeConfig.default;
187
+ const modeInfo = developmentModeConfig.mode[selectMode];
188
+ let staticDir = null;
189
+
190
+ // html模式
191
+ if (selectMode == 'html') {
192
+ if (this.config.env !== 'prod') {
193
+ staticDir = path.join(this.config.homeDir, 'frontend', 'dist');
194
+ }
195
+ this.loadLocalWeb('html', staticDir, modeInfo);
196
+ return;
197
+ }
198
+
199
+ // 单页应用
200
+ url = protocol + modeInfo.hostname + ':' + modeInfo.port;
201
+ if (this.config.env !== 'prod') {
202
+ this.loadMainUrl('spa', url);
203
+ } else {
204
+ this.loadLocalWeb('spa');
205
+ }
206
+ }
207
+
208
+ /**
209
+ * 加载本地前端资源
210
+ */
211
+ loadLocalWeb (mode, staticDir, hostInfo) {
212
+ const self = this;
213
+ if (!staticDir) {
214
+ staticDir = path.join(this.config.homeDir, 'public', 'dist')
215
+ }
216
+
217
+ const koaApp = new Koa();
218
+ koaApp.use(koaServe(staticDir))
219
+ const port = process.env.EE_WEB_PORT;
220
+ let url = 'http://127.0.0.1:' + port;
221
+ if (mode == 'html') {
222
+ url += '/' + hostInfo.indexPage;
227
223
  }
228
224
 
225
+ koaApp.listen(port, () => {
226
+ self.loadMainUrl(mode, url);
227
+ });
228
+ }
229
+
230
+ /**
231
+ * 主页面
232
+ */
233
+ loadMainUrl (type, url) {
229
234
  this.logger.info('main page is env: %s, type: %s, url: %s', this.config.env, type, url);
230
235
  this.electron.mainWindow.loadURL(url);
231
- }
236
+ }
232
237
 
233
238
  /**
234
239
  * egg
235
240
  */
236
- startEgg (argv) {
241
+ // startEgg (argv) {
237
242
 
238
- let homeDir = this.homeDir;
239
- argv.baseDir = homeDir;
240
- argv.framework = path.join(homeDir, 'node_modules', 'egg');
243
+ // let homeDir = this.homeDir;
244
+ // argv.baseDir = homeDir;
245
+ // argv.framework = path.join(homeDir, 'node_modules', 'egg');
241
246
 
242
- const appName = this.config.name;
243
- argv.title = argv.title || `egg-server-${appName}`;
247
+ // const appName = this.config.name;
248
+ // argv.title = argv.title || `egg-server-${appName}`;
244
249
 
245
250
 
246
- // normalize env
247
- // 目前没有用到,不用修改;想要修改的话,区分打包前后的路径?
248
- // env.HOME = HOME; // 这个home不能修改,因为自动升级功能会用到(win没有问题,mac有权限问题)
249
- //env.NODE_ENV = 'production';
251
+ // // normalize env
252
+ // // 目前没有用到,不用修改;想要修改的话,区分打包前后的路径?
253
+ // // env.HOME = HOME; // 这个home不能修改,因为自动升级功能会用到(win没有问题,mac有权限问题)
254
+ // //env.NODE_ENV = 'production';
250
255
 
251
- // 更新缓存配置
252
- this.getCoreDB().setItem('config', this.config);
256
+ // // 更新缓存配置
257
+ // this.getCoreDB().setItem('config', this.config);
253
258
 
254
- const ignoreKeys = [ '_', '$0', 'env', 'daemon', 'stdout', 'stderr', 'timeout', 'ignore-stderr', 'node' ];
255
- const clusterOptions = this.stringify(argv, ignoreKeys);
256
- const options = JSON.parse(clusterOptions);
257
- this.coreLogger.info('[ee-core:EeApp] [startEgg] options', options);
258
- if (is.function(this.startEggCluster)) {
259
- return this.startEggCluster(options);
260
- }
261
- }
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
+ // }
262
267
 
263
268
  /**
264
269
  * 限制一个窗口
@@ -275,7 +280,17 @@ class EeApp extends BaseApp {
275
280
  */
276
281
  async appQuit () {
277
282
  await this.beforeClose();
283
+
284
+ // 窗口销毁
278
285
  this.electron.mainWindow.destroy();
286
+
287
+ //console.log('Exit now!');
288
+ // 托盘销毁
289
+ // if (this.electron.tray) {
290
+ // console.log('ssssssssssss');
291
+ // this.electron.tray.destroy();
292
+ // }
293
+
279
294
  app.quit();
280
295
  }
281
296
 
@@ -314,6 +329,12 @@ class EeApp extends BaseApp {
314
329
  process.on('uncaughtException', function(err) {
315
330
  self.logger.error(err);
316
331
  });
332
+
333
+ // process.on('SIGINT', function () {
334
+ // console.log('Exit now!');
335
+ // self.appQuit();
336
+ // process.exit();
337
+ // });
317
338
  }
318
339
 
319
340
  /**
@@ -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.3",
3
+ "version": "1.1.6",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  "egg-logger": "^2.7.1",
18
18
  "electron-is": "^3.0.0",
19
19
  "electron-updater": "^4.6.1",
20
+ "extend2": "^1.0.1",
20
21
  "fs-extra": "^10.0.0",
21
22
  "get-port": "^5.1.1",
22
23
  "globby": "^10.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