ee-core 2.9.2-beta.1 → 2.10.0

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.
Files changed (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/addon/index.js +34 -34
  4. package/addon/window/index.js +98 -98
  5. package/bin/tools.js +8 -8
  6. package/config/cache.js +41 -38
  7. package/config/config.default.js +331 -330
  8. package/config/index.js +75 -73
  9. package/const/channel.js +17 -17
  10. package/const/index.js +8 -8
  11. package/controller/baseContextClass.js +34 -34
  12. package/controller/index.js +34 -34
  13. package/core/index.js +10 -10
  14. package/core/lib/ee.js +216 -216
  15. package/core/lib/loader/context_loader.js +106 -106
  16. package/core/lib/loader/ee_loader.js +435 -435
  17. package/core/lib/loader/file_loader.js +326 -326
  18. package/core/lib/loader/mixin/addon.js +32 -32
  19. package/core/lib/loader/mixin/config.js +130 -130
  20. package/core/lib/loader/mixin/controller.js +125 -125
  21. package/core/lib/loader/mixin/service.js +28 -28
  22. package/core/lib/utils/base_context_class.js +34 -34
  23. package/core/lib/utils/function.js +30 -30
  24. package/core/lib/utils/index.js +133 -133
  25. package/core/lib/utils/sequencify.js +59 -59
  26. package/core/lib/utils/timing.js +77 -77
  27. package/cross/index.js +183 -183
  28. package/cross/spawnProcess.js +183 -183
  29. package/ee/appLoader.js +48 -48
  30. package/ee/application.js +99 -99
  31. package/ee/baseApp.js +103 -102
  32. package/ee/eeApp.js +408 -408
  33. package/ee/index.js +57 -57
  34. package/electron/app/index.js +64 -58
  35. package/electron/index.js +19 -19
  36. package/electron/window/index.js +73 -73
  37. package/electron/window/winState.js +186 -186
  38. package/exception/index.js +112 -112
  39. package/html/boot.html +98 -98
  40. package/html/cross-failure.html +28 -28
  41. package/html/failure.html +28 -28
  42. package/html/index.js +13 -13
  43. package/httpclient/index.js +161 -161
  44. package/index.js +54 -54
  45. package/jobs/baseJobClass.js +16 -16
  46. package/jobs/child/app.js +65 -65
  47. package/jobs/child/forkProcess.js +145 -145
  48. package/jobs/child/index.js +82 -82
  49. package/jobs/child-pool/index.js +213 -213
  50. package/jobs/index.js +8 -8
  51. package/jobs/load-balancer/algorithm/index.js +11 -11
  52. package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
  53. package/jobs/load-balancer/algorithm/polling.js +11 -11
  54. package/jobs/load-balancer/algorithm/random.js +9 -9
  55. package/jobs/load-balancer/algorithm/specify.js +14 -14
  56. package/jobs/load-balancer/algorithm/weights.js +21 -21
  57. package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
  58. package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
  59. package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
  60. package/jobs/load-balancer/consts.js +9 -9
  61. package/jobs/load-balancer/index.js +201 -201
  62. package/jobs/load-balancer/scheduler.js +31 -31
  63. package/jobs/renderer/index.js +141 -141
  64. package/jobs/renderer/loadView.js +40 -40
  65. package/jobs/unification.js +63 -63
  66. package/loader/index.js +172 -172
  67. package/log/index.js +68 -68
  68. package/log/logger.js +86 -80
  69. package/main/index.js +56 -56
  70. package/message/childMessage.js +54 -54
  71. package/message/index.js +18 -18
  72. package/old-utils/index.js +91 -91
  73. package/package.json +38 -38
  74. package/ps/index.js +371 -371
  75. package/services/baseContextClass.js +34 -34
  76. package/services/index.js +40 -40
  77. package/socket/httpServer.js +147 -147
  78. package/socket/index.js +81 -81
  79. package/socket/io.js +27 -27
  80. package/socket/ipcServer.js +112 -112
  81. package/socket/socketServer.js +69 -65
  82. package/storage/index.js +38 -38
  83. package/storage/jsondb/adapters/Base.js +23 -23
  84. package/storage/jsondb/adapters/FileSync.js +64 -52
  85. package/storage/jsondb/main.js +55 -42
  86. package/storage/jsondbStorage.js +195 -195
  87. package/storage/sqliteStorage.js +123 -123
  88. package/utils/co.js +237 -237
  89. package/utils/copyto.js +160 -160
  90. package/utils/depd/index.js +538 -538
  91. package/utils/depd/lib/browser/index.js +77 -77
  92. package/utils/extend.js +73 -73
  93. package/utils/get-port/index.d.ts +64 -64
  94. package/utils/get-port/index.js +148 -148
  95. package/utils/helper.js +220 -220
  96. package/utils/index.js +160 -160
  97. package/utils/ip.js +261 -261
  98. package/utils/is.js +145 -145
  99. package/utils/json.js +72 -72
  100. package/utils/pargv.js +263 -263
  101. package/utils/time/index.js +19 -19
  102. package/utils/time/ms.js +162 -162
  103. package/utils/wrap.js +35 -35
@@ -1,184 +1,184 @@
1
- const EventEmitter = require('events');
2
- const path = require('path');
3
- const crossSpawn = require('cross-spawn');
4
- const Log = require('../log');
5
- const Ps = require('../ps');
6
- const Channel = require('../const/channel');
7
- const EE = require('../ee');
8
- const Helper = require('../utils/helper');
9
- const UtilsIs = require('../utils/is');
10
- const UtilsPargv = require('../utils/pargv');
11
-
12
- class SpawnProcess {
13
- constructor(host, opt = {}) {
14
- this.emitter = new EventEmitter();
15
- this.host = host;
16
- this.child = undefined;
17
- this.pid = 0;
18
- this.port = 0;
19
- this.name = "";
20
- this.config = {};
21
- this._init(opt);
22
- }
23
-
24
- /**
25
- * 初始化子进程
26
- */
27
- _init(options = {}) {
28
- const { targetConf, port } = options;
29
- this.config = targetConf;
30
- this.port = port;
31
-
32
- // 该名称如果在childrenMap重复,会被重写
33
- this.name = targetConf.name;
34
-
35
- // Launch executable program
36
- let cmdPath = '';
37
- let cmdArgs = targetConf.args;
38
- let execDir = Ps.getExtraResourcesDir();
39
- let standardOutput = ['inherit', 'inherit', 'inherit', 'ipc'];
40
- if (Ps.isPackaged()) {
41
- standardOutput = ['ignore', 'ignore', 'ignore', 'ipc'];
42
- }
43
- if (targetConf.stdio) {
44
- standardOutput = targetConf.stdio;
45
- }
46
-
47
- const { cmd, directory } = targetConf;
48
- // use cmd first
49
- if (cmd) {
50
- if (!directory) {
51
- throw new Error(`[ee-core] [cross] The config [directory] attribute does not exist`);
52
- }
53
- cmdPath = cmd;
54
- if (!path.isAbsolute(cmd) && !Ps.isDev()) {
55
- cmdPath = path.join(Ps.getExtraResourcesDir(), cmd);
56
- }
57
- } else {
58
- cmdPath = path.join(Ps.getExtraResourcesDir(), targetConf.name);
59
- }
60
-
61
- // windows
62
- if (UtilsIs.windows() && path.extname(cmdPath) != '.exe') {
63
- // Complete the executable program extension
64
- // notice: python.exe may bring up the App Store
65
- if (targetConf.windowsExtname === true || !Ps.isDev()) {
66
- cmdPath += ".exe";
67
- }
68
- }
69
-
70
- // executable program directory
71
- if (directory && path.isAbsolute(directory)) {
72
- execDir = directory;
73
- } else if (directory && !path.isAbsolute(directory)) {
74
- if (Ps.isDev()) {
75
- execDir = path.join(Ps.getHomeDir(), directory);
76
- } else {
77
- execDir = path.join(Ps.getExtraResourcesDir(), directory);
78
- }
79
- } else {
80
- execDir = Ps.getExtraResourcesDir();
81
- }
82
-
83
- Log.coreLogger.info(`[ee-core] [cross/run] cmd: ${cmdPath}, args: ${cmdArgs}`);
84
- const coreProcess = crossSpawn(cmdPath, cmdArgs, {
85
- stdio: standardOutput,
86
- detached: false,
87
- cwd: execDir,
88
- maxBuffer: 1024 * 1024 * 1024
89
- });
90
- this.child = coreProcess;
91
- this.pid = coreProcess.pid;
92
-
93
- coreProcess.on('exit', (code, signal) => {
94
- let data = {
95
- pid: this.pid
96
- }
97
- this.host.emitter.emit(Channel.events.childProcessExit, data);
98
- Log.coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
99
- this._exitElectron();
100
- });
101
-
102
- coreProcess.on('error', (err) => {
103
- let data = {
104
- pid: this.pid
105
- }
106
- this.host.emitter.emit(Channel.events.childProcessError, data);
107
- Log.coreLogger.error(`[ee-core] [corss/process] received a error from child-process, error: ${err}, pid:${this.pid}`);
108
- this._exitElectron();
109
- });
110
- }
111
-
112
- /**
113
- * kill
114
- */
115
- kill(timeout = 1000) {
116
- this.child.kill('SIGINT');
117
- setTimeout(() => {
118
- if (this.child.killed) return;
119
- this.child.kill('SIGKILL');
120
- }, timeout)
121
- }
122
-
123
- // send(message) {
124
- // return this.sendByType(message, 'message');
125
- // }
126
-
127
- // close() {
128
- // return this.sendByType('close', 'close');
129
- // }
130
-
131
- // async sendByType(message, type) {
132
- // const msg = typeof message === 'string' ? message : JSON.stringify(message);
133
- // const id = this._generateId();
134
-
135
- // this.child.send({
136
- // id,
137
- // type,
138
- // data: msg,
139
- // });
140
- // return;
141
- // }
142
-
143
- getUrl() {
144
- const ssl = Helper.getValueFromArgv(this.config.args, 'ssl');
145
- let hostname = Helper.getValueFromArgv(this.config.args, 'hostname')
146
- let protocol = 'http://';
147
- if (ssl && (ssl == 'true' || ssl == '1')) {
148
- protocol = 'https://';
149
- }
150
- hostname = hostname ? hostname : '127.0.0.1';
151
- const url = protocol + hostname + ":" + this.port;
152
-
153
- return url;
154
- }
155
-
156
- getArgsObj() {
157
- const obj = UtilsPargv(this.config.args);
158
- return obj;
159
- }
160
-
161
- setPort(port) {
162
- this.port = parseInt(port);
163
- }
164
-
165
- _generateId() {
166
- const rid = Helper.getRandomString();
167
- return `node:${this.pid}:${rid}`;
168
- }
169
-
170
- /**
171
- * exit electron
172
- */
173
- _exitElectron(timeout = 1000) {
174
- const { CoreApp } = EE;
175
- if (this.config.appExit) {
176
- setTimeout(() => {
177
- // 进程退出前的一些清理工作
178
- CoreApp.appQuit();
179
- }, timeout)
180
- }
181
- }
182
- }
183
-
1
+ const EventEmitter = require('events');
2
+ const path = require('path');
3
+ const crossSpawn = require('cross-spawn');
4
+ const Log = require('../log');
5
+ const Ps = require('../ps');
6
+ const Channel = require('../const/channel');
7
+ const EE = require('../ee');
8
+ const Helper = require('../utils/helper');
9
+ const UtilsIs = require('../utils/is');
10
+ const UtilsPargv = require('../utils/pargv');
11
+
12
+ class SpawnProcess {
13
+ constructor(host, opt = {}) {
14
+ this.emitter = new EventEmitter();
15
+ this.host = host;
16
+ this.child = undefined;
17
+ this.pid = 0;
18
+ this.port = 0;
19
+ this.name = "";
20
+ this.config = {};
21
+ this._init(opt);
22
+ }
23
+
24
+ /**
25
+ * 初始化子进程
26
+ */
27
+ _init(options = {}) {
28
+ const { targetConf, port } = options;
29
+ this.config = targetConf;
30
+ this.port = port;
31
+
32
+ // 该名称如果在childrenMap重复,会被重写
33
+ this.name = targetConf.name;
34
+
35
+ // Launch executable program
36
+ let cmdPath = '';
37
+ let cmdArgs = targetConf.args;
38
+ let execDir = Ps.getExtraResourcesDir();
39
+ let standardOutput = ['inherit', 'inherit', 'inherit', 'ipc'];
40
+ if (Ps.isPackaged()) {
41
+ standardOutput = ['ignore', 'ignore', 'ignore', 'ipc'];
42
+ }
43
+ if (targetConf.stdio) {
44
+ standardOutput = targetConf.stdio;
45
+ }
46
+
47
+ const { cmd, directory } = targetConf;
48
+ // use cmd first
49
+ if (cmd) {
50
+ if (!directory) {
51
+ throw new Error(`[ee-core] [cross] The config [directory] attribute does not exist`);
52
+ }
53
+ cmdPath = cmd;
54
+ if (!path.isAbsolute(cmd) && !Ps.isDev()) {
55
+ cmdPath = path.join(Ps.getExtraResourcesDir(), cmd);
56
+ }
57
+ } else {
58
+ cmdPath = path.join(Ps.getExtraResourcesDir(), targetConf.name);
59
+ }
60
+
61
+ // windows
62
+ if (UtilsIs.windows() && path.extname(cmdPath) != '.exe') {
63
+ // Complete the executable program extension
64
+ // notice: python.exe may bring up the App Store
65
+ if (targetConf.windowsExtname === true || !Ps.isDev()) {
66
+ cmdPath += ".exe";
67
+ }
68
+ }
69
+
70
+ // executable program directory
71
+ if (directory && path.isAbsolute(directory)) {
72
+ execDir = directory;
73
+ } else if (directory && !path.isAbsolute(directory)) {
74
+ if (Ps.isDev()) {
75
+ execDir = path.join(Ps.getHomeDir(), directory);
76
+ } else {
77
+ execDir = path.join(Ps.getExtraResourcesDir(), directory);
78
+ }
79
+ } else {
80
+ execDir = Ps.getExtraResourcesDir();
81
+ }
82
+
83
+ Log.coreLogger.info(`[ee-core] [cross/run] cmd: ${cmdPath}, args: ${cmdArgs}`);
84
+ const coreProcess = crossSpawn(cmdPath, cmdArgs, {
85
+ stdio: standardOutput,
86
+ detached: false,
87
+ cwd: execDir,
88
+ maxBuffer: 1024 * 1024 * 1024
89
+ });
90
+ this.child = coreProcess;
91
+ this.pid = coreProcess.pid;
92
+
93
+ coreProcess.on('exit', (code, signal) => {
94
+ let data = {
95
+ pid: this.pid
96
+ }
97
+ this.host.emitter.emit(Channel.events.childProcessExit, data);
98
+ Log.coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
99
+ this._exitElectron();
100
+ });
101
+
102
+ coreProcess.on('error', (err) => {
103
+ let data = {
104
+ pid: this.pid
105
+ }
106
+ this.host.emitter.emit(Channel.events.childProcessError, data);
107
+ Log.coreLogger.error(`[ee-core] [corss/process] received a error from child-process, error: ${err}, pid:${this.pid}`);
108
+ this._exitElectron();
109
+ });
110
+ }
111
+
112
+ /**
113
+ * kill
114
+ */
115
+ kill(timeout = 1000) {
116
+ this.child.kill('SIGINT');
117
+ setTimeout(() => {
118
+ if (this.child.killed) return;
119
+ this.child.kill('SIGKILL');
120
+ }, timeout)
121
+ }
122
+
123
+ // send(message) {
124
+ // return this.sendByType(message, 'message');
125
+ // }
126
+
127
+ // close() {
128
+ // return this.sendByType('close', 'close');
129
+ // }
130
+
131
+ // async sendByType(message, type) {
132
+ // const msg = typeof message === 'string' ? message : JSON.stringify(message);
133
+ // const id = this._generateId();
134
+
135
+ // this.child.send({
136
+ // id,
137
+ // type,
138
+ // data: msg,
139
+ // });
140
+ // return;
141
+ // }
142
+
143
+ getUrl() {
144
+ const ssl = Helper.getValueFromArgv(this.config.args, 'ssl');
145
+ let hostname = Helper.getValueFromArgv(this.config.args, 'hostname')
146
+ let protocol = 'http://';
147
+ if (ssl && (ssl == 'true' || ssl == '1')) {
148
+ protocol = 'https://';
149
+ }
150
+ hostname = hostname ? hostname : '127.0.0.1';
151
+ const url = protocol + hostname + ":" + this.port;
152
+
153
+ return url;
154
+ }
155
+
156
+ getArgsObj() {
157
+ const obj = UtilsPargv(this.config.args);
158
+ return obj;
159
+ }
160
+
161
+ setPort(port) {
162
+ this.port = parseInt(port);
163
+ }
164
+
165
+ _generateId() {
166
+ const rid = Helper.getRandomString();
167
+ return `node:${this.pid}:${rid}`;
168
+ }
169
+
170
+ /**
171
+ * exit electron
172
+ */
173
+ _exitElectron(timeout = 1000) {
174
+ const { CoreApp } = EE;
175
+ if (this.config.appExit) {
176
+ setTimeout(() => {
177
+ // 进程退出前的一些清理工作
178
+ CoreApp.appQuit();
179
+ }, timeout)
180
+ }
181
+ }
182
+ }
183
+
184
184
  module.exports = SpawnProcess;
package/ee/appLoader.js CHANGED
@@ -1,48 +1,48 @@
1
- const EeLoader = require('../core/index').EeLoader;
2
-
3
- /**
4
- * App Loader
5
- * @see
6
- */
7
- class AppLoader extends EeLoader {
8
-
9
- /**
10
- * loadPlugin first, then loadConfig
11
- * @since 1.0.0
12
- */
13
- loadConfig() {
14
- super.loadConfig();
15
- }
16
-
17
- /**
18
- * Load all directories in convention
19
- * @since 1.0.0
20
- */
21
- load() {
22
-
23
- // app > plugin
24
- this.loadService();
25
-
26
- // app
27
- this.loadController();
28
-
29
- }
30
-
31
- /**
32
- * load addons
33
- * @since 1.0.0
34
- */
35
- loadAddons() {
36
- this.loadAddon();
37
- }
38
-
39
- /**
40
- * load electron modules
41
- * @since 1.0.0
42
- */
43
- loadElectron() {
44
-
45
- }
46
- }
47
-
48
- module.exports = AppLoader;
1
+ const EeLoader = require('../core/index').EeLoader;
2
+
3
+ /**
4
+ * App Loader
5
+ * @see
6
+ */
7
+ class AppLoader extends EeLoader {
8
+
9
+ /**
10
+ * loadPlugin first, then loadConfig
11
+ * @since 1.0.0
12
+ */
13
+ loadConfig() {
14
+ super.loadConfig();
15
+ }
16
+
17
+ /**
18
+ * Load all directories in convention
19
+ * @since 1.0.0
20
+ */
21
+ load() {
22
+
23
+ // app > plugin
24
+ this.loadService();
25
+
26
+ // app
27
+ this.loadController();
28
+
29
+ }
30
+
31
+ /**
32
+ * load addons
33
+ * @since 1.0.0
34
+ */
35
+ loadAddons() {
36
+ this.loadAddon();
37
+ }
38
+
39
+ /**
40
+ * load electron modules
41
+ * @since 1.0.0
42
+ */
43
+ loadElectron() {
44
+
45
+ }
46
+ }
47
+
48
+ module.exports = AppLoader;
package/ee/application.js CHANGED
@@ -1,100 +1,100 @@
1
- const Exception = require('../exception');
2
- const { app } = require('electron');
3
- const path = require('path');
4
- const debug = require('debug')('ee-core:Appliaction');
5
- const EeApp = require('./eeApp');
6
- const Utils = require('../utils');
7
- const Ps = require('../ps');
8
- const EE = require('./index');
9
-
10
- class Appliaction extends EeApp {
11
- constructor() {
12
- Exception.start();
13
- const { env } = process;
14
-
15
- // initialize mode
16
- Ps.initMode();
17
-
18
- let options = {
19
- env: 'prod',
20
- serverScope: '',
21
- type: 'application',
22
- baseDir: path.join(app.getAppPath(), 'electron'),
23
- homeDir: app.getAppPath(),
24
- framework: path.join(app.getAppPath(), 'node_modules', 'ee-core'),
25
- appName: app.getName(),
26
- userHome: app.getPath('home'),
27
- appData: app.getPath('appData'),
28
- appUserData: app.getPath('userData'),
29
- appVersion: app.getVersion(),
30
- isPackaged: app.isPackaged,
31
- execDir: app.getAppPath(),
32
- isEncrypted: false
33
- }
34
-
35
- // argv
36
- let hotReload = false;
37
- for (let i = 0; i < process.argv.length; i++) {
38
- const tmpArgv = process.argv[i]
39
- if (tmpArgv.indexOf('--env=') !== -1) {
40
- options.env = tmpArgv.substring(6);
41
- }
42
- if (tmpArgv.indexOf('--hot-reload=') !== -1) {
43
- hotReload = tmpArgv.substring(13) == 1 ? true : false;
44
- }
45
- }
46
-
47
- // exec directory (exe dmg dep) for prod
48
- if (options.env == 'prod' && app.isPackaged) {
49
- options.execDir = path.dirname(app.getPath('exe'));
50
- }
51
-
52
- // Todo app.getAppPath() ??? process.cwd()
53
- // Use encryption, base directory is public/electron
54
- if (options.env == 'prod' && Utils.isEncrypt(app.getAppPath())) {
55
- options.baseDir = Ps.getEncryptDir(app.getAppPath());
56
- options.isEncrypted = true;
57
- }
58
-
59
- // normalize env
60
- env.EE_APP_NAME = options.appName;
61
- env.EE_HOME = options.homeDir;
62
- env.EE_BASE_DIR = options.baseDir;
63
- env.EE_SERVER_ENV = options.env;
64
- env.EE_SERVER_SCOPE = options.serverScope;
65
- env.EE_USER_HOME = options.userHome;
66
- env.EE_APP_DATA = options.appData;
67
- env.EE_APP_USER_DATA = options.appUserData;
68
- env.HOT_RELOAD = hotReload;
69
- env.EE_EXEC_DIR = options.execDir;
70
- env.EE_IS_PACKAGED = options.isPackaged;
71
- env.EE_IS_ENCRYPTED = options.isEncrypted;
72
- env.EE_DATABASE_DIR = null;
73
- env.EE_MAIN_PORT = null;
74
- env.EE_SOCKET_PORT = null;
75
- env.EE_HTTP_PORT = null;
76
- debug('options:%j', options)
77
-
78
- super(options);
79
-
80
- // 设置全局this
81
- EE.CoreApp = this;
82
-
83
- this.initialize();
84
- }
85
-
86
- async initialize () {
87
-
88
- await this.createPorts();
89
-
90
- await this.startSocket();
91
-
92
- await this.ready();
93
-
94
- await this.createElectronApp();
95
-
96
- await this.InitModuleMode();
97
- }
98
- }
99
-
1
+ const Exception = require('../exception');
2
+ const { app } = require('electron');
3
+ const path = require('path');
4
+ const debug = require('debug')('ee-core:Appliaction');
5
+ const EeApp = require('./eeApp');
6
+ const Utils = require('../utils');
7
+ const Ps = require('../ps');
8
+ const EE = require('./index');
9
+
10
+ class Appliaction extends EeApp {
11
+ constructor() {
12
+ Exception.start();
13
+ const { env } = process;
14
+
15
+ // initialize mode
16
+ Ps.initMode();
17
+
18
+ let options = {
19
+ env: 'prod',
20
+ serverScope: '',
21
+ type: 'application',
22
+ baseDir: path.join(app.getAppPath(), 'electron'),
23
+ homeDir: app.getAppPath(),
24
+ framework: path.join(app.getAppPath(), 'node_modules', 'ee-core'),
25
+ appName: app.getName(),
26
+ userHome: app.getPath('home'),
27
+ appData: app.getPath('appData'),
28
+ appUserData: app.getPath('userData'),
29
+ appVersion: app.getVersion(),
30
+ isPackaged: app.isPackaged,
31
+ execDir: app.getAppPath(),
32
+ isEncrypted: false
33
+ }
34
+
35
+ // argv
36
+ let hotReload = false;
37
+ for (let i = 0; i < process.argv.length; i++) {
38
+ const tmpArgv = process.argv[i]
39
+ if (tmpArgv.indexOf('--env=') !== -1) {
40
+ options.env = tmpArgv.substring(6);
41
+ }
42
+ if (tmpArgv.indexOf('--hot-reload=') !== -1) {
43
+ hotReload = tmpArgv.substring(13) == 1 ? true : false;
44
+ }
45
+ }
46
+
47
+ // exec directory (exe dmg dep) for prod
48
+ if (options.env == 'prod' && app.isPackaged) {
49
+ options.execDir = path.dirname(app.getPath('exe'));
50
+ }
51
+
52
+ // Todo app.getAppPath() ??? process.cwd()
53
+ // Use encryption, base directory is public/electron
54
+ if (options.env == 'prod' && Utils.isEncrypt(app.getAppPath())) {
55
+ options.baseDir = Ps.getEncryptDir(app.getAppPath());
56
+ options.isEncrypted = true;
57
+ }
58
+
59
+ // normalize env
60
+ env.EE_APP_NAME = options.appName;
61
+ env.EE_HOME = options.homeDir;
62
+ env.EE_BASE_DIR = options.baseDir;
63
+ env.EE_SERVER_ENV = options.env;
64
+ env.EE_SERVER_SCOPE = options.serverScope;
65
+ env.EE_USER_HOME = options.userHome;
66
+ env.EE_APP_DATA = options.appData;
67
+ env.EE_APP_USER_DATA = options.appUserData;
68
+ env.HOT_RELOAD = hotReload;
69
+ env.EE_EXEC_DIR = options.execDir;
70
+ env.EE_IS_PACKAGED = options.isPackaged;
71
+ env.EE_IS_ENCRYPTED = options.isEncrypted;
72
+ env.EE_DATABASE_DIR = null;
73
+ env.EE_MAIN_PORT = null;
74
+ env.EE_SOCKET_PORT = null;
75
+ env.EE_HTTP_PORT = null;
76
+ debug('options:%j', options)
77
+
78
+ super(options);
79
+
80
+ // 设置全局this
81
+ EE.CoreApp = this;
82
+
83
+ this.initialize();
84
+ }
85
+
86
+ async initialize () {
87
+
88
+ await this.createPorts();
89
+
90
+ await this.startSocket();
91
+
92
+ await this.ready();
93
+
94
+ await this.createElectronApp();
95
+
96
+ await this.InitModuleMode();
97
+ }
98
+ }
99
+
100
100
  module.exports = Appliaction;