ee-core 2.1.1 → 2.2.0-beta.1
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/addon/index.js +19 -18
- package/ee/application.js +5 -0
- package/ee/baseApp.js +0 -3
- package/ee/eeApp.js +23 -85
- package/ee/index.js +22 -2
- package/electron/app/index.js +62 -0
- package/electron/index.js +2 -14
- package/electron/{window.js → window/index.js} +31 -7
- package/index.js +2 -2
- package/package.json +1 -1
- package/services/baseContextClass.js +34 -0
- package/services/index.js +31 -0
- /package/{service/index.js → controller/baseContextClass.js} +0 -0
- /package/electron/{winState.js → window/winState.js} +0 -0
package/addon/index.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
const
|
|
1
|
+
const EE = require('../ee');
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* todo 插件模块
|
|
5
|
-
*/
|
|
6
3
|
const Addon = {
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
|
-
*
|
|
6
|
+
* 获取 all addon instances
|
|
10
7
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
8
|
+
all() {
|
|
9
|
+
const { CoreApp } = EE;
|
|
10
|
+
const instances = CoreApp.addon || null;
|
|
11
|
+
if (!instances) {
|
|
12
|
+
throw new Error('Addons not exists or do not call directly at the top!');
|
|
13
|
+
};
|
|
14
|
+
return instances;
|
|
19
15
|
},
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
18
|
+
* 获取 addon instance
|
|
23
19
|
*/
|
|
24
20
|
get(name) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
21
|
+
const instances = this.all();
|
|
22
|
+
const instance = instances[name] || null;
|
|
23
|
+
if (!instance) {
|
|
24
|
+
throw new Error(`Addon class '${name}' not exists or do not call directly at the top!`);
|
|
25
|
+
};
|
|
26
|
+
return instance;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
};
|
|
29
30
|
|
|
30
31
|
module.exports = Addon;
|
package/ee/application.js
CHANGED
|
@@ -5,6 +5,7 @@ const debug = require('debug')('ee-core:Appliaction');
|
|
|
5
5
|
const EeApp = require('./eeApp');
|
|
6
6
|
const Utils = require('../utils');
|
|
7
7
|
const Ps = require('../ps');
|
|
8
|
+
const EE = require('./index');
|
|
8
9
|
|
|
9
10
|
class Appliaction extends EeApp {
|
|
10
11
|
constructor() {
|
|
@@ -71,6 +72,10 @@ class Appliaction extends EeApp {
|
|
|
71
72
|
debug('options:%j', options)
|
|
72
73
|
|
|
73
74
|
super(options);
|
|
75
|
+
|
|
76
|
+
// 设置全局this
|
|
77
|
+
EE.CoreApp = this;
|
|
78
|
+
|
|
74
79
|
this.initialize();
|
|
75
80
|
}
|
|
76
81
|
|
package/ee/baseApp.js
CHANGED
package/ee/eeApp.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const assert = require('assert');
|
|
4
|
-
const { app } = require('electron');
|
|
5
4
|
const is = require('is-type-of');
|
|
6
5
|
const Koa = require('koa');
|
|
7
6
|
const koaServe = require('koa-static');
|
|
8
7
|
const https = require('https');
|
|
9
8
|
const BaseApp = require('./baseApp');
|
|
10
9
|
const Log = require('../log');
|
|
11
|
-
const
|
|
10
|
+
const CoreElectron = require('../electron');
|
|
11
|
+
const CoreElectronApp = require('../electron/app');
|
|
12
|
+
const CoreElectronWindow = require('../electron/window');
|
|
12
13
|
const Conf = require('../config');
|
|
13
14
|
const Ps = require('../ps');
|
|
14
15
|
const Socket = require('../socket');
|
|
@@ -18,14 +19,15 @@ class EeApp extends BaseApp {
|
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
super(options);
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// 兼容旧的api
|
|
23
|
+
this.electron = CoreElectron;
|
|
22
24
|
this.mainWindow;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* 生成端口
|
|
27
29
|
*/
|
|
28
|
-
async createPorts
|
|
30
|
+
async createPorts() {
|
|
29
31
|
const mainPort = await GetPort({port: this.config.mainServer.port});
|
|
30
32
|
process.env.EE_MAIN_PORT = mainPort;
|
|
31
33
|
this.config.mainServer.port = mainPort;
|
|
@@ -49,46 +51,17 @@ class EeApp extends BaseApp {
|
|
|
49
51
|
/**
|
|
50
52
|
* 启动通信模块
|
|
51
53
|
*/
|
|
52
|
-
async startSocket
|
|
54
|
+
async startSocket() {
|
|
53
55
|
Socket.startAll(this);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
/**
|
|
57
59
|
* 创建electron应用
|
|
58
60
|
*/
|
|
59
|
-
async createElectronApp
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!gotTheLock) {
|
|
64
|
-
await this.appQuit();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
app.on('second-instance', (event) => {
|
|
69
|
-
self.restoreMainWindow();
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
app.whenReady().then(() => {
|
|
73
|
-
self.createWindow();
|
|
74
|
-
app.on('activate', () => {
|
|
75
|
-
self.restoreMainWindow();
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
app.on('window-all-closed', () => {
|
|
80
|
-
if (process.platform !== 'darwin') {
|
|
81
|
-
Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
|
|
82
|
-
self.appQuit();
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
app.on('before-quit', () => {
|
|
87
|
-
Electron.extra.closeWindow = true;
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
if (this.config.hardGpu.enable == false) {
|
|
91
|
-
app.disableHardwareAcceleration();
|
|
61
|
+
async createElectronApp() {
|
|
62
|
+
const newApp = CoreElectronApp.create();
|
|
63
|
+
if (!newApp) {
|
|
64
|
+
return
|
|
92
65
|
}
|
|
93
66
|
|
|
94
67
|
await this.electronAppReady();
|
|
@@ -97,10 +70,10 @@ class EeApp extends BaseApp {
|
|
|
97
70
|
/**
|
|
98
71
|
* 创建应用主窗口
|
|
99
72
|
*/
|
|
100
|
-
async createWindow
|
|
73
|
+
async createWindow() {
|
|
101
74
|
|
|
102
75
|
// 初始化一个主窗口
|
|
103
|
-
this.mainWindow =
|
|
76
|
+
this.mainWindow = CoreElectronWindow.getMainWindow();
|
|
104
77
|
|
|
105
78
|
await this.windowReady();
|
|
106
79
|
|
|
@@ -111,23 +84,10 @@ class EeApp extends BaseApp {
|
|
|
111
84
|
this.selectAppType();
|
|
112
85
|
}
|
|
113
86
|
|
|
114
|
-
/**
|
|
115
|
-
* 还原窗口
|
|
116
|
-
*/
|
|
117
|
-
restoreMainWindow () {
|
|
118
|
-
if (this.mainWindow) {
|
|
119
|
-
if (this.mainWindow.isMinimized()) {
|
|
120
|
-
this.mainWindow.restore();
|
|
121
|
-
}
|
|
122
|
-
this.mainWindow.show();
|
|
123
|
-
this.mainWindow.focus();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
87
|
/**
|
|
128
88
|
* 应用类型 (远程、html、单页应用)
|
|
129
89
|
*/
|
|
130
|
-
selectAppType
|
|
90
|
+
selectAppType() {
|
|
131
91
|
let type = '';
|
|
132
92
|
let url = '';
|
|
133
93
|
|
|
@@ -167,7 +127,7 @@ class EeApp extends BaseApp {
|
|
|
167
127
|
/**
|
|
168
128
|
* 加载本地前端资源
|
|
169
129
|
*/
|
|
170
|
-
loadLocalWeb
|
|
130
|
+
loadLocalWeb(mode, staticDir, hostInfo) {
|
|
171
131
|
const self = this;
|
|
172
132
|
if (!staticDir) {
|
|
173
133
|
staticDir = path.join(this.config.homeDir, 'public', 'dist')
|
|
@@ -210,7 +170,7 @@ class EeApp extends BaseApp {
|
|
|
210
170
|
/**
|
|
211
171
|
* 主页面
|
|
212
172
|
*/
|
|
213
|
-
loadMainUrl
|
|
173
|
+
loadMainUrl(type, url) {
|
|
214
174
|
const mainServer = this.config.mainServer;
|
|
215
175
|
Log.coreLogger.info('[ee-core] [main] Env: %s, Type: %s', this.config.env, type);
|
|
216
176
|
Log.coreLogger.info('[ee-core] [main] App running at: %s', url);
|
|
@@ -220,15 +180,15 @@ class EeApp extends BaseApp {
|
|
|
220
180
|
/**
|
|
221
181
|
* electron app退出
|
|
222
182
|
*/
|
|
223
|
-
async appQuit
|
|
183
|
+
async appQuit() {
|
|
224
184
|
await this.beforeClose();
|
|
225
|
-
|
|
185
|
+
CoreElectronApp.quit();
|
|
226
186
|
}
|
|
227
187
|
|
|
228
188
|
/**
|
|
229
189
|
* 加载插件
|
|
230
190
|
*/
|
|
231
|
-
async _loderAddons
|
|
191
|
+
async _loderAddons() {
|
|
232
192
|
this.loader.loadAddons();
|
|
233
193
|
|
|
234
194
|
// 注册主窗口Contents id
|
|
@@ -243,7 +203,7 @@ class EeApp extends BaseApp {
|
|
|
243
203
|
/**
|
|
244
204
|
* 预加载模块
|
|
245
205
|
*/
|
|
246
|
-
async _loderPreload
|
|
206
|
+
async _loderPreload() {
|
|
247
207
|
let filepath = this.loader.resolveModule(path.join(this.config.baseDir, 'preload', 'index'));
|
|
248
208
|
if (!filepath) return;
|
|
249
209
|
const fileObj = this.loader.loadFile(filepath);
|
|
@@ -254,46 +214,24 @@ class EeApp extends BaseApp {
|
|
|
254
214
|
}
|
|
255
215
|
}
|
|
256
216
|
|
|
257
|
-
/**
|
|
258
|
-
* 序列化参数
|
|
259
|
-
*/
|
|
260
|
-
stringify(obj, ignore) {
|
|
261
|
-
const result = {};
|
|
262
|
-
Object.keys(obj).forEach(key => {
|
|
263
|
-
if (!ignore.includes(key)) {
|
|
264
|
-
result[key] = obj[key];
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
return JSON.stringify(result);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 捕获异常(废弃)
|
|
272
|
-
*/
|
|
273
|
-
async catchLog () {
|
|
274
|
-
process.on('uncaughtException', function(err) {
|
|
275
|
-
Log.coreLogger.error(err);
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
217
|
/**
|
|
280
218
|
* electron app已经准备好,主窗口还未创建
|
|
281
219
|
*/
|
|
282
|
-
async electronAppReady
|
|
220
|
+
async electronAppReady() {
|
|
283
221
|
// do some things
|
|
284
222
|
}
|
|
285
223
|
|
|
286
224
|
/**
|
|
287
225
|
* 主应用窗口已经创建
|
|
288
226
|
*/
|
|
289
|
-
async windowReady
|
|
227
|
+
async windowReady() {
|
|
290
228
|
// do some things
|
|
291
229
|
}
|
|
292
230
|
|
|
293
231
|
/**
|
|
294
232
|
* app关闭之前
|
|
295
233
|
*/
|
|
296
|
-
async beforeClose
|
|
234
|
+
async beforeClose() {
|
|
297
235
|
// do some things
|
|
298
236
|
}
|
|
299
237
|
}
|
package/ee/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const Utils = require('../utils');
|
|
2
2
|
const EEApplication = Symbol('Ee#Application');
|
|
3
|
+
const BuiltInApp = Symbol('Ee#BuiltInApp');
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* EE
|
|
7
|
+
*/
|
|
4
8
|
const EE = {
|
|
5
9
|
|
|
6
10
|
/**
|
|
@@ -12,7 +16,7 @@ const EE = {
|
|
|
12
16
|
},
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
19
|
+
* 设置实例化app对象
|
|
16
20
|
*/
|
|
17
21
|
set app(appObject) {
|
|
18
22
|
if (!this[EEApplication]) {
|
|
@@ -21,12 +25,28 @@ const EE = {
|
|
|
21
25
|
},
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
|
-
*
|
|
28
|
+
* 获取实例化app对象
|
|
25
29
|
*/
|
|
26
30
|
get app() {
|
|
27
31
|
return this[EEApplication] || null;
|
|
28
32
|
},
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* 设置全局this到CoreApp (eeApp)
|
|
36
|
+
*/
|
|
37
|
+
set CoreApp(obj) {
|
|
38
|
+
if (!this[BuiltInApp]) {
|
|
39
|
+
this[BuiltInApp] = obj;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 获取 CoreApp (eeApp)
|
|
45
|
+
*/
|
|
46
|
+
get CoreApp() {
|
|
47
|
+
return this[BuiltInApp] || null;
|
|
48
|
+
},
|
|
49
|
+
|
|
30
50
|
/**
|
|
31
51
|
* 是否加密
|
|
32
52
|
*/
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { app } = require('electron');
|
|
2
|
+
const Window = require('../window');
|
|
3
|
+
const EE = require('../../ee');
|
|
4
|
+
const Log = require('../../log');
|
|
5
|
+
const Electron = require('../index');
|
|
6
|
+
const UtilsIs = require('../../utils/is');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* CoreElectronApp (框架封装的electron app对象)
|
|
10
|
+
*/
|
|
11
|
+
const CoreElectronApp = {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 创建electron应用
|
|
15
|
+
*/
|
|
16
|
+
async create() {
|
|
17
|
+
const { CoreApp } = EE;
|
|
18
|
+
|
|
19
|
+
const gotTheLock = app.requestSingleInstanceLock();
|
|
20
|
+
if (!gotTheLock) {
|
|
21
|
+
app.quit();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
app.on('second-instance', (event) => {
|
|
26
|
+
Window.restoreMainWindow();
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
app.whenReady().then(() => {
|
|
30
|
+
CoreApp.createWindow();
|
|
31
|
+
app.on('activate', () => {
|
|
32
|
+
Window.restoreMainWindow();
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
app.on('window-all-closed', () => {
|
|
37
|
+
if (!UtilsIs.macOS) {
|
|
38
|
+
Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
|
|
39
|
+
CoreApp.appQuit();
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
app.on('before-quit', () => {
|
|
44
|
+
Electron.extra.closeWindow = true;
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
if (CoreApp.config.hardGpu.enable == false) {
|
|
48
|
+
app.disableHardwareAcceleration();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return app;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 退出app
|
|
56
|
+
*/
|
|
57
|
+
quit() {
|
|
58
|
+
app.quit();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = CoreElectronApp;
|
package/electron/index.js
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
const Window = require('./window');
|
|
2
|
-
const EEMainWindow = Symbol('Ee#electron#mainWindow');
|
|
3
2
|
|
|
4
3
|
const Electron = {
|
|
5
4
|
|
|
6
|
-
/**
|
|
7
|
-
* 获取 mainWindow
|
|
8
|
-
*/
|
|
9
|
-
getMainWindow() {
|
|
10
|
-
if (!this[EEMainWindow]) {
|
|
11
|
-
this[EEMainWindow] = Window.createWindow();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return this[EEMainWindow] || null;
|
|
15
|
-
},
|
|
16
|
-
|
|
17
5
|
/**
|
|
18
6
|
* 兼容1.x版本api
|
|
19
7
|
*/
|
|
20
8
|
get mainWindow() {
|
|
21
|
-
return
|
|
9
|
+
return Window.getMainWindow();
|
|
22
10
|
},
|
|
23
11
|
|
|
24
12
|
/**
|
|
@@ -26,7 +14,7 @@ const Electron = {
|
|
|
26
14
|
*/
|
|
27
15
|
extra: {
|
|
28
16
|
closeWindow: false,
|
|
29
|
-
},
|
|
17
|
+
},
|
|
30
18
|
};
|
|
31
19
|
|
|
32
20
|
module.exports = Electron;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
const {app, BrowserWindow, Menu} = require('electron');
|
|
2
|
-
const Conf = require('
|
|
3
|
-
const Ps = require('
|
|
1
|
+
const { app, BrowserWindow, Menu } = require('electron');
|
|
2
|
+
const Conf = require('../../config');
|
|
3
|
+
const Ps = require('../../ps');
|
|
4
|
+
const EEMainWindow = Symbol('Ee#electron#mainWindow');
|
|
4
5
|
|
|
5
6
|
const Window = {
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* 获取 mainWindow
|
|
10
|
+
*/
|
|
11
|
+
getMainWindow() {
|
|
12
|
+
if (!this[EEMainWindow]) {
|
|
13
|
+
this[EEMainWindow] = this.createMainWindow();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this[EEMainWindow] || null;
|
|
17
|
+
},
|
|
18
|
+
|
|
7
19
|
/**
|
|
8
20
|
* 创建应用主窗口
|
|
9
21
|
*/
|
|
10
|
-
|
|
22
|
+
createMainWindow() {
|
|
11
23
|
|
|
12
24
|
// todo
|
|
13
25
|
// const protocolName = 'eefile';
|
|
@@ -18,7 +30,8 @@ const Window = {
|
|
|
18
30
|
// });
|
|
19
31
|
|
|
20
32
|
const config = Conf.all();
|
|
21
|
-
|
|
33
|
+
const win = new BrowserWindow(config.windowsOption);
|
|
34
|
+
this[EEMainWindow] = win;
|
|
22
35
|
|
|
23
36
|
// 菜单显示/隐藏
|
|
24
37
|
if (config.openAppMenu === 'dev-show' && Ps.isProd()) {
|
|
@@ -37,9 +50,20 @@ const Window = {
|
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
return win;
|
|
40
|
-
}
|
|
41
|
-
|
|
53
|
+
},
|
|
42
54
|
|
|
55
|
+
/**
|
|
56
|
+
* 还原窗口
|
|
57
|
+
*/
|
|
58
|
+
restoreMainWindow() {
|
|
59
|
+
if (this[EEMainWindow]) {
|
|
60
|
+
if (this[EEMainWindow].isMinimized()) {
|
|
61
|
+
this[EEMainWindow].restore();
|
|
62
|
+
}
|
|
63
|
+
this[EEMainWindow].show();
|
|
64
|
+
this[EEMainWindow].focus();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
43
67
|
};
|
|
44
68
|
|
|
45
69
|
module.exports = Window;
|
package/index.js
CHANGED
|
@@ -12,13 +12,13 @@ const EE = require('./ee');
|
|
|
12
12
|
* @member {Controller} EeCore#Controller
|
|
13
13
|
* @since 1.0.0
|
|
14
14
|
*/
|
|
15
|
-
const Controller = require('./controller');
|
|
15
|
+
const Controller = require('./controller/baseContextClass');
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @member {Service} EeCore#Service
|
|
19
19
|
* @since 1.0.0
|
|
20
20
|
*/
|
|
21
|
-
const Service = require('./
|
|
21
|
+
const Service = require('./services/baseContextClass');
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @member {Storage}
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BaseContextClass is a base class that can be extended,
|
|
5
|
+
* it's instantiated in context level,
|
|
6
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
7
|
+
*/
|
|
8
|
+
class BaseContextClass {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class
|
|
12
|
+
* @param {Context} ctx - context instance
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
/**
|
|
17
|
+
* @member {Application} BaseContextClass#app
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
this.app = ctx;
|
|
21
|
+
/**
|
|
22
|
+
* @member {Config} BaseContextClass#config
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
this.config = ctx.config;
|
|
26
|
+
/**
|
|
27
|
+
* @member {Service} BaseContextClass#service
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
this.service = ctx.service;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = BaseContextClass;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const EE = require('../ee');
|
|
2
|
+
|
|
3
|
+
const Services = {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取 all addon instances
|
|
7
|
+
*/
|
|
8
|
+
all() {
|
|
9
|
+
const { CoreApp } = EE;
|
|
10
|
+
const instances = CoreApp.service || null;
|
|
11
|
+
if (!instances) {
|
|
12
|
+
throw new Error('Services not exists or do not call directly at the top!');
|
|
13
|
+
};
|
|
14
|
+
return instances;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 获取 addon instance
|
|
19
|
+
*/
|
|
20
|
+
get(name) {
|
|
21
|
+
const instances = this.all();
|
|
22
|
+
const instance = instances[name] || null;
|
|
23
|
+
if (!instance) {
|
|
24
|
+
throw new Error(`Service class '${name}' not exists or do not call directly at the top!`);
|
|
25
|
+
};
|
|
26
|
+
return instance;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = Services;
|
|
File without changes
|
|
File without changes
|