ee-core 2.0.0-beta.3 → 2.0.0-beta.4

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 (60) hide show
  1. package/index.js +12 -13
  2. package/{lib → module/app}/application.js +2 -2
  3. package/{lib → module/app}/baseApp.js +3 -3
  4. package/{lib → module/app}/eeApp.js +2 -2
  5. package/module/app/index.js +5 -0
  6. package/{config → module/config}/config.default.js +2 -3
  7. package/module/const/channel.js +6 -0
  8. package/{core → module/core}/index.js +0 -2
  9. package/{core → module/core}/lib/ee.js +0 -2
  10. package/{core → module/core}/lib/loader/ee_loader.js +1 -1
  11. package/{core → module/core}/lib/loader/mixin/addon.js +1 -1
  12. package/module/core/lib/utils/base_context_class.js +34 -0
  13. package/module/exception/index.js +75 -6
  14. package/module/httpclient/index.js +2 -2
  15. package/module/jobs/baseJobClass.js +16 -0
  16. package/module/jobs/child/app.js +38 -18
  17. package/module/jobs/child/forkProcess.js +17 -38
  18. package/module/jobs/child/index.js +37 -20
  19. package/module/jobs/childPool/app.js +68 -0
  20. package/module/jobs/childPool/forkProcess.js +81 -0
  21. package/module/jobs/childPool/index.js +71 -0
  22. package/module/jobs/{child → childPool}/pool.js +3 -3
  23. package/module/jobs/renderer/loadView.js +1 -1
  24. package/module/jobs/unification.js +1 -1
  25. package/module/loader/index.js +36 -14
  26. package/module/log/logger.js +1 -1
  27. package/module/message/childMessage.js +11 -43
  28. package/module/message/index.js +2 -9
  29. package/{utils → module/oldUtils}/index.js +6 -6
  30. package/module/{utils/ps.js → ps/index.js} +20 -0
  31. package/module/service/index.js +34 -0
  32. package/module/socket/httpServer.js +1 -1
  33. package/module/socket/io.js +2 -2
  34. package/module/socket/ipcServer.js +3 -3
  35. package/module/socket/socketClient.js +2 -2
  36. package/module/socket/socketServer.js +3 -3
  37. package/module/storage/jsondbStorage.js +1 -1
  38. package/module/storage/sqliteStorage.js +1 -1
  39. package/{tools → module/tools}/encrypt.js +1 -1
  40. package/module/utils/helper.js +0 -1
  41. package/module/utils/index.js +1 -1
  42. package/package.json +3 -2
  43. package/module/message/ipcMain.js +0 -160
  44. package/module/message/ipcRender.js +0 -0
  45. package/module/message/manager.js +0 -0
  46. package/module/message/messenger.js +0 -0
  47. /package/{addon → module/addon}/window/index.js +0 -0
  48. /package/{lib → module/app}/appLoader.js +0 -0
  49. /package/{bin → module/bin}/tools.js +0 -0
  50. /package/{core/lib/utils/base_context_class.js → module/controller/index.js} +0 -0
  51. /package/{core → module/core}/lib/loader/context_loader.js +0 -0
  52. /package/{core → module/core}/lib/loader/file_loader.js +0 -0
  53. /package/{core → module/core}/lib/loader/mixin/config.js +0 -0
  54. /package/{core → module/core}/lib/loader/mixin/controller.js +0 -0
  55. /package/{core → module/core}/lib/loader/mixin/service.js +0 -0
  56. /package/{core → module/core}/lib/utils/function.js +0 -0
  57. /package/{core → module/core}/lib/utils/index.js +0 -0
  58. /package/{core → module/core}/lib/utils/sequencify.js +0 -0
  59. /package/{core → module/core}/lib/utils/timing.js +0 -0
  60. /package/{tools → module/tools}/replaceDist.js +0 -0
@@ -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
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