ee-core 2.0.0-beta.3 → 2.0.0-beta.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.
Files changed (68) hide show
  1. package/addon/index.js +30 -0
  2. package/config/config.default.js +2 -3
  3. package/config/index.js +54 -0
  4. package/const/channel.js +9 -0
  5. package/{module/const → const}/index.js +1 -5
  6. package/controller/index.js +34 -0
  7. package/core/index.js +0 -2
  8. package/core/lib/ee.js +0 -2
  9. package/core/lib/loader/ee_loader.js +2 -2
  10. package/core/lib/loader/file_loader.js +1 -0
  11. package/{lib → ee}/application.js +2 -2
  12. package/{lib → ee}/baseApp.js +5 -4
  13. package/{lib → ee}/eeApp.js +21 -47
  14. package/ee/index.js +30 -0
  15. package/electron/index.js +32 -0
  16. package/electron/window.js +45 -0
  17. package/exception/index.js +85 -0
  18. package/{module/httpclient → httpclient}/index.js +2 -2
  19. package/index.js +8 -10
  20. package/jobs/baseJobClass.js +16 -0
  21. package/jobs/child/app.js +63 -0
  22. package/jobs/child/forkProcess.js +61 -0
  23. package/jobs/child/index.js +78 -0
  24. package/jobs/childPool/app.js +68 -0
  25. package/{module/jobs/child → jobs/childPool}/forkProcess.js +15 -16
  26. package/{module/jobs/child → jobs/childPool}/index.js +27 -17
  27. package/{module/jobs/child → jobs/childPool}/pool.js +3 -3
  28. package/{module/jobs → jobs}/renderer/loadView.js +1 -1
  29. package/{module/jobs → jobs}/unification.js +1 -1
  30. package/{module/loader → loader}/index.js +36 -14
  31. package/{module/log → log}/logger.js +1 -1
  32. package/message/childMessage.js +31 -0
  33. package/{module/message → message}/index.js +2 -11
  34. package/{module/utils → oldUtils}/index.js +25 -5
  35. package/package.json +2 -1
  36. package/{module/utils/ps.js → ps/index.js} +30 -3
  37. package/service/index.js +34 -0
  38. package/{module/socket → socket}/httpServer.js +12 -18
  39. package/socket/index.js +82 -0
  40. package/{module/socket → socket}/io.js +6 -2
  41. package/{module/socket → socket}/ipcServer.js +2 -4
  42. package/socket/socketServer.js +66 -0
  43. package/{module/storage → storage}/jsondbStorage.js +38 -1
  44. package/{module/storage → storage}/sqliteStorage.js +1 -1
  45. package/tools/encrypt.js +1 -1
  46. package/{module/utils → utils}/helper.js +0 -1
  47. package/utils/index.js +7 -27
  48. package/module/exception/index.js +0 -16
  49. package/module/jobs/child/app.js +0 -43
  50. package/module/message/childMessage.js +0 -63
  51. package/module/message/ipcMain.js +0 -160
  52. package/module/message/ipcRender.js +0 -0
  53. package/module/message/manager.js +0 -0
  54. package/module/message/messenger.js +0 -0
  55. package/module/socket/socketClient.js +0 -49
  56. package/module/socket/socketServer.js +0 -76
  57. package/module/socket/start.js +0 -22
  58. /package/{lib → ee}/appLoader.js +0 -0
  59. /package/{module/jobs → jobs}/index.js +0 -0
  60. /package/{module/jobs → jobs}/renderer/index.js +0 -0
  61. /package/{module/log → log}/index.js +0 -0
  62. /package/{module/storage → storage}/index.js +0 -0
  63. /package/{module/storage → storage}/jsondb/adapters/Base.js +0 -0
  64. /package/{module/storage → storage}/jsondb/adapters/FileSync.js +0 -0
  65. /package/{module/storage → storage}/jsondb/main.js +0 -0
  66. /package/{module/utils → utils}/copyto.js +0 -0
  67. /package/{module/utils → utils}/json.js +0 -0
  68. /package/{module/utils → utils}/wrap.js +0 -0
@@ -1,63 +0,0 @@
1
- const Log = require('../log');
2
-
3
- /**
4
- * ChildMessage
5
- */
6
- class ChildMessage {
7
- constructor() {
8
- // ...
9
- }
10
-
11
- /**
12
- * 初始化事件监听
13
- */
14
- initEvents() {
15
- process.on('disconnect', () => {
16
- Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process disconnected:${process.pid} !`);
17
- });
18
- process.on('exit', () => {
19
- Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process exited:${process.pid} !`);
20
- });
21
- }
22
-
23
- /**
24
- * 监听消息
25
- */
26
- onMessage(handle) {
27
- Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${params} from the mainProcess`);
28
-
29
- process.on('message', handle.bind(this));
30
- }
31
-
32
- /**
33
- * 消息处理
34
- */
35
- // _handleMessage(params = {}) {
36
- // Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${params} from the mainProcess`);
37
- // }
38
-
39
- /**
40
- * 向主进程发消息
41
- */
42
- sendToMain(message, ...other) {
43
- return process.send(message, ...other);
44
- }
45
-
46
- /**
47
- * 断开连接
48
- */
49
- disconnect() {
50
- process.disconnect();
51
- }
52
-
53
- /**
54
- * 进程退出
55
- */
56
- exit() {
57
- process.exit();
58
- }
59
- }
60
-
61
-
62
-
63
- module.exports = ChildMessage;
@@ -1,160 +0,0 @@
1
-
2
- class IpcMain {
3
- constructor() {
4
- this.event = new EventEmitter();
5
- this.services = {};
6
- /* 根据name获取window id */
7
- ipcMain.handle('MessageChannel.getIdFromName', (e, args) => {
8
- return (this.services[args.name] || {}).id;
9
- });
10
- /* 使用name和window id注册一个服务 */
11
- ipcMain.handle('MessageChannel.registryService', (e, args) => {
12
- const { name, id } = args;
13
- this.registry(name, id);
14
- return this.services[name];
15
- });
16
-
17
- }
18
-
19
- /**
20
- * invoke [在主进程(main)中向另外一个服务进程(service)发送异步请求,并取得回调Promise]
21
- * @param {[String]} name [服务名]
22
- * @param {[String]} channel [服务监听的信号名]
23
- * @param {[Any]} args [携带参数(会被序列化,不会传递对象Proptype信息)]
24
- * @return {[Promise]} [回调]
25
- */
26
- invoke (name, channel, args={}) {
27
- const pid = getRandomString();
28
- const { id } = this.services[name];
29
-
30
- return new Promise((resolve, reject) => {
31
- if (name === 'main') reject(new Error(`MessageChannel: the main process can not send a message to itself!`))
32
- if (!id) reject(new Error(`MessageChannel: can not get the id of the window names ${name}`));
33
- const win = BrowserWindow.fromId(id);
34
- if (!win) reject(new Error(`MessageChannel: can not find a window with id: ${id}`));
35
- win.webContents.send(channel, Object.assign(args, { pid, isFromMain: true }));
36
- ipcMain.once(pid, function(event, rsp) {
37
- resolve(rsp);
38
- });
39
-
40
- });
41
- }
42
-
43
- /**
44
- * handle [在主进程中(main)监听来自其它渲染进程(service/window)的请求,将promiseFunc执行的结果返回]
45
- * @param {[String]} channel [服务监听的信号名]
46
- * @param {[Function]} promiseFunc [此函数执行的结果会被发送到消息发送者]
47
- * @return {[Promise]} [回调]
48
- */
49
- handle(channel, promiseFunc) {
50
- if (!promiseFunc instanceof Function) throw new Error('MessageChannel: promiseFunc must be a function!');
51
- ipcMain.handle(channel, (event, ...args) => {
52
- return promiseFunc(event, ...args).then((result) => {
53
-
54
- return result;
55
- });
56
- });
57
- }
58
-
59
- /**
60
- * handle [在主进程中(main)监听一次来自其它渲染进程(service/window)的请求,将promiseFunc执行的结果返回]
61
- * @param {[String]} channel [服务监听的信号名]
62
- * @param {[Function]} promiseFunc [此函数执行的结果会被发送到消息发送者]
63
- * @return {[Promise]} [回调]
64
- */
65
- handleOnce(channel, promiseFunc) {
66
- if (!promiseFunc instanceof Function) throw new Error('MessageChannel: promiseFunc must be a function!');
67
- ipcMain.handleOnce(channel, (event, ...args) => {
68
- return promiseFunc(event, ...args).then(result => {
69
-
70
- return result;
71
- });
72
- });
73
- }
74
-
75
- /**
76
- * send [在主进程(main)向另外一个服务进程(service)发送异步请求,不可立即取得值,请配合on监听信号使用]
77
- * @param {[String]} name [服务名]
78
- * @param {[String]} channel [服务监听的信号名]
79
- * @param {[Any]} args [携带参数(会被序列化,不会传递对象Proptype信息)]
80
- */
81
- send(name, channel, args={}) {
82
- const id = (this.services[name] || {}).id;
83
-
84
-
85
- if (!id) throw new Error(`MessageChannel: can not get the id of the window names ${name}`);
86
- const win = BrowserWindow.fromId(id);
87
- if (!win) throw new Error(`MessageChannel: can not find a window with id: ${id}`);
88
-
89
- win.webContents.send(channel, args);
90
- }
91
-
92
- /**
93
- * send [在主进程中(main)向指定某个id的渲染进程窗口(service/window)发送请求,不可立即取得值,请配合on监听信号使用]
94
- * @param {[String]} id [window id]
95
- * @param {[String]} channel [服务监听的信号名]
96
- * @param {[Any]} args [携带参数(会被序列化,不会传递对象Proptype信息)]
97
- */
98
- sendTo(id, channel, args) {
99
-
100
- if (!BrowserWindow.fromId(id)) throw new Error(`MessageChannel: can not find a window with id:${id}!`);
101
- BrowserWindow.fromId(id).webContents.send(channel, args);
102
- }
103
-
104
- /**
105
- * on [在主进程中(main)监听来自其它渲染进程(service/window)的请求]
106
- * @param {[String]} channel [服务监听的信号名]
107
- * @param {[Function]} func [消息到达后,此函数会被触发,同于原生ipcRenderer.on]
108
- */
109
- on(channel, func) {
110
- if (!func instanceof Function) throw new Error('MessageChannel: func must be a function!');
111
- ipcMain.on(channel, (event, ...args) => {
112
-
113
- func(event, ...args);
114
- });
115
- }
116
-
117
- /**
118
- * once [在主进程中(main)监听一次来自其它渲染进程(service/window)的请求]
119
- * @param {[String]} channel [服务监听的信号名]
120
- * @param {[Function]} func [消息到达后,此函数会被触发,同于原生ipcRenderer.on]
121
- */
122
- once(channel, func) {
123
- if (!func instanceof Function) throw new Error('MessageChannel: func must be a function!');
124
- ipcMain.once(channel, (event, ...args) => {
125
-
126
- func(event, ...args);
127
- });
128
- }
129
-
130
- /**
131
- * registry [注册BrowserWindow和BrowserService]
132
- * @param {[String]} name [唯一的名字]
133
- * @param {[String]} id [window id]
134
- * @param {[String]} pid [process id]
135
- */
136
- registry(name, id, pid) {
137
- if (name === 'main') throw new Error(`MessageChannel: you can not registry a service named:${name}, it's reserved for the main process!`)
138
- if (this.services[name]) console.warn(`MessageChannel: the service - ${name} has been registeried!`)
139
- this.services[name] = { name, id, pid };
140
- this.event.emit('registry', this.services[name]);
141
- }
142
-
143
- /**
144
- * unregistry [注册BrowserWindow和BrowserService]
145
- * @param {[String]} name [唯一的名字]
146
- * @param {[String]} id [window id]
147
- * @param {[String]} pid [process id]
148
- */
149
- unregistry(name) {
150
- if (name === 'main') throw new Error(`MessageChannel: you can not unregistry a service named:${name}, it's reserved for the main process!`);
151
- if (this.services[name]) console.warn(`MessageChannel: the service - ${name} will be unregisteried!`);
152
- if (this.services[name]) {
153
- this.event.emit('unregistry', this.services[name]);
154
- delete this.services[name];
155
- } else {
156
- console.warn(`MessageChannel: unregistry -> the service - ${name} is not found!`);
157
- }
158
- }
159
- }
160
-
File without changes
File without changes
File without changes
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const IoClient = require('socket.io-client');
5
- const Constants = require('../const');
6
- const Storage = require('../storage');
7
-
8
- class SocketClient {
9
- constructor (port) {
10
- port = port ? parseInt(port) : this.getSocketcPort();
11
-
12
- assert(typeof port === 'number', 'port required, and must be a number');
13
-
14
- const url = 'http://127.0.0.1:' + port;
15
- console.log('[ee-core] [module/socket/socketClient] url:', url);
16
- this.client = IoClient(url);
17
- }
18
-
19
- static getInstance (port) {
20
- if (typeof this.instance === 'object') {
21
- return this.instance;
22
- }
23
- this.instance = new SocketClient(port);
24
- return this.instance;
25
- }
26
-
27
- call (method = '', ...params) {
28
- return new Promise((resolve, reject) => {
29
- // 获取通信频道
30
- const channel = Constants.socketIo.channel.partySoftware;
31
- this.client.emit(channel, { cmd: method, params: params }, (response) => {
32
- resolve(response);
33
- });
34
- });
35
- }
36
-
37
- getCoreDB () {
38
- const coreDB = Storage.connection('system');
39
- return coreDB;
40
- }
41
-
42
- getSocketcPort () {
43
- const cdb = this.getCoreDB();
44
- const port = cdb.getItem('config').socketServer.port;
45
- return parseInt(port);
46
- }
47
- }
48
-
49
- module.exports = SocketClient;
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { Server } = require('socket.io');
5
- const is = require('is-type-of');
6
- const Storage = require('../storage');
7
- const Constants = require('../const');
8
- const Log = require('../log');
9
-
10
- /**
11
- * socket server
12
- */
13
- class SocketServer {
14
- constructor (app) {
15
- this.app = app;
16
- const options = this.app.config.socketServer;
17
-
18
- if (!options.enable) {
19
- return;
20
- }
21
-
22
- let port = process.env.EE_SOCKET_PORT ? parseInt(process.env.EE_SOCKET_PORT) : parseInt(this.getSocketPort());
23
- assert(typeof port === 'number', 'socekt port required, and must be a number');
24
- this.consoleLogger.info('[ee-core] [module/socket/socketServer] port is:', port);
25
-
26
- // let opt = Object.assign({}, options);
27
- // delete opt.enable;
28
- this.io = new Server(port, options);
29
- this.connec();
30
- }
31
-
32
- connec () {
33
- const self = this;
34
- this.io.on('connection', (socket) => {
35
- const channel = Constants.socketIo.channel.partySoftware;
36
- socket.on(channel, async (message, callback) => {
37
- console.log('[ee-core] [module/socket/socketServer] socket id:' + socket.id + ' message cmd: ' + message.cmd);
38
-
39
- try {
40
- // 找函数
41
- const cmd = message.cmd;
42
- const args = message.params;
43
- let fn = null;
44
- if (is.string(cmd)) {
45
- const actions = cmd.split('.');
46
- let obj = self.app;
47
- actions.forEach(key => {
48
- obj = obj[key];
49
- if (!obj) throw new Error(`class or function '${key}' not exists`);
50
- });
51
- fn = obj;
52
- }
53
- if (!fn) throw new Error('function not exists');
54
-
55
- const result = await fn.call(self.app, args);
56
- callback(result);
57
- } catch (err) {
58
- Log.coreLogger.error('[ee-core] [module/socket/socketServer] throw error:', err);
59
- }
60
- });
61
- });
62
- }
63
-
64
- getCoreDB () {
65
- const coreDB = Storage.connection('system');
66
- return coreDB;
67
- }
68
-
69
- getSocketPort () {
70
- const cdb = this.getCoreDB();
71
- const port = cdb.getItem('config').socketServer.port;
72
- return port;
73
- }
74
- }
75
-
76
- module.exports = SocketServer;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- const SocketServer = require('./socketServer');
4
- const IpcServer = require('./ipcServer');
5
- const HttpServer = require('./httpServer');
6
-
7
- /**
8
- * server
9
- */
10
- module.exports = (app) => {
11
-
12
- // 启动 socket server
13
- new SocketServer(app);
14
-
15
- // 启动 http server
16
- new HttpServer(app);
17
-
18
- // 启动 electron ipc server
19
- new IpcServer(app);
20
-
21
- }
22
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes