emr-bridge 1.5.0 → 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/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 -27
- package/cjs/scripts/Main.d.ts +2 -1
- package/cjs/scripts/Main.js +71 -51
- package/cjs/scripts/newDecorators.d.ts +13 -6
- package/cjs/scripts/newDecorators.js +1 -1
- package/cjs/scripts/oldDecorators.d.ts +13 -37
- package/cjs/scripts/oldDecorators.js +1 -1
- package/cjs/scripts/preloadProvider.js +28 -15
- package/cjs/scripts/publish.d.ts +9 -5
- package/cjs/scripts/publish.js +40 -18
- package/cjs/types.d.ts +8 -8
- 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 -27
- package/esm/scripts/Main.d.ts +2 -1
- package/esm/scripts/Main.js +71 -51
- package/esm/scripts/newDecorators.d.ts +13 -6
- package/esm/scripts/newDecorators.js +1 -1
- package/esm/scripts/oldDecorators.d.ts +13 -37
- package/esm/scripts/oldDecorators.js +1 -1
- package/esm/scripts/preloadProvider.js +12 -2
- package/esm/scripts/publish.d.ts +9 -5
- package/esm/scripts/publish.js +25 -6
- package/esm/types.d.ts +8 -8
- package/package.json +3 -35
package/esm/scripts/Main.d.ts
CHANGED
package/esm/scripts/Main.js
CHANGED
|
@@ -1,60 +1,80 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Electron from 'electron';
|
|
2
2
|
import { IPCChannel, Scope } from '../enums';
|
|
3
3
|
import createProvider from './provider';
|
|
4
|
-
const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
|
|
5
|
-
if (!info)
|
|
6
|
-
throw new Error('Public methods from main is not provided');
|
|
7
4
|
/**
|
|
8
5
|
* Bridge between `preload` and `main` processes.
|
|
9
6
|
*
|
|
10
7
|
* _only for preload process_
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
handleMainEvent(name, type, handler) {
|
|
18
|
-
const listener = (_, result) => handler(result);
|
|
19
|
-
const emitChannel = IPCChannel.mainEventEmit + name;
|
|
20
|
-
if (type === 'on') {
|
|
21
|
-
ipcRenderer.send(IPCChannel.mainEventOn + name);
|
|
22
|
-
ipcRenderer.on(emitChannel, listener);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
ipcRenderer.send(IPCChannel.mainEventOnce + name);
|
|
26
|
-
ipcRenderer.once(emitChannel, listener);
|
|
27
|
-
}
|
|
28
|
-
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
29
|
-
},
|
|
30
|
-
emitRendererEvent(name, arg) {
|
|
31
|
-
const emitChannel = IPCChannel.rendererEventEmit + name;
|
|
32
|
-
if (arg instanceof Promise) {
|
|
33
|
-
const promiseChannel = emitChannel + IPCChannel.promisePostfix;
|
|
34
|
-
ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
35
|
-
arg
|
|
36
|
-
.then(value => ipcRenderer.send(promiseChannel, { value }))
|
|
37
|
-
.catch(reason => ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
ipcRenderer.send(emitChannel, { value: arg });
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
getVariable(name) {
|
|
44
|
-
return ipcRenderer.sendSync(IPCChannel.propertyGet + name);
|
|
45
|
-
},
|
|
46
|
-
setVariable(name, value) {
|
|
47
|
-
return ipcRenderer.sendSync(IPCChannel.propertySet + name, value);
|
|
48
|
-
},
|
|
49
|
-
waitPromise(channel) {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
ipcRenderer.once(channel, (_, result) => {
|
|
52
|
-
if (result.error)
|
|
53
|
-
reject(result.error);
|
|
54
|
-
else
|
|
55
|
-
resolve(result.value);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
9
|
+
let Main = new Proxy({ as() { throwError(); } }, {
|
|
10
|
+
get() { throwError(); },
|
|
11
|
+
set() { throwError(); },
|
|
12
|
+
apply() { throwError(); }
|
|
59
13
|
});
|
|
14
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
15
|
+
let throwError;
|
|
16
|
+
if (typeof window !== 'undefined') {
|
|
17
|
+
throwError = () => { throw new Error('"Main" is unavailable in renderer process. Use "Bridge" instead'); };
|
|
18
|
+
}
|
|
19
|
+
else if (!Electron.ipcRenderer) {
|
|
20
|
+
throwError = () => { throw new Error('"Main" is unavailable in main process.'); };
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
initInNode();
|
|
24
|
+
}
|
|
25
|
+
/** Выполняется только в NodeJS */
|
|
26
|
+
function initInNode() {
|
|
27
|
+
const { ipcRenderer } = Electron;
|
|
28
|
+
const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
|
|
29
|
+
if (!info)
|
|
30
|
+
throw new Error('Public methods from main is not provided. Call any publish methods to provide it from main process.');
|
|
31
|
+
Main = createProvider({
|
|
32
|
+
info, scope: Scope.preload,
|
|
33
|
+
callFunction(name, ...args) {
|
|
34
|
+
return ipcRenderer.sendSync(IPCChannel.functionCall + name, ...args);
|
|
35
|
+
},
|
|
36
|
+
handleMainEvent(name, type, handler) {
|
|
37
|
+
const listener = (_, result) => handler(result);
|
|
38
|
+
const emitChannel = IPCChannel.mainEventEmit + name;
|
|
39
|
+
if (type === 'on') {
|
|
40
|
+
ipcRenderer.send(IPCChannel.mainEventOn + name);
|
|
41
|
+
ipcRenderer.on(emitChannel, listener);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
ipcRenderer.send(IPCChannel.mainEventOnce + name);
|
|
45
|
+
ipcRenderer.once(emitChannel, listener);
|
|
46
|
+
}
|
|
47
|
+
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
48
|
+
},
|
|
49
|
+
emitRendererEvent(name, arg) {
|
|
50
|
+
const emitChannel = IPCChannel.rendererEventEmit + name;
|
|
51
|
+
if (arg instanceof Promise) {
|
|
52
|
+
const promiseChannel = emitChannel + IPCChannel.promisePostfix;
|
|
53
|
+
ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
54
|
+
arg
|
|
55
|
+
.then(value => ipcRenderer.send(promiseChannel, { value }))
|
|
56
|
+
.catch(reason => ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
ipcRenderer.send(emitChannel, { value: arg });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
getVariable(name) {
|
|
63
|
+
return ipcRenderer.sendSync(IPCChannel.propertyGet + name);
|
|
64
|
+
},
|
|
65
|
+
setVariable(name, value) {
|
|
66
|
+
return ipcRenderer.sendSync(IPCChannel.propertySet + name, value);
|
|
67
|
+
},
|
|
68
|
+
waitPromise(channel) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
ipcRenderer.once(channel, (_, result) => {
|
|
71
|
+
if (result.error)
|
|
72
|
+
reject(result.error);
|
|
73
|
+
else
|
|
74
|
+
resolve(result.value);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
60
80
|
export default Main;
|
|
@@ -9,6 +9,7 @@ export declare function publicMethod(): ClassMethodDecorator;
|
|
|
9
9
|
* Makes the method available for **renderer** and **preload** processes.
|
|
10
10
|
*
|
|
11
11
|
* _only new decorators_
|
|
12
|
+
*
|
|
12
13
|
* @param name - name by which the method will be accessed
|
|
13
14
|
*/
|
|
14
15
|
export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
@@ -16,6 +17,7 @@ export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
|
16
17
|
* Makes the method available for **renderer** and **preload** processes.
|
|
17
18
|
*
|
|
18
19
|
* _only new decorators_
|
|
20
|
+
*
|
|
19
21
|
* @param args - publish args
|
|
20
22
|
*/
|
|
21
23
|
export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecorator;
|
|
@@ -29,6 +31,7 @@ export declare function publicClassMainEvent(): ClassMethodDecorator;
|
|
|
29
31
|
* Makes the event available for **renderer** and **preload** processes.
|
|
30
32
|
*
|
|
31
33
|
* _only new decorators_
|
|
34
|
+
*
|
|
32
35
|
* @param name - name by which the event will be accessed
|
|
33
36
|
*/
|
|
34
37
|
export declare function publicClassMainEvent(name: string): ClassMethodDecorator;
|
|
@@ -36,6 +39,7 @@ export declare function publicClassMainEvent(name: string): ClassMethodDecorator
|
|
|
36
39
|
* Makes the event available for **renderer** and **preload** processes.
|
|
37
40
|
*
|
|
38
41
|
* _only new decorators_
|
|
42
|
+
*
|
|
39
43
|
* @param args - publish args
|
|
40
44
|
*/
|
|
41
45
|
export declare function publicClassMainEvent(args: IPublishMainEventArgs): ClassMethodDecorator;
|
|
@@ -49,6 +53,7 @@ export declare function publicClassRendererEvent(): ClassPropertyDecorator;
|
|
|
49
53
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
50
54
|
*
|
|
51
55
|
* _only new decorators_
|
|
56
|
+
*
|
|
52
57
|
* @param name - name by which the event will be accessed
|
|
53
58
|
*/
|
|
54
59
|
export declare function publicClassRendererEvent(name: string): ClassPropertyDecorator;
|
|
@@ -56,12 +61,14 @@ export declare function publicClassRendererEvent(name: string): ClassPropertyDec
|
|
|
56
61
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
57
62
|
*
|
|
58
63
|
* _only new decorators_
|
|
64
|
+
*
|
|
59
65
|
* @param receiver - linked receiver
|
|
60
66
|
*/
|
|
61
67
|
export declare function publicClassRendererEvent(receiver: EventReceiver): ClassPropertyDecorator;
|
|
62
68
|
/**
|
|
63
69
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
64
70
|
*
|
|
71
|
+
* * _only new decorators_
|
|
65
72
|
*
|
|
66
73
|
* @param name - name by which the event will be accessed
|
|
67
74
|
* @param receiver - linked receiver
|
|
@@ -71,13 +78,7 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
71
78
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
72
79
|
*
|
|
73
80
|
* _only new decorators_
|
|
74
|
-
* @param args - publish args
|
|
75
|
-
*/
|
|
76
|
-
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
77
|
-
/**
|
|
78
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
79
81
|
*
|
|
80
|
-
* _only new decorators_
|
|
81
82
|
* @param args - publish args
|
|
82
83
|
*/
|
|
83
84
|
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
@@ -91,6 +92,7 @@ export declare function publicProperty(): ClassPropertyDecorator;
|
|
|
91
92
|
* Makes the property available for **renderer** and **preload** processes.
|
|
92
93
|
*
|
|
93
94
|
* _only new decorators_
|
|
95
|
+
*
|
|
94
96
|
* @param name - name by which the property will be accessed
|
|
95
97
|
*/
|
|
96
98
|
export declare function publicProperty(name: string): ClassPropertyDecorator;
|
|
@@ -98,6 +100,7 @@ export declare function publicProperty(name: string): ClassPropertyDecorator;
|
|
|
98
100
|
* Makes the property available for **renderer** and **preload** processes.
|
|
99
101
|
*
|
|
100
102
|
* _only new decorators_
|
|
103
|
+
*
|
|
101
104
|
* @param args - publish args
|
|
102
105
|
*/
|
|
103
106
|
export declare function publicProperty(args: IPublishPropertyArgs): ClassPropertyDecorator;
|
|
@@ -111,6 +114,7 @@ export declare function publicGetter(): ClassGetterDecorator;
|
|
|
111
114
|
* Makes the property getter available for **renderer** and **preload** processes.
|
|
112
115
|
*
|
|
113
116
|
* _only new decorators_
|
|
117
|
+
*
|
|
114
118
|
* @param name - name by which the property will be accessed
|
|
115
119
|
*/
|
|
116
120
|
export declare function publicGetter(name: string): ClassGetterDecorator;
|
|
@@ -118,6 +122,7 @@ export declare function publicGetter(name: string): ClassGetterDecorator;
|
|
|
118
122
|
* Makes the property getter available for **renderer** and **preload** processes.
|
|
119
123
|
*
|
|
120
124
|
* _only new decorators_
|
|
125
|
+
*
|
|
121
126
|
* @param args - publish args
|
|
122
127
|
*/
|
|
123
128
|
export declare function publicGetter(args: PublishGetterArgs): ClassGetterDecorator;
|
|
@@ -131,6 +136,7 @@ export declare function publicSetter(): ClassSetterDecorator;
|
|
|
131
136
|
* Makes the property setter available for **renderer** and **preload** processes.
|
|
132
137
|
*
|
|
133
138
|
* _only new decorators_
|
|
139
|
+
*
|
|
134
140
|
* @param name - name by which the property will be accessed
|
|
135
141
|
*/
|
|
136
142
|
export declare function publicSetter(name: string): ClassSetterDecorator;
|
|
@@ -138,6 +144,7 @@ export declare function publicSetter(name: string): ClassSetterDecorator;
|
|
|
138
144
|
* Makes the property setter available for **renderer** and **preload** processes.
|
|
139
145
|
*
|
|
140
146
|
* _only new decorators_
|
|
147
|
+
*
|
|
141
148
|
* @param args - publish args
|
|
142
149
|
*/
|
|
143
150
|
export declare function publicSetter(args: PublishSetterArgs): ClassSetterDecorator;
|
|
@@ -46,7 +46,7 @@ export function publicClassRendererEvent(arg) {
|
|
|
46
46
|
}
|
|
47
47
|
else if (typeof arg === 'object') {
|
|
48
48
|
name = arg.name ?? String(context.name);
|
|
49
|
-
receiver = arg.
|
|
49
|
+
receiver = arg.procFn ?? receiver;
|
|
50
50
|
if (arg.scope)
|
|
51
51
|
addScope(name, arg.scope);
|
|
52
52
|
}
|
|
@@ -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,10 +46,9 @@ 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)`_
|
|
51
|
+
*
|
|
57
52
|
* @param args - publish args
|
|
58
53
|
*/
|
|
59
54
|
export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
@@ -61,9 +56,7 @@ export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
|
61
56
|
* Makes the event available for **renderer** and **preload** processes.
|
|
62
57
|
*
|
|
63
58
|
* _only for non-static_
|
|
64
|
-
*
|
|
65
59
|
* _experimental decorators_
|
|
66
|
-
*
|
|
67
60
|
* _required `providePublic(classInstance)`_
|
|
68
61
|
*/
|
|
69
62
|
export declare function publicClassMainEvent(): MethodDecorator;
|
|
@@ -71,10 +64,9 @@ export declare function publicClassMainEvent(): MethodDecorator;
|
|
|
71
64
|
* Makes the event available for **renderer** and **preload** processes.
|
|
72
65
|
*
|
|
73
66
|
* _only for non-static_
|
|
74
|
-
*
|
|
75
67
|
* _experimental decorators_
|
|
76
|
-
*
|
|
77
68
|
* _required `providePublic(classInstance)`_
|
|
69
|
+
*
|
|
78
70
|
* @param name - name by which the event will be accessed
|
|
79
71
|
*/
|
|
80
72
|
export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
@@ -82,10 +74,9 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
|
82
74
|
* Makes the event available for **renderer** and **preload** processes.
|
|
83
75
|
*
|
|
84
76
|
* _only for non-static_
|
|
85
|
-
*
|
|
86
77
|
* _experimental decorators_
|
|
87
|
-
*
|
|
88
78
|
* _required `providePublic(classInstance)`_
|
|
79
|
+
*
|
|
89
80
|
* @param args - publish args
|
|
90
81
|
*/
|
|
91
82
|
export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
@@ -93,7 +84,6 @@ export declare function publicClassMainEvent(args: IPublishMainEventArgs): Metho
|
|
|
93
84
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
94
85
|
*
|
|
95
86
|
* _only for non-static_
|
|
96
|
-
*
|
|
97
87
|
* _experimental decorators_
|
|
98
88
|
*/
|
|
99
89
|
export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
@@ -101,8 +91,8 @@ export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
|
101
91
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
102
92
|
*
|
|
103
93
|
* _only for non-static_
|
|
104
|
-
*
|
|
105
94
|
* _experimental decorators_
|
|
95
|
+
*
|
|
106
96
|
* @param name - name by which the event will be accessed
|
|
107
97
|
*/
|
|
108
98
|
export declare function publicClassRendererEvent(name: string): PropertyDecorator;
|
|
@@ -110,8 +100,8 @@ export declare function publicClassRendererEvent(name: string): PropertyDecorato
|
|
|
110
100
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
111
101
|
*
|
|
112
102
|
* _only for non-static_
|
|
113
|
-
*
|
|
114
103
|
* _experimental decorators_
|
|
104
|
+
*
|
|
115
105
|
* @param receiver - linked receiver
|
|
116
106
|
*/
|
|
117
107
|
export declare function publicClassRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
@@ -119,8 +109,8 @@ export declare function publicClassRendererEvent(receiver: EventReceiver): Prope
|
|
|
119
109
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
120
110
|
*
|
|
121
111
|
* _only for non-static_
|
|
122
|
-
*
|
|
123
112
|
* _experimental decorators_
|
|
113
|
+
*
|
|
124
114
|
* @param name - name by which the event will be accessed
|
|
125
115
|
* @param receiver - linked receiver
|
|
126
116
|
*/
|
|
@@ -129,17 +119,8 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
129
119
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
130
120
|
*
|
|
131
121
|
* _only for non-static_
|
|
132
|
-
*
|
|
133
122
|
* _experimental decorators_
|
|
134
|
-
* @param args - publish args
|
|
135
|
-
*/
|
|
136
|
-
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
137
|
-
/**
|
|
138
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
139
|
-
*
|
|
140
|
-
* _only for non-static_
|
|
141
123
|
*
|
|
142
|
-
* _experimental decorators_
|
|
143
124
|
* @param args - publish args
|
|
144
125
|
*/
|
|
145
126
|
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
@@ -147,7 +128,6 @@ export declare function publicClassRendererEvent(args: IPublishRendererEventArgs
|
|
|
147
128
|
* Makes the property available for **renderer** and **preload** processes.
|
|
148
129
|
*
|
|
149
130
|
* _only for static_
|
|
150
|
-
*
|
|
151
131
|
* _experimental decorators_
|
|
152
132
|
*/
|
|
153
133
|
export declare function publicStaticProperty(): PropertyDecorator;
|
|
@@ -155,8 +135,8 @@ export declare function publicStaticProperty(): PropertyDecorator;
|
|
|
155
135
|
* Makes the property available for **renderer** and **preload** processes.
|
|
156
136
|
*
|
|
157
137
|
* _only for static_
|
|
158
|
-
*
|
|
159
138
|
* _experimental decorators_
|
|
139
|
+
*
|
|
160
140
|
* @param name - name by which the property will be accessed
|
|
161
141
|
*/
|
|
162
142
|
export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
@@ -164,8 +144,8 @@ export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
|
164
144
|
* Makes the property available for **renderer** and **preload** processes.
|
|
165
145
|
*
|
|
166
146
|
* _only for static_
|
|
167
|
-
*
|
|
168
147
|
* _experimental decorators_
|
|
148
|
+
*
|
|
169
149
|
* @param args - publish args
|
|
170
150
|
*/
|
|
171
151
|
export declare function publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
@@ -173,9 +153,7 @@ export declare function publicStaticProperty(args: IPublishPropertyArgs): Proper
|
|
|
173
153
|
* Makes the property available for **renderer** and **preload** processes.
|
|
174
154
|
*
|
|
175
155
|
* _only for non-static_
|
|
176
|
-
*
|
|
177
156
|
* _experimental decorators_
|
|
178
|
-
*
|
|
179
157
|
* _required `providePublic(classInstance)`_
|
|
180
158
|
*/
|
|
181
159
|
export declare function publicProperty(): PropertyDecorator;
|
|
@@ -183,10 +161,9 @@ export declare function publicProperty(): PropertyDecorator;
|
|
|
183
161
|
* Makes the property available for **renderer** and **preload** processes.
|
|
184
162
|
*
|
|
185
163
|
* _only for non-static_
|
|
186
|
-
*
|
|
187
164
|
* _experimental decorators_
|
|
188
|
-
*
|
|
189
165
|
* _required `providePublic(classInstance)`_
|
|
166
|
+
*
|
|
190
167
|
* @param name - name by which the property will be accessed
|
|
191
168
|
*/
|
|
192
169
|
export declare function publicProperty(name: string): PropertyDecorator;
|
|
@@ -194,10 +171,9 @@ export declare function publicProperty(name: string): PropertyDecorator;
|
|
|
194
171
|
* Makes the property available for **renderer** and **preload** processes.
|
|
195
172
|
*
|
|
196
173
|
* _only for non-static_
|
|
197
|
-
*
|
|
198
174
|
* _experimental decorators_
|
|
199
|
-
*
|
|
200
175
|
* _required `providePublic(classInstance)`_
|
|
176
|
+
*
|
|
201
177
|
* @param args - publish args
|
|
202
178
|
*/
|
|
203
179
|
export declare function publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Electron from 'electron';
|
|
2
2
|
import { IPCChannel } from '../enums';
|
|
3
|
-
|
|
3
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
4
|
+
let mayThrowError = () => { };
|
|
5
|
+
if (typeof window === 'undefined') {
|
|
6
|
+
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in main process.'); };
|
|
7
|
+
}
|
|
8
|
+
else if (!Electron.contextBridge) {
|
|
9
|
+
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in renderer process.'); };
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Sets access to main from renderer
|
|
6
13
|
*
|
|
7
14
|
* @param contextIsolation - _default_: `true`
|
|
8
15
|
*/
|
|
9
16
|
function provideFromMain(contextIsolation = true) {
|
|
17
|
+
mayThrowError();
|
|
18
|
+
const { contextBridge, ipcRenderer } = Electron;
|
|
19
|
+
const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
|
|
10
20
|
const provider = {
|
|
11
21
|
getInfo() {
|
|
12
22
|
return info;
|
package/esm/scripts/publish.d.ts
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
import { Access, Scope } from '../enums';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PublicFunction, PublicProperty, RendererEvent } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
5
5
|
*
|
|
6
6
|
* @param name - name by which the event will be accessed
|
|
7
|
+
* @param procFn - function of processing before sending the event
|
|
7
8
|
* @param scopes - event scopes
|
|
8
9
|
*/
|
|
9
|
-
export declare function publicMainEvent<
|
|
10
|
+
export declare function publicMainEvent<In = void, Out = In extends Array<any> ? In[0] : In, ProcFn extends (...args: any[]) => any = In extends Array<any> ? (...args: In) => Out : (val: In) => Out>(name: string, procFn?: ProcFn, scopes?: Scope[]): (...args: Parameters<ProcFn>) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
12
13
|
*
|
|
13
14
|
* @param name - name by which the event will be accessed
|
|
15
|
+
* @param procFn - processing function before calling handlers
|
|
14
16
|
* @param scopes - event scopes
|
|
15
17
|
*/
|
|
16
|
-
export declare function publicRendererEvent<
|
|
18
|
+
export declare function publicRendererEvent<In = void, Out = In, ProcFn extends (...args: any[]) => any = (v?: In) => Out>(name: string, procFn?: ProcFn, scopes?: Scope[]): RendererEvent<Out>;
|
|
17
19
|
/**
|
|
18
20
|
* Makes the function available for **renderer** and **preload** processes.
|
|
19
21
|
*
|
|
20
22
|
* _only for function_
|
|
23
|
+
*
|
|
21
24
|
* @param name - name by which the function will be accessed
|
|
22
25
|
* @param func - linked function
|
|
23
26
|
* @param scopes - function scopes
|
|
24
27
|
*/
|
|
25
|
-
export declare function publicFunction(name: string, func:
|
|
28
|
+
export declare function publicFunction<F extends PublicFunction>(name: string, func: F, scopes?: Scope[]): void;
|
|
26
29
|
/**
|
|
27
30
|
* Makes the function available for **renderer** and **preload** processes.
|
|
28
31
|
*
|
|
29
32
|
* _only for variables_
|
|
33
|
+
*
|
|
30
34
|
* @param name - name by which the variable will be accessed
|
|
31
35
|
* @param value - variable getter/setter
|
|
32
36
|
* @param scopes - variable scopes
|
|
33
37
|
*/
|
|
34
|
-
export declare function publicVariable(name: string, value: PublicProperty
|
|
38
|
+
export declare function publicVariable<T>(name: string, value: PublicProperty<T>, scopes?: Scope[]): void;
|
|
35
39
|
export declare function addScope(key: string, scope: Scope): void;
|
|
36
40
|
export declare function addAccess(key: string, access: Access): void;
|
package/esm/scripts/publish.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Electron from 'electron';
|
|
2
2
|
import { Access, IPCChannel, Scope } from '../enums';
|
|
3
3
|
const publicInfo = {
|
|
4
4
|
properties: new Set(),
|
|
@@ -8,14 +8,24 @@ const publicInfo = {
|
|
|
8
8
|
accesses: new Map(),
|
|
9
9
|
scopes: new Map()
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
12
|
+
let mayThrowError = () => { };
|
|
13
|
+
if (typeof window !== 'undefined' || !Electron.ipcMain) {
|
|
14
|
+
mayThrowError = () => { throw new Error('Publish methods is available only in main process.'); };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
Electron.ipcMain.on(IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
14
21
|
*
|
|
15
22
|
* @param name - name by which the event will be accessed
|
|
23
|
+
* @param procFn - function of processing before sending the event
|
|
16
24
|
* @param scopes - event scopes
|
|
17
25
|
*/
|
|
18
|
-
export function publicMainEvent(name,
|
|
26
|
+
export function publicMainEvent(name, procFn = ((...args) => args[0]), scopes = [Scope.preload, Scope.renderer]) {
|
|
27
|
+
mayThrowError();
|
|
28
|
+
const { ipcMain } = Electron;
|
|
19
29
|
const { mainEvents } = publicInfo;
|
|
20
30
|
const mainEmitChannel = IPCChannel.mainEventEmit + name;
|
|
21
31
|
const mainHandleChannel = IPCChannel.mainEventOn + name;
|
|
@@ -41,7 +51,7 @@ export function publicMainEvent(name, receiver = ((v = undefined) => v), scopes
|
|
|
41
51
|
filterSenders();
|
|
42
52
|
const allSenders = [...senders, ...sendersOnce];
|
|
43
53
|
try {
|
|
44
|
-
const result =
|
|
54
|
+
const result = procFn(...args);
|
|
45
55
|
if (result instanceof Promise) {
|
|
46
56
|
result
|
|
47
57
|
.then(value => {
|
|
@@ -70,9 +80,12 @@ export function publicMainEvent(name, receiver = ((v = undefined) => v), scopes
|
|
|
70
80
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
71
81
|
*
|
|
72
82
|
* @param name - name by which the event will be accessed
|
|
83
|
+
* @param procFn - processing function before calling handlers
|
|
73
84
|
* @param scopes - event scopes
|
|
74
85
|
*/
|
|
75
|
-
export function publicRendererEvent(name,
|
|
86
|
+
export function publicRendererEvent(name, procFn = ((v) => v), scopes = [Scope.preload, Scope.renderer]) {
|
|
87
|
+
mayThrowError();
|
|
88
|
+
const { ipcMain } = Electron;
|
|
76
89
|
if (name.startsWith('on')) {
|
|
77
90
|
name = name.replace('on', '');
|
|
78
91
|
name = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
@@ -88,7 +101,7 @@ export function publicRendererEvent(name, receiver = ((v = undefined) => v), sco
|
|
|
88
101
|
ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
89
102
|
if (result.error)
|
|
90
103
|
throw new Error(result.error);
|
|
91
|
-
const converted =
|
|
104
|
+
const converted = procFn(result.value);
|
|
92
105
|
handlers.forEach(handler => handler(converted));
|
|
93
106
|
handlersOnce.forEach(handler => handler(converted));
|
|
94
107
|
handlersOnce.clear();
|
|
@@ -108,11 +121,14 @@ export function publicRendererEvent(name, receiver = ((v = undefined) => v), sco
|
|
|
108
121
|
* Makes the function available for **renderer** and **preload** processes.
|
|
109
122
|
*
|
|
110
123
|
* _only for function_
|
|
124
|
+
*
|
|
111
125
|
* @param name - name by which the function will be accessed
|
|
112
126
|
* @param func - linked function
|
|
113
127
|
* @param scopes - function scopes
|
|
114
128
|
*/
|
|
115
129
|
export function publicFunction(name, func, scopes = [Scope.preload, Scope.renderer]) {
|
|
130
|
+
mayThrowError();
|
|
131
|
+
const { ipcMain } = Electron;
|
|
116
132
|
const { functions } = publicInfo;
|
|
117
133
|
const channel = IPCChannel.functionCall + name;
|
|
118
134
|
functions.add(name);
|
|
@@ -142,11 +158,14 @@ export function publicFunction(name, func, scopes = [Scope.preload, Scope.render
|
|
|
142
158
|
* Makes the function available for **renderer** and **preload** processes.
|
|
143
159
|
*
|
|
144
160
|
* _only for variables_
|
|
161
|
+
*
|
|
145
162
|
* @param name - name by which the variable will be accessed
|
|
146
163
|
* @param value - variable getter/setter
|
|
147
164
|
* @param scopes - variable scopes
|
|
148
165
|
*/
|
|
149
166
|
export function publicVariable(name, value, scopes = [Scope.renderer, Scope.preload]) {
|
|
167
|
+
mayThrowError();
|
|
168
|
+
const { ipcMain } = Electron;
|
|
150
169
|
const { properties } = publicInfo;
|
|
151
170
|
const getChannel = IPCChannel.propertyGet + name;
|
|
152
171
|
const setChannel = IPCChannel.propertySet + name;
|