emr-bridge 1.4.1 → 1.6.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/README.md +20 -20
- package/cjs/enums.js +3 -3
- package/cjs/exp.d.ts +1 -1
- package/cjs/exp.js +1 -3
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +16 -0
- package/cjs/main.d.ts +4 -0
- package/cjs/main.js +18 -0
- package/cjs/scripts/Bridge.d.ts +2 -1
- package/cjs/scripts/Bridge.js +44 -28
- package/cjs/scripts/Main.d.ts +2 -1
- package/cjs/scripts/Main.js +71 -52
- package/cjs/scripts/newDecorators.d.ts +13 -6
- package/cjs/scripts/newDecorators.js +3 -3
- package/cjs/scripts/oldDecorators.d.ts +13 -117
- package/cjs/scripts/oldDecorators.js +30 -42
- package/cjs/scripts/preloadProvider.js +29 -16
- package/cjs/scripts/provider.js +86 -133
- package/cjs/scripts/publish.d.ts +9 -5
- package/cjs/scripts/publish.js +59 -33
- package/cjs/types.d.ts +10 -10
- package/esm/exp.d.ts +1 -1
- package/esm/exp.js +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/main.d.ts +4 -0
- package/esm/main.js +3 -0
- package/esm/scripts/Bridge.d.ts +2 -1
- package/esm/scripts/Bridge.js +44 -28
- package/esm/scripts/Main.d.ts +2 -1
- package/esm/scripts/Main.js +71 -52
- package/esm/scripts/newDecorators.d.ts +13 -6
- package/esm/scripts/newDecorators.js +3 -3
- package/esm/scripts/oldDecorators.d.ts +13 -117
- package/esm/scripts/oldDecorators.js +29 -39
- package/esm/scripts/preloadProvider.js +13 -3
- package/esm/scripts/provider.js +87 -134
- package/esm/scripts/publish.d.ts +9 -5
- package/esm/scripts/publish.js +44 -21
- package/esm/types.d.ts +10 -10
- package/package.json +3 -35
|
@@ -3,7 +3,6 @@ import type { EventReceiver, IPublishMainEventArgs, IPublishMethodArgs, IPublish
|
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
5
5
|
* _only for static_
|
|
6
|
-
*
|
|
7
6
|
* _experimental decorators_
|
|
8
7
|
*/
|
|
9
8
|
export declare function publicStaticMethod(): MethodDecorator;
|
|
@@ -11,8 +10,8 @@ export declare function publicStaticMethod(): MethodDecorator;
|
|
|
11
10
|
* Makes the method available for **renderer** and **preload** processes.
|
|
12
11
|
*
|
|
13
12
|
* _only for static_
|
|
14
|
-
*
|
|
15
13
|
* _experimental decorators_
|
|
14
|
+
*
|
|
16
15
|
* @param name - name by which the method will be accessed
|
|
17
16
|
*/
|
|
18
17
|
export declare function publicStaticMethod(name: string): MethodDecorator;
|
|
@@ -20,8 +19,8 @@ export declare function publicStaticMethod(name: string): MethodDecorator;
|
|
|
20
19
|
* Makes the method available for **renderer** and **preload** processes.
|
|
21
20
|
*
|
|
22
21
|
* _only for static_
|
|
23
|
-
*
|
|
24
22
|
* _experimental decorators_
|
|
23
|
+
*
|
|
25
24
|
* @param args - publish args
|
|
26
25
|
*/
|
|
27
26
|
export declare function publicStaticMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
@@ -29,9 +28,7 @@ export declare function publicStaticMethod(args: IPublishMethodArgs): MethodDeco
|
|
|
29
28
|
* Makes the method available for **renderer** and **preload** processes.
|
|
30
29
|
*
|
|
31
30
|
* _only for non-static_
|
|
32
|
-
*
|
|
33
31
|
* _experimental decorators_
|
|
34
|
-
*
|
|
35
32
|
* _required `providePublic(classInstance)`_
|
|
36
33
|
*/
|
|
37
34
|
export declare function publicMethod(): MethodDecorator;
|
|
@@ -39,10 +36,9 @@ export declare function publicMethod(): MethodDecorator;
|
|
|
39
36
|
* Makes the method available for **renderer** and **preload** processes.
|
|
40
37
|
*
|
|
41
38
|
* _only for non-static_
|
|
42
|
-
*
|
|
43
39
|
* _experimental decorators_
|
|
44
|
-
*
|
|
45
40
|
* _required `providePublic(classInstance)`_
|
|
41
|
+
*
|
|
46
42
|
* @param name - name by which the method will be accessed
|
|
47
43
|
*/
|
|
48
44
|
export declare function publicMethod(name: string): MethodDecorator;
|
|
@@ -50,46 +46,17 @@ export declare function publicMethod(name: string): MethodDecorator;
|
|
|
50
46
|
* Makes the method available for **renderer** and **preload** processes.
|
|
51
47
|
*
|
|
52
48
|
* _only for non-static_
|
|
53
|
-
*
|
|
54
49
|
* _experimental decorators_
|
|
55
|
-
*
|
|
56
50
|
* _required `providePublic(classInstance)`_
|
|
57
|
-
* @param args - publish args
|
|
58
|
-
*/
|
|
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
51
|
*
|
|
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
52
|
* @param args - publish args
|
|
84
53
|
*/
|
|
85
|
-
export declare function
|
|
54
|
+
export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
86
55
|
/**
|
|
87
56
|
* Makes the event available for **renderer** and **preload** processes.
|
|
88
57
|
*
|
|
89
58
|
* _only for non-static_
|
|
90
|
-
*
|
|
91
59
|
* _experimental decorators_
|
|
92
|
-
*
|
|
93
60
|
* _required `providePublic(classInstance)`_
|
|
94
61
|
*/
|
|
95
62
|
export declare function publicClassMainEvent(): MethodDecorator;
|
|
@@ -97,10 +64,9 @@ export declare function publicClassMainEvent(): MethodDecorator;
|
|
|
97
64
|
* Makes the event available for **renderer** and **preload** processes.
|
|
98
65
|
*
|
|
99
66
|
* _only for non-static_
|
|
100
|
-
*
|
|
101
67
|
* _experimental decorators_
|
|
102
|
-
*
|
|
103
68
|
* _required `providePublic(classInstance)`_
|
|
69
|
+
*
|
|
104
70
|
* @param name - name by which the event will be accessed
|
|
105
71
|
*/
|
|
106
72
|
export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
@@ -108,72 +74,16 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
|
108
74
|
* Makes the event available for **renderer** and **preload** processes.
|
|
109
75
|
*
|
|
110
76
|
* _only for non-static_
|
|
111
|
-
*
|
|
112
77
|
* _experimental decorators_
|
|
113
|
-
*
|
|
114
78
|
* _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
79
|
*
|
|
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
80
|
* @param args - publish args
|
|
170
81
|
*/
|
|
171
|
-
export declare function
|
|
82
|
+
export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
172
83
|
/**
|
|
173
84
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
174
85
|
*
|
|
175
86
|
* _only for non-static_
|
|
176
|
-
*
|
|
177
87
|
* _experimental decorators_
|
|
178
88
|
*/
|
|
179
89
|
export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
@@ -181,8 +91,8 @@ export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
|
181
91
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
182
92
|
*
|
|
183
93
|
* _only for non-static_
|
|
184
|
-
*
|
|
185
94
|
* _experimental decorators_
|
|
95
|
+
*
|
|
186
96
|
* @param name - name by which the event will be accessed
|
|
187
97
|
*/
|
|
188
98
|
export declare function publicClassRendererEvent(name: string): PropertyDecorator;
|
|
@@ -190,8 +100,8 @@ export declare function publicClassRendererEvent(name: string): PropertyDecorato
|
|
|
190
100
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
191
101
|
*
|
|
192
102
|
* _only for non-static_
|
|
193
|
-
*
|
|
194
103
|
* _experimental decorators_
|
|
104
|
+
*
|
|
195
105
|
* @param receiver - linked receiver
|
|
196
106
|
*/
|
|
197
107
|
export declare function publicClassRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
@@ -199,8 +109,8 @@ export declare function publicClassRendererEvent(receiver: EventReceiver): Prope
|
|
|
199
109
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
200
110
|
*
|
|
201
111
|
* _only for non-static_
|
|
202
|
-
*
|
|
203
112
|
* _experimental decorators_
|
|
113
|
+
*
|
|
204
114
|
* @param name - name by which the event will be accessed
|
|
205
115
|
* @param receiver - linked receiver
|
|
206
116
|
*/
|
|
@@ -209,17 +119,8 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
209
119
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
210
120
|
*
|
|
211
121
|
* _only for non-static_
|
|
212
|
-
*
|
|
213
122
|
* _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
123
|
*
|
|
222
|
-
* _experimental decorators_
|
|
223
124
|
* @param args - publish args
|
|
224
125
|
*/
|
|
225
126
|
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
@@ -227,7 +128,6 @@ export declare function publicClassRendererEvent(args: IPublishRendererEventArgs
|
|
|
227
128
|
* Makes the property available for **renderer** and **preload** processes.
|
|
228
129
|
*
|
|
229
130
|
* _only for static_
|
|
230
|
-
*
|
|
231
131
|
* _experimental decorators_
|
|
232
132
|
*/
|
|
233
133
|
export declare function publicStaticProperty(): PropertyDecorator;
|
|
@@ -235,8 +135,8 @@ export declare function publicStaticProperty(): PropertyDecorator;
|
|
|
235
135
|
* Makes the property available for **renderer** and **preload** processes.
|
|
236
136
|
*
|
|
237
137
|
* _only for static_
|
|
238
|
-
*
|
|
239
138
|
* _experimental decorators_
|
|
139
|
+
*
|
|
240
140
|
* @param name - name by which the property will be accessed
|
|
241
141
|
*/
|
|
242
142
|
export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
@@ -244,8 +144,8 @@ export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
|
244
144
|
* Makes the property available for **renderer** and **preload** processes.
|
|
245
145
|
*
|
|
246
146
|
* _only for static_
|
|
247
|
-
*
|
|
248
147
|
* _experimental decorators_
|
|
148
|
+
*
|
|
249
149
|
* @param args - publish args
|
|
250
150
|
*/
|
|
251
151
|
export declare function publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
@@ -253,9 +153,7 @@ export declare function publicStaticProperty(args: IPublishPropertyArgs): Proper
|
|
|
253
153
|
* Makes the property available for **renderer** and **preload** processes.
|
|
254
154
|
*
|
|
255
155
|
* _only for non-static_
|
|
256
|
-
*
|
|
257
156
|
* _experimental decorators_
|
|
258
|
-
*
|
|
259
157
|
* _required `providePublic(classInstance)`_
|
|
260
158
|
*/
|
|
261
159
|
export declare function publicProperty(): PropertyDecorator;
|
|
@@ -263,10 +161,9 @@ export declare function publicProperty(): PropertyDecorator;
|
|
|
263
161
|
* Makes the property available for **renderer** and **preload** processes.
|
|
264
162
|
*
|
|
265
163
|
* _only for non-static_
|
|
266
|
-
*
|
|
267
164
|
* _experimental decorators_
|
|
268
|
-
*
|
|
269
165
|
* _required `providePublic(classInstance)`_
|
|
166
|
+
*
|
|
270
167
|
* @param name - name by which the property will be accessed
|
|
271
168
|
*/
|
|
272
169
|
export declare function publicProperty(name: string): PropertyDecorator;
|
|
@@ -274,10 +171,9 @@ export declare function publicProperty(name: string): PropertyDecorator;
|
|
|
274
171
|
* Makes the property available for **renderer** and **preload** processes.
|
|
275
172
|
*
|
|
276
173
|
* _only for non-static_
|
|
277
|
-
*
|
|
278
174
|
* _experimental decorators_
|
|
279
|
-
*
|
|
280
175
|
* _required `providePublic(classInstance)`_
|
|
176
|
+
*
|
|
281
177
|
* @param args - publish args
|
|
282
178
|
*/
|
|
283
179
|
export declare function publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.
|
|
3
|
+
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
|
|
4
4
|
const publish_1 = require("./publish");
|
|
5
5
|
function publicStaticMethod(arg) {
|
|
6
6
|
return (target, key) => {
|
|
@@ -30,63 +30,51 @@ 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
33
|
function publicClassMainEvent(arg) {
|
|
51
34
|
return (tgt, key, _) => {
|
|
52
35
|
const target = tgt;
|
|
53
36
|
const prevRegister = target.__register__ ?? (() => { });
|
|
54
37
|
target.__register__ = instance => {
|
|
55
38
|
prevRegister(instance);
|
|
56
|
-
|
|
39
|
+
let name = String(key);
|
|
40
|
+
if (arg) {
|
|
41
|
+
if (typeof arg === 'string') {
|
|
42
|
+
name = arg;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
name = arg.name ?? String(key);
|
|
46
|
+
if (arg.scope)
|
|
47
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
instance[key] = (0, publish_1.publicMainEvent)(name, instance[key].bind(instance));
|
|
57
51
|
};
|
|
58
52
|
};
|
|
59
53
|
}
|
|
60
54
|
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
55
|
function publicClassRendererEvent(arg) {
|
|
84
56
|
return (tgt, key) => {
|
|
85
57
|
const target = tgt;
|
|
86
58
|
const prevRegister = target.__register__ ?? (() => { });
|
|
87
59
|
target.__register__ = instance => {
|
|
88
60
|
prevRegister(instance);
|
|
89
|
-
|
|
61
|
+
let name = String(key);
|
|
62
|
+
let receiver = (v) => v;
|
|
63
|
+
if (arg) {
|
|
64
|
+
if (typeof arg === 'string') {
|
|
65
|
+
name = arg;
|
|
66
|
+
}
|
|
67
|
+
else if (typeof arg === 'object') {
|
|
68
|
+
name = arg.name ?? String(key);
|
|
69
|
+
receiver = arg.procFn ?? receiver;
|
|
70
|
+
if (arg.scope)
|
|
71
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
receiver = arg;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
instance[key] = (0, publish_1.publicRendererEvent)(name, receiver);
|
|
90
78
|
};
|
|
91
79
|
};
|
|
92
80
|
}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const electron_1 = require("electron");
|
|
6
|
+
const electron_1 = __importDefault(require("electron"));
|
|
4
7
|
const enums_1 = require("../enums");
|
|
5
|
-
|
|
8
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
9
|
+
let mayThrowError = () => { };
|
|
10
|
+
if (typeof window === 'undefined') {
|
|
11
|
+
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in main process.'); };
|
|
12
|
+
}
|
|
13
|
+
else if (!electron_1.default.contextBridge) {
|
|
14
|
+
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in renderer process.'); };
|
|
15
|
+
}
|
|
6
16
|
/**
|
|
7
17
|
* Sets access to main from renderer
|
|
8
18
|
*
|
|
9
19
|
* @param contextIsolation - _default_: `true`
|
|
10
20
|
*/
|
|
11
21
|
function provideFromMain(contextIsolation = true) {
|
|
22
|
+
mayThrowError();
|
|
23
|
+
const { contextBridge, ipcRenderer } = electron_1.default;
|
|
24
|
+
const info = ipcRenderer.sendSync(enums_1.IPCChannel.getPublicInfo);
|
|
12
25
|
const provider = {
|
|
13
26
|
getInfo() {
|
|
14
27
|
return info;
|
|
15
28
|
},
|
|
16
29
|
waitPromise(channel, resolve, reject) {
|
|
17
|
-
|
|
30
|
+
ipcRenderer.once(channel, (_, result) => {
|
|
18
31
|
if (result.error)
|
|
19
32
|
reject?.(result.error);
|
|
20
33
|
else
|
|
@@ -25,12 +38,12 @@ function provideFromMain(contextIsolation = true) {
|
|
|
25
38
|
properties: {},
|
|
26
39
|
functions: {},
|
|
27
40
|
mainEvents: {},
|
|
28
|
-
rendererEvents: {}
|
|
41
|
+
rendererEvents: {},
|
|
29
42
|
}
|
|
30
43
|
};
|
|
31
44
|
info.functions.forEach(funcName => {
|
|
32
45
|
provider.provided.functions[funcName] = (...args) => {
|
|
33
|
-
return
|
|
46
|
+
return ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + funcName, ...args);
|
|
34
47
|
};
|
|
35
48
|
});
|
|
36
49
|
info.rendererEvents.forEach(eventName => {
|
|
@@ -38,11 +51,11 @@ function provideFromMain(contextIsolation = true) {
|
|
|
38
51
|
const emitChannel = enums_1.IPCChannel.rendererEventEmit + eventName;
|
|
39
52
|
if (arg instanceof Promise) {
|
|
40
53
|
arg
|
|
41
|
-
.then(value =>
|
|
42
|
-
.catch(reason =>
|
|
54
|
+
.then(value => ipcRenderer.send(emitChannel, { value }))
|
|
55
|
+
.catch(reason => ipcRenderer.send(emitChannel, { error: String(reason) }));
|
|
43
56
|
}
|
|
44
57
|
else {
|
|
45
|
-
|
|
58
|
+
ipcRenderer.send(emitChannel, { value: arg });
|
|
46
59
|
}
|
|
47
60
|
};
|
|
48
61
|
});
|
|
@@ -51,28 +64,28 @@ function provideFromMain(contextIsolation = true) {
|
|
|
51
64
|
const listener = (_, result) => handler(result);
|
|
52
65
|
const emitChannel = enums_1.IPCChannel.mainEventEmit + eventName;
|
|
53
66
|
if (type === 'on') {
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
ipcRenderer.on(emitChannel, listener);
|
|
68
|
+
ipcRenderer.send(enums_1.IPCChannel.mainEventOn + eventName);
|
|
56
69
|
}
|
|
57
70
|
else {
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
ipcRenderer.once(emitChannel, listener);
|
|
72
|
+
ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + eventName);
|
|
60
73
|
}
|
|
61
|
-
return () =>
|
|
74
|
+
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
62
75
|
};
|
|
63
76
|
});
|
|
64
77
|
info.properties.forEach(propName => {
|
|
65
78
|
provider.provided.properties[propName] = {
|
|
66
79
|
get() {
|
|
67
|
-
return
|
|
80
|
+
return ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + propName);
|
|
68
81
|
},
|
|
69
82
|
set(value) {
|
|
70
|
-
|
|
83
|
+
ipcRenderer.sendSync(enums_1.IPCChannel.propertySet + propName, value);
|
|
71
84
|
}
|
|
72
85
|
};
|
|
73
86
|
});
|
|
74
87
|
if (contextIsolation)
|
|
75
|
-
|
|
88
|
+
contextBridge.exposeInMainWorld('__provider__', provider);
|
|
76
89
|
else
|
|
77
90
|
window.__provider__ = provider;
|
|
78
91
|
}
|