ee-core 1.5.2-beta.2 → 2.0.0-beta.2
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 +8 -1
- package/core/lib/ee.js +1 -1
- package/core/lib/loader/ee_loader.js +23 -45
- package/core/lib/loader/mixin/config.js +6 -11
- package/core/lib/loader/mixin/controller.js +3 -2
- package/core/lib/utils/function.js +30 -0
- package/core/lib/utils/index.js +6 -0
- package/index.js +2 -2
- package/lib/appLoader.js +0 -5
- package/lib/application.js +12 -9
- package/lib/baseApp.js +9 -26
- package/lib/eeApp.js +18 -52
- package/{lib/constant.js → module/const/index.js} +3 -0
- package/module/exception/index.js +16 -0
- package/{lib/httpclient.js → module/httpclient/index.js} +45 -11
- package/module/jobs/child/app.js +23 -0
- package/module/jobs/child/forkProcess.js +104 -0
- package/module/jobs/child/index.js +35 -0
- package/module/jobs/index.js +56 -0
- package/module/jobs/renderer/index.js +140 -0
- package/module/jobs/renderer/loadView.js +40 -0
- package/module/loader/index.js +130 -0
- package/module/log/index.js +53 -0
- package/module/log/logger.js +61 -0
- package/module/message/index.js +13 -0
- package/module/message/ipcMain.js +160 -0
- package/module/message/ipcRender.js +0 -0
- package/{lib → module}/socket/ipcServer.js +6 -8
- package/{lib → module}/socket/socketClient.js +4 -3
- package/{lib → module}/socket/socketServer.js +4 -3
- package/module/socket/start.js +22 -0
- package/{lib → module}/storage/index.js +16 -13
- package/module/storage/jsondb/adapters/Base.js +14 -0
- package/module/storage/jsondb/adapters/FileSync.js +32 -0
- package/{lib/storage/lowdb → module/storage/jsondb}/main.js +6 -10
- package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +12 -14
- package/{lib → module}/storage/sqliteStorage.js +7 -11
- package/module/utils/copyto.js +161 -0
- package/module/utils/helper.js +117 -0
- package/module/utils/index.js +120 -0
- package/module/utils/json.js +72 -0
- package/module/utils/ps.js +196 -0
- package/{utils → module/utils}/wrap.js +0 -2
- package/package.json +3 -7
- package/tools/encrypt.js +2 -2
- package/utils/index.js +17 -135
- package/lib/logger.js +0 -47
- package/lib/socket/start.js +0 -22
- package/lib/storage/lowdb/adapters/Base.js +0 -15
- package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
- package/lib/storage/lowdb/adapters/FileSync.js +0 -39
- package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
- package/lib/storage/lowdb/adapters/Memory.js +0 -8
- package/lib/storage/lowdb/adapters/_stringify.js +0 -4
- package/lib/storage/lowdb/common.js +0 -33
- package/lib/storage/lowdb/fp.js +0 -23
- package/lib/storage/lowdb/isPromise.js +0 -6
- package/lib/storage/lowdb/nano.js +0 -5
- package/utils/common.js +0 -91
- /package/{lib → module}/socket/httpServer.js +0 -0
- /package/{lib → module}/socket/io.js +0 -0
package/config/config.default.js
CHANGED
|
@@ -134,6 +134,7 @@ module.exports = appInfo => {
|
|
|
134
134
|
* @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
|
|
135
135
|
*/
|
|
136
136
|
config.logger = {
|
|
137
|
+
type: 'application',
|
|
137
138
|
dir: path.join(appInfo.root, 'logs'),
|
|
138
139
|
encoding: 'utf8',
|
|
139
140
|
env: appInfo.env,
|
|
@@ -151,6 +152,13 @@ module.exports = appInfo => {
|
|
|
151
152
|
enablePerformanceTimer: false,
|
|
152
153
|
};
|
|
153
154
|
|
|
155
|
+
/**
|
|
156
|
+
* customLogger options
|
|
157
|
+
* @member Config#customLogger
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
config.customLogger = {}
|
|
161
|
+
|
|
154
162
|
/**
|
|
155
163
|
* The option for httpclient
|
|
156
164
|
* @member Config#httpclient
|
|
@@ -173,7 +181,6 @@ module.exports = appInfo => {
|
|
|
173
181
|
enableDNSCache: false,
|
|
174
182
|
dnsCacheLookupInterval: 10000,
|
|
175
183
|
dnsCacheMaxLength: 1000,
|
|
176
|
-
|
|
177
184
|
request: {
|
|
178
185
|
timeout: 5000,
|
|
179
186
|
},
|
package/core/lib/ee.js
CHANGED
|
@@ -7,9 +7,9 @@ const is = require('is-type-of');
|
|
|
7
7
|
const debug = require('debug')('ee-core:EeLoader');
|
|
8
8
|
const FileLoader = require('./file_loader');
|
|
9
9
|
const ContextLoader = require('./context_loader');
|
|
10
|
-
const utility = require('utility');
|
|
11
10
|
const utils = require('../utils');
|
|
12
11
|
const Timing = require('../utils/timing');
|
|
12
|
+
const Ps = require('../../../module/utils/ps');
|
|
13
13
|
|
|
14
14
|
const REQUIRE_COUNT = Symbol('EeLoader#requireCount');
|
|
15
15
|
|
|
@@ -83,25 +83,8 @@ class EeLoader {
|
|
|
83
83
|
getServerEnv() {
|
|
84
84
|
let serverEnv = this.options.env;
|
|
85
85
|
|
|
86
|
-
const envPath = path.join(this.options.baseDir, 'config/env');
|
|
87
|
-
if (!serverEnv && fs.existsSync(envPath)) {
|
|
88
|
-
serverEnv = fs.readFileSync(envPath, 'utf8').trim();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
86
|
if (!serverEnv) {
|
|
92
|
-
serverEnv
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!serverEnv) {
|
|
96
|
-
if (process.env.NODE_ENV === 'test') {
|
|
97
|
-
serverEnv = 'unittest';
|
|
98
|
-
} else if (process.env.NODE_ENV === 'production') {
|
|
99
|
-
serverEnv = 'prod';
|
|
100
|
-
} else {
|
|
101
|
-
serverEnv = 'local';
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
serverEnv = serverEnv.trim();
|
|
87
|
+
throw new Error('[core] [lib] [loader] getServerEnv serverEnv can not be empty!');
|
|
105
88
|
}
|
|
106
89
|
|
|
107
90
|
return serverEnv;
|
|
@@ -199,7 +182,7 @@ class EeLoader {
|
|
|
199
182
|
* The directory whether is homeDir or appUserData depend on env.
|
|
200
183
|
* @member {String} AppInfo#root
|
|
201
184
|
*/
|
|
202
|
-
root:
|
|
185
|
+
root: Ps.getRootDir(),
|
|
203
186
|
|
|
204
187
|
/**
|
|
205
188
|
* electron application data dir
|
|
@@ -313,15 +296,6 @@ class EeLoader {
|
|
|
313
296
|
|
|
314
297
|
const dirs = this.dirs = [];
|
|
315
298
|
|
|
316
|
-
if (this.orderPlugins) {
|
|
317
|
-
for (const plugin of this.orderPlugins) {
|
|
318
|
-
dirs.push({
|
|
319
|
-
path: plugin.path,
|
|
320
|
-
type: 'plugin',
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
299
|
// framework or Ee path
|
|
326
300
|
for (const EePath of this.EePaths) {
|
|
327
301
|
dirs.push({
|
|
@@ -404,36 +378,40 @@ class EeLoader {
|
|
|
404
378
|
|
|
405
379
|
getTypeFiles(filename) {
|
|
406
380
|
const files = [ `${filename}.default` ];
|
|
407
|
-
if (this.serverScope) files.push(`${filename}.${this.serverScope}`);
|
|
408
|
-
if (this.serverEnv === 'default') return files;
|
|
409
|
-
|
|
410
381
|
files.push(`${filename}.${this.serverEnv}`);
|
|
411
|
-
|
|
382
|
+
|
|
412
383
|
return files;
|
|
413
384
|
}
|
|
414
385
|
|
|
415
386
|
resolveModule(filepath) {
|
|
416
|
-
let
|
|
387
|
+
let fullpath;
|
|
417
388
|
try {
|
|
418
|
-
|
|
389
|
+
fullpath = require.resolve(filepath);
|
|
419
390
|
} catch (e) {
|
|
420
|
-
let jscFile = filepath + '.jsc';
|
|
421
|
-
if (fs.existsSync(jscFile)) {
|
|
422
|
-
return jscFile;
|
|
423
|
-
}
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
391
|
|
|
427
|
-
|
|
428
|
-
|
|
392
|
+
// 特殊后缀处理
|
|
393
|
+
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
394
|
+
fullpath = filepath + '.jsc';
|
|
395
|
+
} else if (filepath && filepath.endsWith('.js')) {
|
|
396
|
+
fullpath = filepath + 'c';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
400
|
+
this.options.logger.warn(`[ee-core] [core/lib/loader/ee_loader] resolveModule unknow filepath: ${filepath}`)
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
429
403
|
}
|
|
430
404
|
|
|
431
|
-
return
|
|
405
|
+
return fullpath;
|
|
432
406
|
}
|
|
433
407
|
|
|
434
408
|
getPkg() {
|
|
435
409
|
const filePath = path.join(this.options.homeDir, 'package.json');
|
|
436
|
-
|
|
410
|
+
if (!fs.existsSync(filePath)) {
|
|
411
|
+
throw new Error(filePath + ' is not found');
|
|
412
|
+
}
|
|
413
|
+
const json = JSON.parse(fs.readFileSync(filePath));
|
|
414
|
+
|
|
437
415
|
return json;
|
|
438
416
|
}
|
|
439
417
|
}
|
|
@@ -24,14 +24,7 @@ module.exports = {
|
|
|
24
24
|
|
|
25
25
|
// Load Application config first
|
|
26
26
|
const appConfig = this._preloadAppConfig();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// plugin config.default
|
|
30
|
-
// framework config.default
|
|
31
|
-
// app config.default
|
|
32
|
-
// plugin config.{env}
|
|
33
|
-
// framework config.{env}
|
|
34
|
-
// app config.{env}
|
|
27
|
+
|
|
35
28
|
for (const filename of this.getTypeFiles('config')) {
|
|
36
29
|
for (const unit of this.getLoadUnits()) {
|
|
37
30
|
const isApp = unit.type === 'app';
|
|
@@ -64,6 +57,8 @@ module.exports = {
|
|
|
64
57
|
'config.default',
|
|
65
58
|
`config.${this.serverEnv}`,
|
|
66
59
|
];
|
|
60
|
+
|
|
61
|
+
|
|
67
62
|
const target = {};
|
|
68
63
|
for (const filename of names) {
|
|
69
64
|
const config = this._loadConfig(this.options.baseDir, filename, undefined, 'app');
|
|
@@ -78,9 +73,9 @@ module.exports = {
|
|
|
78
73
|
let filepath = this.resolveModule(path.join(dirpath, 'config', filename));
|
|
79
74
|
|
|
80
75
|
// let config.js compatible
|
|
81
|
-
if (filename === 'config.default' && !filepath) {
|
|
82
|
-
|
|
83
|
-
}
|
|
76
|
+
// if (filename === 'config.default' && !filepath) {
|
|
77
|
+
// filepath = this.resolveModule(path.join(dirpath, 'config/config'));
|
|
78
|
+
// }
|
|
84
79
|
|
|
85
80
|
const config = this.loadFile(filepath, this.appInfo, extraInject);
|
|
86
81
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const is = require('is-type-of');
|
|
5
|
-
const
|
|
5
|
+
const utilsFn = require('../../utils/function');
|
|
6
6
|
const utils = require('../../utils');
|
|
7
7
|
const FULLPATH = require('../file_loader').FULLPATH;
|
|
8
8
|
|
|
@@ -97,7 +97,7 @@ function wrapObject(obj, path, prefix) {
|
|
|
97
97
|
const ret = {};
|
|
98
98
|
for (const key of keys) {
|
|
99
99
|
if (is.function(obj[key])) {
|
|
100
|
-
const names =
|
|
100
|
+
const names = utilsFn.getParamNames(obj[key]);
|
|
101
101
|
if (names[0] === 'next') {
|
|
102
102
|
throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
|
|
103
103
|
}
|
|
@@ -122,3 +122,4 @@ function wrapObject(obj, path, prefix) {
|
|
|
122
122
|
return objectControllerMiddleware;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A empty function.
|
|
5
|
+
*
|
|
6
|
+
* @return {Function}
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
exports.noop = function noop() {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get a function parameter's names.
|
|
13
|
+
*
|
|
14
|
+
* @param {Function} func
|
|
15
|
+
* @param {Boolean} [useCache], default is true
|
|
16
|
+
* @return {Array} names
|
|
17
|
+
*/
|
|
18
|
+
exports.getParamNames = function getParamNames(func, cache) {
|
|
19
|
+
var type = typeof func;
|
|
20
|
+
assert(type === 'function', 'The "func" must be a function. Received type "' + type + '"');
|
|
21
|
+
|
|
22
|
+
cache = cache !== false;
|
|
23
|
+
if (cache && func.__cache_names) {
|
|
24
|
+
return func.__cache_names;
|
|
25
|
+
}
|
|
26
|
+
var str = func.toString();
|
|
27
|
+
var names = str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g) || [];
|
|
28
|
+
func.__cache_names = names;
|
|
29
|
+
return names;
|
|
30
|
+
};
|
package/core/lib/utils/index.js
CHANGED
|
@@ -14,6 +14,12 @@ const Module = module.constructor.length > 1
|
|
|
14
14
|
/* istanbul ignore next */
|
|
15
15
|
: BuiltinModule;
|
|
16
16
|
|
|
17
|
+
// Module._extensions:
|
|
18
|
+
// '.js': [Function (anonymous)],
|
|
19
|
+
// '.json': [Function (anonymous)],
|
|
20
|
+
// '.node': [Function: func],
|
|
21
|
+
// '.jsc': [Function (anonymous)]
|
|
22
|
+
|
|
17
23
|
module.exports = {
|
|
18
24
|
extensions: Module._extensions,
|
|
19
25
|
|
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const Service = require('./core/lib/utils/base_context_class');
|
|
|
26
26
|
* @member {Storage}
|
|
27
27
|
* @since 1.0.0
|
|
28
28
|
*/
|
|
29
|
-
const Storage = require('./
|
|
29
|
+
const Storage = require('./module/storage/index');
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* @member {Utils}
|
|
@@ -38,7 +38,7 @@ const Utils = require('./utils/index');
|
|
|
38
38
|
* @member {Socket}
|
|
39
39
|
* @since 1.0.0
|
|
40
40
|
*/
|
|
41
|
-
const Socket = require('./
|
|
41
|
+
const Socket = require('./module/socket/io');
|
|
42
42
|
|
|
43
43
|
module.exports = {
|
|
44
44
|
Appliaction,
|
package/lib/appLoader.js
CHANGED
package/lib/application.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const {app} = require('electron');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const EeApp = require('./eeApp');
|
|
4
3
|
const debug = require('debug')('ee-core:Appliaction');
|
|
5
4
|
const fs = require('fs');
|
|
5
|
+
const EeApp = require('./eeApp');
|
|
6
6
|
|
|
7
7
|
class Appliaction extends EeApp {
|
|
8
8
|
constructor() {
|
|
@@ -18,10 +18,10 @@ class Appliaction extends EeApp {
|
|
|
18
18
|
userHome: app.getPath('home'),
|
|
19
19
|
appData: app.getPath('appData'),
|
|
20
20
|
appUserData: app.getPath('userData'),
|
|
21
|
-
//logsDir: app.getPath('logs'),
|
|
22
21
|
appVersion: app.getVersion(),
|
|
23
22
|
isPackaged: app.isPackaged,
|
|
24
|
-
execDir: app.getAppPath()
|
|
23
|
+
execDir: app.getAppPath(),
|
|
24
|
+
isEncrypted: false
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// argv
|
|
@@ -43,25 +43,28 @@ class Appliaction extends EeApp {
|
|
|
43
43
|
|
|
44
44
|
// Use encryption, base directory is public/electron
|
|
45
45
|
const encryptDir = path.join(app.getAppPath(), 'public', 'electron');
|
|
46
|
-
|
|
47
|
-
if (options.env == 'prod' && isEncrypted) {
|
|
46
|
+
if (options.env == 'prod' && fs.existsSync(encryptDir)) {
|
|
48
47
|
options.baseDir = encryptDir;
|
|
48
|
+
options.isEncrypted = true;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// normalize env
|
|
52
|
-
env.NODE_ENV =
|
|
52
|
+
env.NODE_ENV = options.env;
|
|
53
53
|
env.EE_HOME = options.homeDir;
|
|
54
|
+
env.EE_BASE_DIR = options.baseDir;
|
|
54
55
|
env.EE_SERVER_ENV = options.env;
|
|
55
56
|
env.EE_SERVER_SCOPE = options.serverScope;
|
|
56
57
|
env.EE_USER_HOME = options.userHome;
|
|
57
58
|
env.EE_APP_DATA = options.appData;
|
|
58
59
|
env.EE_APP_USER_DATA = options.appUserData;
|
|
59
|
-
env.EE_MAIN_PORT = null;
|
|
60
|
-
env.EE_SOCKET_PORT = null;
|
|
61
|
-
env.EE_HTTP_PORT = null;
|
|
62
60
|
env.HOT_RELOAD = hotReload;
|
|
63
61
|
env.EE_EXEC_DIR = options.execDir;
|
|
62
|
+
env.EE_IS_PACKAGED = options.isPackaged;
|
|
63
|
+
env.EE_IS_ENCRYPTED = options.isEncrypted;
|
|
64
64
|
env.EE_DATABASE_DIR = null;
|
|
65
|
+
env.EE_MAIN_PORT = null;
|
|
66
|
+
env.EE_SOCKET_PORT = null;
|
|
67
|
+
env.EE_HTTP_PORT = null;
|
|
65
68
|
debug('options:%j', options)
|
|
66
69
|
|
|
67
70
|
super(options);
|
package/lib/baseApp.js
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const EeAppCore = require('../core/index').EeCore;
|
|
4
2
|
const EE_PATH = Symbol.for('ee#eePath');
|
|
5
3
|
const path = require('path');
|
|
6
4
|
const EE_LOADER = Symbol.for('ee#loader');
|
|
7
5
|
const AppLoader = require('./appLoader');
|
|
8
|
-
const
|
|
9
|
-
const ELoggers = require('./logger');
|
|
10
|
-
const HttpClient = require('./httpclient');
|
|
6
|
+
const HttpClient = require('../module/httpclient');
|
|
11
7
|
const HTTPCLIENT = Symbol('EeApplication#httpclient');
|
|
8
|
+
const LOGGERS = Symbol('EeApplication#loggers');
|
|
9
|
+
const Log = require('../module/log');
|
|
10
|
+
const Storage = require('../module/storage');
|
|
12
11
|
|
|
13
12
|
class BaseApp extends EeAppCore {
|
|
14
13
|
constructor (options = {}) {
|
|
15
14
|
|
|
16
15
|
super(options);
|
|
17
|
-
|
|
18
|
-
this.HttpClient = HttpClient;
|
|
19
16
|
|
|
20
17
|
this.loader.loadConfig();
|
|
21
18
|
|
|
22
|
-
// todo
|
|
23
|
-
//this.setDatabaseDir();
|
|
24
|
-
|
|
25
19
|
// 缓存配置
|
|
26
20
|
this.getCoreDB().setItem('config', this.config);
|
|
27
21
|
|
|
28
22
|
this.loader.load();
|
|
29
23
|
|
|
24
|
+
this.HttpClient = HttpClient;
|
|
25
|
+
|
|
30
26
|
// TODO 这个不行,要么每次new对象,要么所有地方都用同一个实例,否则会出现数据无法刷新的情况
|
|
31
27
|
//this.coreDB = this.getCoreDB();
|
|
32
|
-
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
get [EE_PATH]() {
|
|
@@ -47,7 +42,7 @@ class BaseApp extends EeAppCore {
|
|
|
47
42
|
*/
|
|
48
43
|
get loggers() {
|
|
49
44
|
if (!this[LOGGERS]) {
|
|
50
|
-
this[LOGGERS] =
|
|
45
|
+
this[LOGGERS] = Log.create(this.config);
|
|
51
46
|
}
|
|
52
47
|
return this[LOGGERS];
|
|
53
48
|
}
|
|
@@ -85,7 +80,7 @@ class BaseApp extends EeAppCore {
|
|
|
85
80
|
* @since 1.0.0
|
|
86
81
|
*/
|
|
87
82
|
getCoreDB () {
|
|
88
|
-
const db =
|
|
83
|
+
const db = Storage.connection('system');
|
|
89
84
|
return db;
|
|
90
85
|
}
|
|
91
86
|
|
|
@@ -104,23 +99,11 @@ class BaseApp extends EeAppCore {
|
|
|
104
99
|
*/
|
|
105
100
|
get httpclient() {
|
|
106
101
|
if (!this[HTTPCLIENT]) {
|
|
107
|
-
this[HTTPCLIENT] = new this.HttpClient(this);
|
|
102
|
+
this[HTTPCLIENT] = new this.HttpClient(this.config.httpclient);
|
|
108
103
|
}
|
|
109
104
|
return this[HTTPCLIENT];
|
|
110
105
|
}
|
|
111
106
|
|
|
112
|
-
/**
|
|
113
|
-
* todo 设置db存储目录
|
|
114
|
-
*/
|
|
115
|
-
setDatabaseDir (dirPath) {
|
|
116
|
-
if (dirPath) {
|
|
117
|
-
assert(typeof dirPath === 'string', ` ${dirPath} dirPath required, and must be a string`);
|
|
118
|
-
process.env.EE_DATABASE_DIR = dirPath;
|
|
119
|
-
} else {
|
|
120
|
-
process.env.EE_DATABASE_DIR = this.config.database.dir;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
107
|
/**
|
|
125
108
|
* core app have been loaded
|
|
126
109
|
*/
|
package/lib/eeApp.js
CHANGED
|
@@ -2,13 +2,13 @@ const path = require('path');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
const getPort = require('get-port');
|
|
5
|
-
const {app, BrowserWindow,
|
|
6
|
-
const BaseApp = require('./baseApp');
|
|
5
|
+
const {app, BrowserWindow, Menu, protocol} = require('electron');
|
|
7
6
|
const is = require('is-type-of');
|
|
8
7
|
const Koa = require('koa');
|
|
9
8
|
const koaServe = require('koa-static');
|
|
10
9
|
const https = require('https');
|
|
11
|
-
const
|
|
10
|
+
const BaseApp = require('./baseApp');
|
|
11
|
+
const Log = require('../module/log');
|
|
12
12
|
|
|
13
13
|
class EeApp extends BaseApp {
|
|
14
14
|
constructor(options = {}) {
|
|
@@ -51,7 +51,7 @@ class EeApp extends BaseApp {
|
|
|
51
51
|
* 启动通信模块
|
|
52
52
|
*/
|
|
53
53
|
async startSocket () {
|
|
54
|
-
const socket = require('
|
|
54
|
+
const socket = require('../module/socket/start');
|
|
55
55
|
socket(this);
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -80,7 +80,7 @@ class EeApp extends BaseApp {
|
|
|
80
80
|
|
|
81
81
|
app.on('window-all-closed', () => {
|
|
82
82
|
if (process.platform !== 'darwin') {
|
|
83
|
-
|
|
83
|
+
Log.coreLogger.info('[Appliaction] [initialize] window-all-closed quit');
|
|
84
84
|
self.appQuit();
|
|
85
85
|
}
|
|
86
86
|
})
|
|
@@ -100,6 +100,15 @@ class EeApp extends BaseApp {
|
|
|
100
100
|
* 创建应用主窗口
|
|
101
101
|
*/
|
|
102
102
|
async createWindow () {
|
|
103
|
+
|
|
104
|
+
// todo
|
|
105
|
+
const protocolName = 'eefile';
|
|
106
|
+
protocol.registerFileProtocol(protocolName, (request, callback) => {
|
|
107
|
+
const url = request.url.substring(protocolName.length + 3);
|
|
108
|
+
console.log('[ee-core:job] ----url: ', url);
|
|
109
|
+
callback({ path: path.normalize(decodeURIComponent(url)) })
|
|
110
|
+
});
|
|
111
|
+
|
|
103
112
|
const winOptions = this.config.windowsOption;
|
|
104
113
|
this.electron.mainWindow = new BrowserWindow(winOptions);
|
|
105
114
|
let win = this.electron.mainWindow;
|
|
@@ -114,8 +123,6 @@ class EeApp extends BaseApp {
|
|
|
114
123
|
// nothing
|
|
115
124
|
}
|
|
116
125
|
|
|
117
|
-
this.loadingView(winOptions);
|
|
118
|
-
|
|
119
126
|
await this.windowReady();
|
|
120
127
|
|
|
121
128
|
await this._loderAddons();
|
|
@@ -142,45 +149,6 @@ class EeApp extends BaseApp {
|
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
/**
|
|
146
|
-
* 加载已经实现的功能
|
|
147
|
-
*/
|
|
148
|
-
async loadPreference () {
|
|
149
|
-
const preferences = require('./preferences');
|
|
150
|
-
return await preferences(this);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 加载loading页面
|
|
155
|
-
*/
|
|
156
|
-
loadingView (winOptions) {
|
|
157
|
-
let currentV = process.versions.electron;
|
|
158
|
-
if (utilsCommon.compareVersion(currentV, '12.2.3') == 1) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (!this.config.loadingPage) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const self = this;
|
|
165
|
-
const loadingBrowserView = new BrowserView();
|
|
166
|
-
this.electron.mainWindow.setBrowserView(loadingBrowserView);
|
|
167
|
-
loadingBrowserView.setBounds({
|
|
168
|
-
x: 0,
|
|
169
|
-
y: 0,
|
|
170
|
-
width: winOptions.width,
|
|
171
|
-
height: winOptions.height
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// loading html
|
|
175
|
-
const loadingHtml = path.join('file://', this.config.homeDir, 'public', 'html', 'loading.html');
|
|
176
|
-
loadingBrowserView.webContents.loadURL(loadingHtml);
|
|
177
|
-
this.logger.info('loadingHtml:', loadingHtml);
|
|
178
|
-
|
|
179
|
-
this.electron.mainWindow.webContents.on('dom-ready', async (event) => {
|
|
180
|
-
self.electron.mainWindow.removeBrowserView(loadingBrowserView);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
152
|
/**
|
|
185
153
|
* 应用类型 (远程、html、单页应用)
|
|
186
154
|
*/
|
|
@@ -252,7 +220,7 @@ class EeApp extends BaseApp {
|
|
|
252
220
|
};
|
|
253
221
|
https.createServer(sslOpt, koaApp.callback()).listen(mainServer.port, (err) => {
|
|
254
222
|
if (err) {
|
|
255
|
-
|
|
223
|
+
Log.coreLogger.info('[error] ', err);
|
|
256
224
|
return
|
|
257
225
|
}
|
|
258
226
|
self.loadMainUrl(mode, url);
|
|
@@ -269,8 +237,8 @@ class EeApp extends BaseApp {
|
|
|
269
237
|
*/
|
|
270
238
|
loadMainUrl (type, url) {
|
|
271
239
|
const mainServer = this.config.mainServer;
|
|
272
|
-
|
|
273
|
-
|
|
240
|
+
Log.coreLogger.info('[ee-core:main] Env: %s, Type: %s', this.config.env, type);
|
|
241
|
+
Log.coreLogger.info('[ee-core:main] App running at: %s', url);
|
|
274
242
|
this.electron.mainWindow.loadURL(url, mainServer.options);
|
|
275
243
|
}
|
|
276
244
|
|
|
@@ -328,10 +296,8 @@ class EeApp extends BaseApp {
|
|
|
328
296
|
* 捕获异常
|
|
329
297
|
*/
|
|
330
298
|
async catchLog () {
|
|
331
|
-
const self = this;
|
|
332
|
-
|
|
333
299
|
process.on('uncaughtException', function(err) {
|
|
334
|
-
|
|
300
|
+
Log.coreLogger.error(err);
|
|
335
301
|
});
|
|
336
302
|
}
|
|
337
303
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const Log = require('../log');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 捕获异常
|
|
5
|
+
*/
|
|
6
|
+
exports.start = function() {
|
|
7
|
+
process.on('uncaughtException', this.uncaughtExceptionHandler);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.uncaughtExceptionHandler = function(err) {
|
|
11
|
+
if (!(err instanceof Error)) {
|
|
12
|
+
err = new Error(String(err));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Log.coreLogger.error(err);
|
|
16
|
+
}
|