emr-bridge 1.2.2 → 1.4.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.
- package/LICENCE +1 -1
- package/README.md +136 -113
- package/cjs/enums.d.ts +5 -1
- package/cjs/enums.js +4 -0
- package/cjs/exp.d.ts +4 -0
- package/cjs/exp.js +21 -0
- package/cjs/index.d.ts +3 -4
- package/cjs/index.js +5 -7
- package/cjs/scripts/Bridge.js +6 -0
- package/cjs/scripts/Main.js +26 -0
- package/cjs/scripts/newDecorators.d.ts +63 -1
- package/cjs/scripts/newDecorators.js +50 -5
- package/cjs/scripts/oldDecorators.d.ts +167 -1
- package/cjs/scripts/oldDecorators.js +62 -1
- package/cjs/scripts/preloadProvider.js +37 -1
- package/cjs/scripts/provider.js +58 -1
- package/cjs/scripts/publish.d.ts +15 -1
- package/cjs/scripts/publish.js +96 -1
- package/cjs/types.d.ts +21 -0
- package/{lib → esm}/enums.d.ts +5 -1
- package/{lib → esm}/enums.js +4 -0
- package/esm/exp.d.ts +4 -0
- package/esm/exp.js +3 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +3 -0
- package/{lib → esm}/scripts/Bridge.js +6 -0
- package/esm/scripts/Main.js +61 -0
- package/{lib → esm}/scripts/newDecorators.d.ts +63 -1
- package/{lib → esm}/scripts/newDecorators.js +48 -5
- package/esm/scripts/oldDecorators.d.ts +289 -0
- package/{lib → esm}/scripts/oldDecorators.js +58 -1
- package/esm/scripts/preloadProvider.js +87 -0
- package/{lib → esm}/scripts/provider.js +58 -1
- package/{lib → esm}/scripts/publish.d.ts +15 -1
- package/esm/scripts/publish.js +194 -0
- package/{lib → esm}/types.d.ts +21 -0
- package/package.json +29 -13
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -4
- package/lib/scripts/Main.js +0 -35
- package/lib/scripts/oldDecorators.d.ts +0 -123
- package/lib/scripts/preloadProvider.js +0 -51
- package/lib/scripts/publish.js +0 -101
- /package/{lib → esm}/preload.d.ts +0 -0
- /package/{lib → esm}/preload.js +0 -0
- /package/{lib → esm}/renderer.d.ts +0 -0
- /package/{lib → esm}/renderer.js +0 -0
- /package/{lib → esm}/scripts/Bridge.d.ts +0 -0
- /package/{lib → esm}/scripts/Main.d.ts +0 -0
- /package/{lib → esm}/scripts/preloadProvider.d.ts +0 -0
- /package/{lib → esm}/scripts/provider.d.ts +0 -0
- /package/{lib → esm}/types.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicSetter = exports.publicGetter = exports.publicProperty = exports.publicMethod = void 0;
|
|
3
|
+
exports.publicSetter = exports.publicGetter = exports.publicProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = void 0;
|
|
4
4
|
const publish_1 = require("./publish");
|
|
5
5
|
function publicMethod(arg) {
|
|
6
6
|
return (method, context) => {
|
|
@@ -21,10 +21,55 @@ function publicMethod(arg) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
exports.publicMethod = publicMethod;
|
|
24
|
+
function publicClassMainEvent(arg) {
|
|
25
|
+
return (method, context) => {
|
|
26
|
+
let name = String(context.name);
|
|
27
|
+
if (arg) {
|
|
28
|
+
if (typeof arg === 'string') {
|
|
29
|
+
name = arg;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
name = arg.name ?? name;
|
|
33
|
+
if (arg.scope)
|
|
34
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
context.addInitializer(function () {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
this[context.name] = (0, publish_1.publicMainEvent)(name, method.bind(this));
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.publicClassMainEvent = publicClassMainEvent;
|
|
44
|
+
function publicClassRendererEvent(arg) {
|
|
45
|
+
return (_, context) => {
|
|
46
|
+
let name = String(context.name);
|
|
47
|
+
let receiver = (v) => v;
|
|
48
|
+
if (arg) {
|
|
49
|
+
if (typeof arg === 'string') {
|
|
50
|
+
name = arg;
|
|
51
|
+
}
|
|
52
|
+
else if (typeof arg === 'object') {
|
|
53
|
+
name = arg.name ?? String(context.name);
|
|
54
|
+
receiver = arg.receiver ?? receiver;
|
|
55
|
+
if (arg.scope)
|
|
56
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
receiver = arg;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
context.addInitializer(function () {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
this[context.name] = (0, publish_1.publicRendererEvent)(name, receiver);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.publicClassRendererEvent = publicClassRendererEvent;
|
|
24
69
|
function publicProperty(arg) {
|
|
25
70
|
return (_, context) => {
|
|
26
|
-
const
|
|
27
|
-
let name =
|
|
71
|
+
const key = String(context.name);
|
|
72
|
+
let name = key;
|
|
28
73
|
if (arg) {
|
|
29
74
|
if (typeof arg === 'string') {
|
|
30
75
|
name = arg;
|
|
@@ -41,11 +86,11 @@ function publicProperty(arg) {
|
|
|
41
86
|
(0, publish_1.publicVariable)(name, {
|
|
42
87
|
get: () => {
|
|
43
88
|
// @ts-ignore
|
|
44
|
-
return this[
|
|
89
|
+
return this[key];
|
|
45
90
|
},
|
|
46
91
|
set: (value) => {
|
|
47
92
|
// @ts-ignore
|
|
48
|
-
this[
|
|
93
|
+
this[key] = value;
|
|
49
94
|
}
|
|
50
95
|
});
|
|
51
96
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IPublishMethodArgs, IPublishPropertyArgs } from '../types';
|
|
1
|
+
import type { EventReceiver, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
@@ -57,6 +57,172 @@ export declare function publicMethod(name: string): MethodDecorator;
|
|
|
57
57
|
* @param args - publish args
|
|
58
58
|
*/
|
|
59
59
|
export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
60
|
+
/**
|
|
61
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
62
|
+
*
|
|
63
|
+
* _only for static_
|
|
64
|
+
*
|
|
65
|
+
* _experimental decorators_
|
|
66
|
+
*/
|
|
67
|
+
export declare function publicStaticMainEvent(): MethodDecorator;
|
|
68
|
+
/**
|
|
69
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
70
|
+
*
|
|
71
|
+
* _only for static_
|
|
72
|
+
*
|
|
73
|
+
* _experimental decorators_
|
|
74
|
+
* @param name - name by which the event will be accessed
|
|
75
|
+
*/
|
|
76
|
+
export declare function publicStaticMainEvent(name: string): MethodDecorator;
|
|
77
|
+
/**
|
|
78
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
79
|
+
*
|
|
80
|
+
* _only for static_
|
|
81
|
+
*
|
|
82
|
+
* _experimental decorators_
|
|
83
|
+
* @param args - publish args
|
|
84
|
+
*/
|
|
85
|
+
export declare function publicStaticMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
86
|
+
/**
|
|
87
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
88
|
+
*
|
|
89
|
+
* _only for non-static_
|
|
90
|
+
*
|
|
91
|
+
* _experimental decorators_
|
|
92
|
+
*
|
|
93
|
+
* _required `providePublic(classInstance)`_
|
|
94
|
+
*/
|
|
95
|
+
export declare function publicClassMainEvent(): MethodDecorator;
|
|
96
|
+
/**
|
|
97
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
98
|
+
*
|
|
99
|
+
* _only for non-static_
|
|
100
|
+
*
|
|
101
|
+
* _experimental decorators_
|
|
102
|
+
*
|
|
103
|
+
* _required `providePublic(classInstance)`_
|
|
104
|
+
* @param name - name by which the event will be accessed
|
|
105
|
+
*/
|
|
106
|
+
export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
107
|
+
/**
|
|
108
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
109
|
+
*
|
|
110
|
+
* _only for non-static_
|
|
111
|
+
*
|
|
112
|
+
* _experimental decorators_
|
|
113
|
+
*
|
|
114
|
+
* _required `providePublic(classInstance)`_
|
|
115
|
+
* @param args - publish args
|
|
116
|
+
*/
|
|
117
|
+
export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
118
|
+
/**
|
|
119
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
120
|
+
*
|
|
121
|
+
* _only for static_
|
|
122
|
+
*
|
|
123
|
+
* _experimental decorators_
|
|
124
|
+
*/
|
|
125
|
+
export declare function publicStaticRendererEvent(): PropertyDecorator;
|
|
126
|
+
/**
|
|
127
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
128
|
+
*
|
|
129
|
+
* _only for static_
|
|
130
|
+
*
|
|
131
|
+
* _experimental decorators_
|
|
132
|
+
* @param name - name by which the event will be accessed
|
|
133
|
+
*/
|
|
134
|
+
export declare function publicStaticRendererEvent(name: string): PropertyDecorator;
|
|
135
|
+
/**
|
|
136
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
137
|
+
*
|
|
138
|
+
* _only for static_
|
|
139
|
+
*
|
|
140
|
+
* _experimental decorators_
|
|
141
|
+
* @param receiver - linked receiver
|
|
142
|
+
*/
|
|
143
|
+
export declare function publicStaticRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
144
|
+
/**
|
|
145
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
146
|
+
*
|
|
147
|
+
* _only for static_
|
|
148
|
+
*
|
|
149
|
+
* _experimental decorators_
|
|
150
|
+
* @param name - name by which the event will be accessed
|
|
151
|
+
* @param receiver - linked receiver
|
|
152
|
+
*/
|
|
153
|
+
export declare function publicStaticRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
|
|
154
|
+
/**
|
|
155
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
156
|
+
*
|
|
157
|
+
* _only for static_
|
|
158
|
+
*
|
|
159
|
+
* _experimental decorators_
|
|
160
|
+
* @param args - publish args
|
|
161
|
+
*/
|
|
162
|
+
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
163
|
+
/**
|
|
164
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
165
|
+
*
|
|
166
|
+
* _only for static_
|
|
167
|
+
*
|
|
168
|
+
* _experimental decorators_
|
|
169
|
+
* @param args - publish args
|
|
170
|
+
*/
|
|
171
|
+
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
172
|
+
/**
|
|
173
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
174
|
+
*
|
|
175
|
+
* _only for non-static_
|
|
176
|
+
*
|
|
177
|
+
* _experimental decorators_
|
|
178
|
+
*/
|
|
179
|
+
export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
180
|
+
/**
|
|
181
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
182
|
+
*
|
|
183
|
+
* _only for non-static_
|
|
184
|
+
*
|
|
185
|
+
* _experimental decorators_
|
|
186
|
+
* @param name - name by which the event will be accessed
|
|
187
|
+
*/
|
|
188
|
+
export declare function publicClassRendererEvent(name: string): PropertyDecorator;
|
|
189
|
+
/**
|
|
190
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
191
|
+
*
|
|
192
|
+
* _only for non-static_
|
|
193
|
+
*
|
|
194
|
+
* _experimental decorators_
|
|
195
|
+
* @param receiver - linked receiver
|
|
196
|
+
*/
|
|
197
|
+
export declare function publicClassRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
198
|
+
/**
|
|
199
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
200
|
+
*
|
|
201
|
+
* _only for non-static_
|
|
202
|
+
*
|
|
203
|
+
* _experimental decorators_
|
|
204
|
+
* @param name - name by which the event will be accessed
|
|
205
|
+
* @param receiver - linked receiver
|
|
206
|
+
*/
|
|
207
|
+
export declare function publicClassRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
|
|
208
|
+
/**
|
|
209
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
210
|
+
*
|
|
211
|
+
* _only for non-static_
|
|
212
|
+
*
|
|
213
|
+
* _experimental decorators_
|
|
214
|
+
* @param args - publish args
|
|
215
|
+
*/
|
|
216
|
+
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
217
|
+
/**
|
|
218
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
219
|
+
*
|
|
220
|
+
* _only for non-static_
|
|
221
|
+
*
|
|
222
|
+
* _experimental decorators_
|
|
223
|
+
* @param args - publish args
|
|
224
|
+
*/
|
|
225
|
+
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
60
226
|
/**
|
|
61
227
|
* Makes the property available for **renderer** and **preload** processes.
|
|
62
228
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicMethod = exports.publicStaticMethod = void 0;
|
|
3
|
+
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicStaticRendererEvent = exports.publicClassMainEvent = exports.publicStaticMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
|
|
4
4
|
const publish_1 = require("./publish");
|
|
5
5
|
function publicStaticMethod(arg) {
|
|
6
6
|
return (target, key) => {
|
|
@@ -30,6 +30,67 @@ function publicMethod(arg) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
exports.publicMethod = publicMethod;
|
|
33
|
+
function publicStaticMainEvent(arg) {
|
|
34
|
+
return (target, key) => {
|
|
35
|
+
let name = String(key);
|
|
36
|
+
if (arg) {
|
|
37
|
+
if (typeof arg === 'string') {
|
|
38
|
+
name = arg;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
name = arg.name ?? String(key);
|
|
42
|
+
if (arg.scope)
|
|
43
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
target[key] = (0, publish_1.publicMainEvent)(name, target[key].bind(target));
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.publicStaticMainEvent = publicStaticMainEvent;
|
|
50
|
+
function publicClassMainEvent(arg) {
|
|
51
|
+
return (tgt, key, _) => {
|
|
52
|
+
const target = tgt;
|
|
53
|
+
const prevRegister = target.__register__ ?? (() => { });
|
|
54
|
+
target.__register__ = instance => {
|
|
55
|
+
prevRegister(instance);
|
|
56
|
+
publicStaticMainEvent(arg)(instance, key, _);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.publicClassMainEvent = publicClassMainEvent;
|
|
61
|
+
function publicStaticRendererEvent(arg) {
|
|
62
|
+
return (target, key) => {
|
|
63
|
+
let name = String(key);
|
|
64
|
+
let receiver = (v) => v;
|
|
65
|
+
if (arg) {
|
|
66
|
+
if (typeof arg === 'string') {
|
|
67
|
+
name = arg;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof arg === 'object') {
|
|
70
|
+
name = arg.name ?? String(key);
|
|
71
|
+
receiver = arg.receiver ?? receiver;
|
|
72
|
+
if (arg.scope)
|
|
73
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
receiver = arg;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
target[key] = (0, publish_1.publicRendererEvent)(name, receiver);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
exports.publicStaticRendererEvent = publicStaticRendererEvent;
|
|
83
|
+
function publicClassRendererEvent(arg) {
|
|
84
|
+
return (tgt, key) => {
|
|
85
|
+
const target = tgt;
|
|
86
|
+
const prevRegister = target.__register__ ?? (() => { });
|
|
87
|
+
target.__register__ = instance => {
|
|
88
|
+
prevRegister(instance);
|
|
89
|
+
publicStaticRendererEvent(arg)(instance, key);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
exports.publicClassRendererEvent = publicClassRendererEvent;
|
|
33
94
|
function publicStaticProperty(arg) {
|
|
34
95
|
return (target, key) => {
|
|
35
96
|
let name = String(key);
|
|
@@ -23,7 +23,9 @@ function provideFromMain(contextIsolation = true) {
|
|
|
23
23
|
},
|
|
24
24
|
provided: {
|
|
25
25
|
properties: {},
|
|
26
|
-
functions: {}
|
|
26
|
+
functions: {},
|
|
27
|
+
mainEvents: {},
|
|
28
|
+
rendererEvents: {}
|
|
27
29
|
}
|
|
28
30
|
};
|
|
29
31
|
info.functions.forEach(funcName => {
|
|
@@ -34,6 +36,40 @@ function provideFromMain(contextIsolation = true) {
|
|
|
34
36
|
enumerable: true
|
|
35
37
|
});
|
|
36
38
|
});
|
|
39
|
+
info.rendererEvents.forEach(rendererEventName => {
|
|
40
|
+
Object.defineProperty(provider.provided.rendererEvents, rendererEventName, {
|
|
41
|
+
value(arg) {
|
|
42
|
+
const emitChannel = enums_1.IPCChannel.rendererEventEmit + rendererEventName;
|
|
43
|
+
if (arg instanceof Promise) {
|
|
44
|
+
arg
|
|
45
|
+
.then(value => electron_1.ipcRenderer.send(emitChannel, { value }))
|
|
46
|
+
.catch(reason => electron_1.ipcRenderer.send(emitChannel, { error: String(reason) }));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
electron_1.ipcRenderer.send(emitChannel, { value: arg });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
enumerable: true
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
info.mainEvents.forEach(mainEventName => {
|
|
56
|
+
Object.defineProperty(provider.provided.mainEvents, mainEventName, {
|
|
57
|
+
value(type, handler) {
|
|
58
|
+
const listener = (_, result) => handler(result);
|
|
59
|
+
const emitChannel = enums_1.IPCChannel.mainEventEmit + mainEventName;
|
|
60
|
+
if (type === 'on') {
|
|
61
|
+
electron_1.ipcRenderer.on(emitChannel, listener);
|
|
62
|
+
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + mainEventName);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
electron_1.ipcRenderer.once(emitChannel, listener);
|
|
66
|
+
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + mainEventName);
|
|
67
|
+
}
|
|
68
|
+
return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
|
|
69
|
+
},
|
|
70
|
+
enumerable: true
|
|
71
|
+
});
|
|
72
|
+
});
|
|
37
73
|
info.properties.forEach(propName => {
|
|
38
74
|
Object.defineProperty(provider.provided.properties, propName, {
|
|
39
75
|
get() {
|
package/cjs/scripts/provider.js
CHANGED
|
@@ -5,7 +5,7 @@ function errorHandler(error, channel) {
|
|
|
5
5
|
console.error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
6
6
|
}
|
|
7
7
|
function createProvider(args) {
|
|
8
|
-
const { info, scope, getVariable, setVariable, callFunction, waitPromise } = args;
|
|
8
|
+
const { info, scope, getVariable, setVariable, callFunction, handleMainEvent, waitPromise, emitRendererEvent } = args;
|
|
9
9
|
const target = {
|
|
10
10
|
as: () => proxy
|
|
11
11
|
};
|
|
@@ -31,6 +31,63 @@ function createProvider(args) {
|
|
|
31
31
|
enumerable: true
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
+
info.rendererEvents.forEach(rendererEventName => {
|
|
35
|
+
if (!info.scopes[rendererEventName].has(scope))
|
|
36
|
+
return;
|
|
37
|
+
Object.defineProperty(target, rendererEventName, {
|
|
38
|
+
get() {
|
|
39
|
+
return (arg) => emitRendererEvent(rendererEventName, arg);
|
|
40
|
+
},
|
|
41
|
+
set() {
|
|
42
|
+
throw new Error(`Function '${rendererEventName}' is readonly`);
|
|
43
|
+
},
|
|
44
|
+
enumerable: true
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
info.mainEvents.forEach(mainEventName => {
|
|
48
|
+
if (!info.scopes[mainEventName].has(scope))
|
|
49
|
+
return;
|
|
50
|
+
const eventNameOn = `on${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
51
|
+
const eventNameOnce = `once${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
52
|
+
Object.defineProperty(target, eventNameOn, {
|
|
53
|
+
get() {
|
|
54
|
+
return (handler) => {
|
|
55
|
+
return handleMainEvent(mainEventName, 'on', (result) => {
|
|
56
|
+
if (result.error) {
|
|
57
|
+
errorHandler(result.error, mainEventName);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (result.promiseChannel)
|
|
61
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
62
|
+
handler(result.value);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
set() {
|
|
67
|
+
throw new Error(`Function '${eventNameOn}' is readonly`);
|
|
68
|
+
},
|
|
69
|
+
enumerable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(target, eventNameOnce, {
|
|
72
|
+
get() {
|
|
73
|
+
return (handler) => {
|
|
74
|
+
return handleMainEvent(mainEventName, 'once', (result) => {
|
|
75
|
+
if (result.error) {
|
|
76
|
+
errorHandler(result.error, mainEventName);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (result.promiseChannel)
|
|
80
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
81
|
+
handler(result.value);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
set() {
|
|
86
|
+
throw new Error(`Function '${eventNameOnce}' is readonly`);
|
|
87
|
+
},
|
|
88
|
+
enumerable: true
|
|
89
|
+
});
|
|
90
|
+
});
|
|
34
91
|
info.properties.forEach(propName => {
|
|
35
92
|
if (!info.scopes[propName].has(scope))
|
|
36
93
|
return;
|
package/cjs/scripts/publish.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { Access, Scope } from '../enums';
|
|
2
|
-
import type { PublicFunction, PublicProperty } from '../types';
|
|
2
|
+
import type { EventEmitter, PublicFunction, PublicProperty, RendererEvent } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
5
|
+
*
|
|
6
|
+
* @param name - name by which the event will be accessed
|
|
7
|
+
* @param scopes - event scopes
|
|
8
|
+
*/
|
|
9
|
+
export declare function publicMainEvent<Emitter extends EventEmitter>(name: string, receiver?: Emitter, scopes?: Scope[]): (...args: Parameters<Emitter>) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
12
|
+
*
|
|
13
|
+
* @param name - name by which the event will be accessed
|
|
14
|
+
* @param scopes - event scopes
|
|
15
|
+
*/
|
|
16
|
+
export declare function publicRendererEvent<I = undefined, O = I>(name: string, receiver?: (v?: I) => O, scopes?: Scope[]): RendererEvent<O>;
|
|
3
17
|
/**
|
|
4
18
|
* Makes the function available for **renderer** and **preload** processes.
|
|
5
19
|
*
|
package/cjs/scripts/publish.js
CHANGED
|
@@ -1,15 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addAccess = exports.addScope = exports.publicVariable = exports.publicFunction = void 0;
|
|
3
|
+
exports.addAccess = exports.addScope = exports.publicVariable = exports.publicFunction = exports.publicRendererEvent = exports.publicMainEvent = void 0;
|
|
4
4
|
const electron_1 = require("electron");
|
|
5
5
|
const enums_1 = require("../enums");
|
|
6
6
|
const publicInfo = {
|
|
7
7
|
properties: new Set(),
|
|
8
8
|
functions: new Set(),
|
|
9
|
+
mainEvents: new Set(),
|
|
10
|
+
rendererEvents: new Set(),
|
|
9
11
|
accesses: {},
|
|
10
12
|
scopes: {}
|
|
11
13
|
};
|
|
12
14
|
electron_1.ipcMain.on(enums_1.IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
15
|
+
/**
|
|
16
|
+
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
17
|
+
*
|
|
18
|
+
* @param name - name by which the event will be accessed
|
|
19
|
+
* @param scopes - event scopes
|
|
20
|
+
*/
|
|
21
|
+
function publicMainEvent(name, receiver = ((v = undefined) => v), scopes = [enums_1.Scope.preload, enums_1.Scope.renderer]) {
|
|
22
|
+
const { mainEvents } = publicInfo;
|
|
23
|
+
const mainEmitChannel = enums_1.IPCChannel.mainEventEmit + name;
|
|
24
|
+
const mainHandleChannel = enums_1.IPCChannel.mainEventOn + name;
|
|
25
|
+
const mainHandleChannelOnce = enums_1.IPCChannel.mainEventOnce + name;
|
|
26
|
+
let senders = [];
|
|
27
|
+
let sendersOnce = [];
|
|
28
|
+
mainEvents.add(name);
|
|
29
|
+
if (!publicInfo.scopes[name])
|
|
30
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
31
|
+
electron_1.ipcMain.removeAllListeners(mainHandleChannel);
|
|
32
|
+
electron_1.ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
33
|
+
electron_1.ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
34
|
+
electron_1.ipcMain.on(mainHandleChannelOnce, ({ sender }) => !sendersOnce.includes(sender) && sendersOnce.push(sender));
|
|
35
|
+
return (...args) => {
|
|
36
|
+
function filterSenders() {
|
|
37
|
+
senders = senders.filter(sender => !sender.isDestroyed());
|
|
38
|
+
sendersOnce = sendersOnce.filter(sender => !sender.isDestroyed());
|
|
39
|
+
}
|
|
40
|
+
filterSenders();
|
|
41
|
+
const allSenders = [...senders, ...sendersOnce];
|
|
42
|
+
try {
|
|
43
|
+
const result = receiver(...args);
|
|
44
|
+
if (result instanceof Promise) {
|
|
45
|
+
result
|
|
46
|
+
.then(value => {
|
|
47
|
+
filterSenders();
|
|
48
|
+
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { value }));
|
|
49
|
+
sendersOnce = [];
|
|
50
|
+
})
|
|
51
|
+
.catch(reason => {
|
|
52
|
+
filterSenders();
|
|
53
|
+
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { error: String(reason) }));
|
|
54
|
+
sendersOnce = [];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
allSenders.forEach(sender => sender.send(mainEmitChannel, { value: result }));
|
|
59
|
+
sendersOnce = [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
allSenders.forEach(sender => sender.send(mainEmitChannel, { error: String(error) }));
|
|
64
|
+
sendersOnce = [];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.publicMainEvent = publicMainEvent;
|
|
69
|
+
/**
|
|
70
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
71
|
+
*
|
|
72
|
+
* @param name - name by which the event will be accessed
|
|
73
|
+
* @param scopes - event scopes
|
|
74
|
+
*/
|
|
75
|
+
function publicRendererEvent(name, receiver = ((v = undefined) => v), scopes = [enums_1.Scope.preload, enums_1.Scope.renderer]) {
|
|
76
|
+
if (name.startsWith('on')) {
|
|
77
|
+
name = name.replace('on', '');
|
|
78
|
+
name = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
79
|
+
}
|
|
80
|
+
const { rendererEvents } = publicInfo;
|
|
81
|
+
const rendererEmitChannel = enums_1.IPCChannel.rendererEventEmit + name;
|
|
82
|
+
const handlers = new Set();
|
|
83
|
+
const handlersOnce = new Set();
|
|
84
|
+
rendererEvents.add(name);
|
|
85
|
+
if (!publicInfo.scopes[name])
|
|
86
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
87
|
+
electron_1.ipcMain.removeAllListeners(rendererEmitChannel);
|
|
88
|
+
electron_1.ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
89
|
+
if (result.error)
|
|
90
|
+
throw new Error(result.error);
|
|
91
|
+
const converted = receiver(result.value);
|
|
92
|
+
handlers.forEach(handler => handler(converted));
|
|
93
|
+
handlersOnce.forEach(handler => handler(converted));
|
|
94
|
+
handlersOnce.clear();
|
|
95
|
+
});
|
|
96
|
+
return (handler, isOnce = false) => {
|
|
97
|
+
if (isOnce) {
|
|
98
|
+
handlersOnce.add(handler);
|
|
99
|
+
return () => handlersOnce.delete(handler);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
handlers.add(handler);
|
|
103
|
+
return () => handlers.delete(handler);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
exports.publicRendererEvent = publicRendererEvent;
|
|
13
108
|
/**
|
|
14
109
|
* Makes the function available for **renderer** and **preload** processes.
|
|
15
110
|
*
|
package/cjs/types.d.ts
CHANGED
|
@@ -18,6 +18,15 @@ export interface IPublishMethodArgs {
|
|
|
18
18
|
name?: string;
|
|
19
19
|
scope?: Scope;
|
|
20
20
|
}
|
|
21
|
+
export interface IPublishMainEventArgs {
|
|
22
|
+
name?: string;
|
|
23
|
+
scope?: Scope;
|
|
24
|
+
}
|
|
25
|
+
export interface IPublishRendererEventArgs {
|
|
26
|
+
name?: string;
|
|
27
|
+
scope?: Scope;
|
|
28
|
+
receiver?: EventReceiver;
|
|
29
|
+
}
|
|
21
30
|
export interface IPublishPropertyArgs {
|
|
22
31
|
name?: string;
|
|
23
32
|
scope?: Scope;
|
|
@@ -26,6 +35,8 @@ export interface IPublishPropertyArgs {
|
|
|
26
35
|
export interface ICreateProviderArgs {
|
|
27
36
|
info: IInfo;
|
|
28
37
|
scope: Scope;
|
|
38
|
+
handleMainEvent(name: string, type: 'on' | 'once', handler: EventHandler<IIPCResult>): EventUnsubscriber;
|
|
39
|
+
emitRendererEvent(name: string, arg: any): void;
|
|
29
40
|
callFunction(name: string, ...args: any[]): IIPCResult;
|
|
30
41
|
getVariable(name: string): IIPCResult;
|
|
31
42
|
setVariable(name: string, value: any): IIPCResult | undefined;
|
|
@@ -33,6 +44,12 @@ export interface ICreateProviderArgs {
|
|
|
33
44
|
}
|
|
34
45
|
export type Scopes = Record<string, Set<Scope>>;
|
|
35
46
|
export type Accesses = Record<string, Set<Access>>;
|
|
47
|
+
export type RendererEvent<T = undefined> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
48
|
+
export type MainEvent<T = undefined> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
49
|
+
export type EventEmitter = (...args: any[]) => any;
|
|
50
|
+
export type EventReceiver<I = any, O = any> = (input: I) => O;
|
|
51
|
+
export type EventUnsubscriber = () => void;
|
|
52
|
+
export type EventHandler<T> = (result: T) => void;
|
|
36
53
|
export interface IRendererPublic {
|
|
37
54
|
__register__?(instance: any): void;
|
|
38
55
|
}
|
|
@@ -41,6 +58,8 @@ export interface IProvider {
|
|
|
41
58
|
waitPromise(name: string, resolve: (value: any) => void, reject?: (reason?: any) => void): void;
|
|
42
59
|
provided: {
|
|
43
60
|
functions: Record<string, (...args: any[]) => IIPCResult>;
|
|
61
|
+
mainEvents: Record<string, (type: 'on' | 'once', handler: EventHandler<IIPCResult>) => EventUnsubscriber>;
|
|
62
|
+
rendererEvents: Record<string, (arg: any) => void>;
|
|
44
63
|
properties: Record<string, IIPCResult>;
|
|
45
64
|
};
|
|
46
65
|
}
|
|
@@ -52,6 +71,8 @@ export type PublicProperty = {
|
|
|
52
71
|
export interface IInfo {
|
|
53
72
|
properties: Set<string>;
|
|
54
73
|
functions: Set<string>;
|
|
74
|
+
mainEvents: Set<string>;
|
|
75
|
+
rendererEvents: Set<string>;
|
|
55
76
|
scopes: Scopes;
|
|
56
77
|
accesses: Accesses;
|
|
57
78
|
}
|
package/{lib → esm}/enums.d.ts
RENAMED
|
@@ -9,7 +9,11 @@ export declare enum Scope {
|
|
|
9
9
|
export declare enum IPCChannel {
|
|
10
10
|
getPublicInfo = "GET_PUBLIC_INFO",
|
|
11
11
|
functionCall = "FUNCTION_CALL_",
|
|
12
|
+
mainEventOn = "MAIN_EVENT_ON_",
|
|
13
|
+
mainEventOnce = "MAIN_EVENT_ONCE_",
|
|
14
|
+
mainEventEmit = "MAIN_EVENT_EMIT_",
|
|
12
15
|
propertyGet = "PROPERTY_GET_",
|
|
13
16
|
propertySet = "PROPERTY_SET_",
|
|
14
|
-
promisePostfix = "_PROMISE"
|
|
17
|
+
promisePostfix = "_PROMISE",
|
|
18
|
+
rendererEventEmit = "RENDERER_EMIT_"
|
|
15
19
|
}
|
package/{lib → esm}/enums.js
RENAMED
|
@@ -12,7 +12,11 @@ export var IPCChannel;
|
|
|
12
12
|
(function (IPCChannel) {
|
|
13
13
|
IPCChannel["getPublicInfo"] = "GET_PUBLIC_INFO";
|
|
14
14
|
IPCChannel["functionCall"] = "FUNCTION_CALL_";
|
|
15
|
+
IPCChannel["mainEventOn"] = "MAIN_EVENT_ON_";
|
|
16
|
+
IPCChannel["mainEventOnce"] = "MAIN_EVENT_ONCE_";
|
|
17
|
+
IPCChannel["mainEventEmit"] = "MAIN_EVENT_EMIT_";
|
|
15
18
|
IPCChannel["propertyGet"] = "PROPERTY_GET_";
|
|
16
19
|
IPCChannel["propertySet"] = "PROPERTY_SET_";
|
|
17
20
|
IPCChannel["promisePostfix"] = "_PROMISE";
|
|
21
|
+
IPCChannel["rendererEventEmit"] = "RENDERER_EMIT_";
|
|
18
22
|
})(IPCChannel || (IPCChannel = {}));
|
package/esm/exp.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMainEvent, publicStaticMethod, publicStaticProperty, publicStaticRendererEvent } from './scripts/oldDecorators';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/esm/exp.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMainEvent, publicStaticMethod, publicStaticProperty, publicStaticRendererEvent } from './scripts/oldDecorators';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|