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
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
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/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
@@ -15,6 +15,12 @@ const Bridge = createProvider({
|
|
|
15
15
|
callFunction(name, ...args) {
|
|
16
16
|
return provider.provided.functions[name](...args);
|
|
17
17
|
},
|
|
18
|
+
emitRendererEvent(name, arg) {
|
|
19
|
+
provider.provided.rendererEvents[name](arg);
|
|
20
|
+
},
|
|
21
|
+
handleMainEvent(name, type, handler) {
|
|
22
|
+
return provider.provided.mainEvents[name](type, handler);
|
|
23
|
+
},
|
|
18
24
|
getVariable(name) {
|
|
19
25
|
return provider.provided.properties[name];
|
|
20
26
|
},
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ipcRenderer } from 'electron';
|
|
2
|
+
import { IPCChannel, Scope } from '../enums';
|
|
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
|
+
/**
|
|
8
|
+
* Bridge between `preload` and `main` processes.
|
|
9
|
+
*
|
|
10
|
+
* _only for preload process_
|
|
11
|
+
*/
|
|
12
|
+
const Main = createProvider({
|
|
13
|
+
info,
|
|
14
|
+
scope: Scope.preload,
|
|
15
|
+
callFunction(name, ...args) {
|
|
16
|
+
return ipcRenderer.sendSync(IPCChannel.functionCall + name, ...args);
|
|
17
|
+
},
|
|
18
|
+
handleMainEvent(name, type, handler) {
|
|
19
|
+
const listener = (_, result) => handler(result);
|
|
20
|
+
const emitChannel = IPCChannel.mainEventEmit + name;
|
|
21
|
+
if (type === 'on') {
|
|
22
|
+
ipcRenderer.send(IPCChannel.mainEventOn + name);
|
|
23
|
+
ipcRenderer.on(emitChannel, listener);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
ipcRenderer.send(IPCChannel.mainEventOnce + name);
|
|
27
|
+
ipcRenderer.once(emitChannel, listener);
|
|
28
|
+
}
|
|
29
|
+
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
30
|
+
},
|
|
31
|
+
emitRendererEvent(name, arg) {
|
|
32
|
+
const emitChannel = IPCChannel.rendererEventEmit + name;
|
|
33
|
+
if (arg instanceof Promise) {
|
|
34
|
+
const promiseChannel = emitChannel + IPCChannel.promisePostfix;
|
|
35
|
+
ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
36
|
+
arg
|
|
37
|
+
.then(value => ipcRenderer.send(promiseChannel, { value }))
|
|
38
|
+
.catch(reason => ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
ipcRenderer.send(emitChannel, { value: arg });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
getVariable(name) {
|
|
45
|
+
return ipcRenderer.sendSync(IPCChannel.propertyGet + name);
|
|
46
|
+
},
|
|
47
|
+
setVariable(name, value) {
|
|
48
|
+
return ipcRenderer.sendSync(IPCChannel.propertySet + name, value);
|
|
49
|
+
},
|
|
50
|
+
waitPromise(channel) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
ipcRenderer.once(channel, (_, result) => {
|
|
53
|
+
if (result.error)
|
|
54
|
+
reject(result.error);
|
|
55
|
+
else
|
|
56
|
+
resolve(result.value);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export default Main;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, IPublishMethodArgs, IPublishPropertyArgs, PublishGetterArgs, PublishSetterArgs } from '../types';
|
|
1
|
+
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, EventReceiver, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, PublishGetterArgs, PublishSetterArgs } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
@@ -19,6 +19,68 @@ export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
|
19
19
|
* @param args - publish args
|
|
20
20
|
*/
|
|
21
21
|
export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecorator;
|
|
22
|
+
/**
|
|
23
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
24
|
+
*
|
|
25
|
+
* _only new decorators_
|
|
26
|
+
*/
|
|
27
|
+
export declare function publicClassMainEvent(): ClassMethodDecorator;
|
|
28
|
+
/**
|
|
29
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
30
|
+
*
|
|
31
|
+
* _only new decorators_
|
|
32
|
+
* @param name - name by which the event will be accessed
|
|
33
|
+
*/
|
|
34
|
+
export declare function publicClassMainEvent(name: string): ClassMethodDecorator;
|
|
35
|
+
/**
|
|
36
|
+
* Makes the event available for **renderer** and **preload** processes.
|
|
37
|
+
*
|
|
38
|
+
* _only new decorators_
|
|
39
|
+
* @param args - publish args
|
|
40
|
+
*/
|
|
41
|
+
export declare function publicClassMainEvent(args: IPublishMainEventArgs): ClassMethodDecorator;
|
|
42
|
+
/**
|
|
43
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
44
|
+
*
|
|
45
|
+
* _only new decorators_
|
|
46
|
+
*/
|
|
47
|
+
export declare function publicClassRendererEvent(): ClassPropertyDecorator;
|
|
48
|
+
/**
|
|
49
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
50
|
+
*
|
|
51
|
+
* _only new decorators_
|
|
52
|
+
* @param name - name by which the event will be accessed
|
|
53
|
+
*/
|
|
54
|
+
export declare function publicClassRendererEvent(name: string): ClassPropertyDecorator;
|
|
55
|
+
/**
|
|
56
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
57
|
+
*
|
|
58
|
+
* _only new decorators_
|
|
59
|
+
* @param receiver - linked receiver
|
|
60
|
+
*/
|
|
61
|
+
export declare function publicClassRendererEvent(receiver: EventReceiver): ClassPropertyDecorator;
|
|
62
|
+
/**
|
|
63
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
* @param name - name by which the event will be accessed
|
|
67
|
+
* @param receiver - linked receiver
|
|
68
|
+
*/
|
|
69
|
+
export declare function publicClassRendererEvent(name: string, receiver: EventReceiver): ClassPropertyDecorator;
|
|
70
|
+
/**
|
|
71
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
72
|
+
*
|
|
73
|
+
* _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
|
+
*
|
|
80
|
+
* _only new decorators_
|
|
81
|
+
* @param args - publish args
|
|
82
|
+
*/
|
|
83
|
+
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
22
84
|
/**
|
|
23
85
|
* Makes the property available for **renderer** and **preload** processes.
|
|
24
86
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAccess, addScope, publicFunction, publicVariable } from './publish';
|
|
1
|
+
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish';
|
|
2
2
|
export function publicMethod(arg) {
|
|
3
3
|
return (method, context) => {
|
|
4
4
|
let name = String(context.name);
|
|
@@ -17,10 +17,53 @@ export function publicMethod(arg) {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
export function publicClassMainEvent(arg) {
|
|
21
|
+
return (method, context) => {
|
|
22
|
+
let name = String(context.name);
|
|
23
|
+
if (arg) {
|
|
24
|
+
if (typeof arg === 'string') {
|
|
25
|
+
name = arg;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
name = arg.name ?? name;
|
|
29
|
+
if (arg.scope)
|
|
30
|
+
addScope(name, arg.scope);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
context.addInitializer(function () {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
this[context.name] = publicMainEvent(name, method.bind(this));
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function publicClassRendererEvent(arg) {
|
|
40
|
+
return (_, context) => {
|
|
41
|
+
let name = String(context.name);
|
|
42
|
+
let receiver = (v) => v;
|
|
43
|
+
if (arg) {
|
|
44
|
+
if (typeof arg === 'string') {
|
|
45
|
+
name = arg;
|
|
46
|
+
}
|
|
47
|
+
else if (typeof arg === 'object') {
|
|
48
|
+
name = arg.name ?? String(context.name);
|
|
49
|
+
receiver = arg.receiver ?? receiver;
|
|
50
|
+
if (arg.scope)
|
|
51
|
+
addScope(name, arg.scope);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
receiver = arg;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
context.addInitializer(function () {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
this[context.name] = publicRendererEvent(name, receiver);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
20
63
|
export function publicProperty(arg) {
|
|
21
64
|
return (_, context) => {
|
|
22
|
-
const
|
|
23
|
-
let name =
|
|
65
|
+
const key = String(context.name);
|
|
66
|
+
let name = key;
|
|
24
67
|
if (arg) {
|
|
25
68
|
if (typeof arg === 'string') {
|
|
26
69
|
name = arg;
|
|
@@ -37,11 +80,11 @@ export function publicProperty(arg) {
|
|
|
37
80
|
publicVariable(name, {
|
|
38
81
|
get: () => {
|
|
39
82
|
// @ts-ignore
|
|
40
|
-
return this[
|
|
83
|
+
return this[key];
|
|
41
84
|
},
|
|
42
85
|
set: (value) => {
|
|
43
86
|
// @ts-ignore
|
|
44
|
-
this[
|
|
87
|
+
this[key] = value;
|
|
45
88
|
}
|
|
46
89
|
});
|
|
47
90
|
});
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import type { EventReceiver, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
4
|
+
*
|
|
5
|
+
* _only for static_
|
|
6
|
+
*
|
|
7
|
+
* _experimental decorators_
|
|
8
|
+
*/
|
|
9
|
+
export declare function publicStaticMethod(): MethodDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
12
|
+
*
|
|
13
|
+
* _only for static_
|
|
14
|
+
*
|
|
15
|
+
* _experimental decorators_
|
|
16
|
+
* @param name - name by which the method will be accessed
|
|
17
|
+
*/
|
|
18
|
+
export declare function publicStaticMethod(name: string): MethodDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
21
|
+
*
|
|
22
|
+
* _only for static_
|
|
23
|
+
*
|
|
24
|
+
* _experimental decorators_
|
|
25
|
+
* @param args - publish args
|
|
26
|
+
*/
|
|
27
|
+
export declare function publicStaticMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
28
|
+
/**
|
|
29
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
30
|
+
*
|
|
31
|
+
* _only for non-static_
|
|
32
|
+
*
|
|
33
|
+
* _experimental decorators_
|
|
34
|
+
*
|
|
35
|
+
* _required `providePublic(classInstance)`_
|
|
36
|
+
*/
|
|
37
|
+
export declare function publicMethod(): MethodDecorator;
|
|
38
|
+
/**
|
|
39
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
40
|
+
*
|
|
41
|
+
* _only for non-static_
|
|
42
|
+
*
|
|
43
|
+
* _experimental decorators_
|
|
44
|
+
*
|
|
45
|
+
* _required `providePublic(classInstance)`_
|
|
46
|
+
* @param name - name by which the method will be accessed
|
|
47
|
+
*/
|
|
48
|
+
export declare function publicMethod(name: string): MethodDecorator;
|
|
49
|
+
/**
|
|
50
|
+
* Makes the method available for **renderer** and **preload** processes.
|
|
51
|
+
*
|
|
52
|
+
* _only for non-static_
|
|
53
|
+
*
|
|
54
|
+
* _experimental decorators_
|
|
55
|
+
*
|
|
56
|
+
* _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
|
+
*
|
|
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;
|
|
226
|
+
/**
|
|
227
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
228
|
+
*
|
|
229
|
+
* _only for static_
|
|
230
|
+
*
|
|
231
|
+
* _experimental decorators_
|
|
232
|
+
*/
|
|
233
|
+
export declare function publicStaticProperty(): PropertyDecorator;
|
|
234
|
+
/**
|
|
235
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
236
|
+
*
|
|
237
|
+
* _only for static_
|
|
238
|
+
*
|
|
239
|
+
* _experimental decorators_
|
|
240
|
+
* @param name - name by which the property will be accessed
|
|
241
|
+
*/
|
|
242
|
+
export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
243
|
+
/**
|
|
244
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
245
|
+
*
|
|
246
|
+
* _only for static_
|
|
247
|
+
*
|
|
248
|
+
* _experimental decorators_
|
|
249
|
+
* @param args - publish args
|
|
250
|
+
*/
|
|
251
|
+
export declare function publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
252
|
+
/**
|
|
253
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
254
|
+
*
|
|
255
|
+
* _only for non-static_
|
|
256
|
+
*
|
|
257
|
+
* _experimental decorators_
|
|
258
|
+
*
|
|
259
|
+
* _required `providePublic(classInstance)`_
|
|
260
|
+
*/
|
|
261
|
+
export declare function publicProperty(): PropertyDecorator;
|
|
262
|
+
/**
|
|
263
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
264
|
+
*
|
|
265
|
+
* _only for non-static_
|
|
266
|
+
*
|
|
267
|
+
* _experimental decorators_
|
|
268
|
+
*
|
|
269
|
+
* _required `providePublic(classInstance)`_
|
|
270
|
+
* @param name - name by which the property will be accessed
|
|
271
|
+
*/
|
|
272
|
+
export declare function publicProperty(name: string): PropertyDecorator;
|
|
273
|
+
/**
|
|
274
|
+
* Makes the property available for **renderer** and **preload** processes.
|
|
275
|
+
*
|
|
276
|
+
* _only for non-static_
|
|
277
|
+
*
|
|
278
|
+
* _experimental decorators_
|
|
279
|
+
*
|
|
280
|
+
* _required `providePublic(classInstance)`_
|
|
281
|
+
* @param args - publish args
|
|
282
|
+
*/
|
|
283
|
+
export declare function publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
284
|
+
/**
|
|
285
|
+
* Binds all public entities of a class to a specific instance.
|
|
286
|
+
*
|
|
287
|
+
* _only for class instance_
|
|
288
|
+
*/
|
|
289
|
+
export declare function providePublic<InstanceType>(instance: InstanceType): InstanceType;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAccess, addScope, publicFunction, publicVariable } from './publish';
|
|
1
|
+
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish';
|
|
2
2
|
export function publicStaticMethod(arg) {
|
|
3
3
|
return (target, key) => {
|
|
4
4
|
let name = String(key);
|
|
@@ -25,6 +25,63 @@ export function publicMethod(arg) {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
export function publicStaticMainEvent(arg) {
|
|
29
|
+
return (target, key) => {
|
|
30
|
+
let name = String(key);
|
|
31
|
+
if (arg) {
|
|
32
|
+
if (typeof arg === 'string') {
|
|
33
|
+
name = arg;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
name = arg.name ?? String(key);
|
|
37
|
+
if (arg.scope)
|
|
38
|
+
addScope(name, arg.scope);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
target[key] = publicMainEvent(name, target[key].bind(target));
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function publicClassMainEvent(arg) {
|
|
45
|
+
return (tgt, key, _) => {
|
|
46
|
+
const target = tgt;
|
|
47
|
+
const prevRegister = target.__register__ ?? (() => { });
|
|
48
|
+
target.__register__ = instance => {
|
|
49
|
+
prevRegister(instance);
|
|
50
|
+
publicStaticMainEvent(arg)(instance, key, _);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function publicStaticRendererEvent(arg) {
|
|
55
|
+
return (target, key) => {
|
|
56
|
+
let name = String(key);
|
|
57
|
+
let receiver = (v) => v;
|
|
58
|
+
if (arg) {
|
|
59
|
+
if (typeof arg === 'string') {
|
|
60
|
+
name = arg;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof arg === 'object') {
|
|
63
|
+
name = arg.name ?? String(key);
|
|
64
|
+
receiver = arg.receiver ?? receiver;
|
|
65
|
+
if (arg.scope)
|
|
66
|
+
addScope(name, arg.scope);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
receiver = arg;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
target[key] = publicRendererEvent(name, receiver);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function publicClassRendererEvent(arg) {
|
|
76
|
+
return (tgt, key) => {
|
|
77
|
+
const target = tgt;
|
|
78
|
+
const prevRegister = target.__register__ ?? (() => { });
|
|
79
|
+
target.__register__ = instance => {
|
|
80
|
+
prevRegister(instance);
|
|
81
|
+
publicStaticRendererEvent(arg)(instance, key);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}
|
|
28
85
|
export function publicStaticProperty(arg) {
|
|
29
86
|
return (target, key) => {
|
|
30
87
|
let name = String(key);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { contextBridge, ipcRenderer } from 'electron';
|
|
2
|
+
import { IPCChannel } from '../enums';
|
|
3
|
+
const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
|
|
4
|
+
/**
|
|
5
|
+
* Sets access to main from renderer
|
|
6
|
+
*
|
|
7
|
+
* @param contextIsolation - _default_: `true`
|
|
8
|
+
*/
|
|
9
|
+
function provideFromMain(contextIsolation = true) {
|
|
10
|
+
const provider = {
|
|
11
|
+
getInfo() {
|
|
12
|
+
return info;
|
|
13
|
+
},
|
|
14
|
+
waitPromise(channel, resolve, reject) {
|
|
15
|
+
ipcRenderer.once(channel, (_, result) => {
|
|
16
|
+
if (result.error)
|
|
17
|
+
reject?.(result.error);
|
|
18
|
+
else
|
|
19
|
+
resolve(result.value);
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
provided: {
|
|
23
|
+
properties: {},
|
|
24
|
+
functions: {},
|
|
25
|
+
mainEvents: {},
|
|
26
|
+
rendererEvents: {}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
info.functions.forEach(funcName => {
|
|
30
|
+
Object.defineProperty(provider.provided.functions, funcName, {
|
|
31
|
+
value(...args) {
|
|
32
|
+
return ipcRenderer.sendSync(IPCChannel.functionCall + funcName, ...args);
|
|
33
|
+
},
|
|
34
|
+
enumerable: true
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
info.rendererEvents.forEach(rendererEventName => {
|
|
38
|
+
Object.defineProperty(provider.provided.rendererEvents, rendererEventName, {
|
|
39
|
+
value(arg) {
|
|
40
|
+
const emitChannel = IPCChannel.rendererEventEmit + rendererEventName;
|
|
41
|
+
if (arg instanceof Promise) {
|
|
42
|
+
arg
|
|
43
|
+
.then(value => ipcRenderer.send(emitChannel, { value }))
|
|
44
|
+
.catch(reason => ipcRenderer.send(emitChannel, { error: String(reason) }));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
ipcRenderer.send(emitChannel, { value: arg });
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
enumerable: true
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
info.mainEvents.forEach(mainEventName => {
|
|
54
|
+
Object.defineProperty(provider.provided.mainEvents, mainEventName, {
|
|
55
|
+
value(type, handler) {
|
|
56
|
+
const listener = (_, result) => handler(result);
|
|
57
|
+
const emitChannel = IPCChannel.mainEventEmit + mainEventName;
|
|
58
|
+
if (type === 'on') {
|
|
59
|
+
ipcRenderer.on(emitChannel, listener);
|
|
60
|
+
ipcRenderer.send(IPCChannel.mainEventOn + mainEventName);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
ipcRenderer.once(emitChannel, listener);
|
|
64
|
+
ipcRenderer.send(IPCChannel.mainEventOnce + mainEventName);
|
|
65
|
+
}
|
|
66
|
+
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
67
|
+
},
|
|
68
|
+
enumerable: true
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
info.properties.forEach(propName => {
|
|
72
|
+
Object.defineProperty(provider.provided.properties, propName, {
|
|
73
|
+
get() {
|
|
74
|
+
return ipcRenderer.sendSync(IPCChannel.propertyGet + propName);
|
|
75
|
+
},
|
|
76
|
+
set(value) {
|
|
77
|
+
ipcRenderer.sendSync(IPCChannel.propertySet + propName, value);
|
|
78
|
+
},
|
|
79
|
+
enumerable: true
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
if (contextIsolation)
|
|
83
|
+
contextBridge.exposeInMainWorld('__provider__', provider);
|
|
84
|
+
else
|
|
85
|
+
window.__provider__ = provider;
|
|
86
|
+
}
|
|
87
|
+
export default provideFromMain;
|