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
|
@@ -3,7 +3,7 @@ function errorHandler(error, channel) {
|
|
|
3
3
|
console.error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
4
4
|
}
|
|
5
5
|
function createProvider(args) {
|
|
6
|
-
const { info, scope, getVariable, setVariable, callFunction, waitPromise } = args;
|
|
6
|
+
const { info, scope, getVariable, setVariable, callFunction, handleMainEvent, waitPromise, emitRendererEvent } = args;
|
|
7
7
|
const target = {
|
|
8
8
|
as: () => proxy
|
|
9
9
|
};
|
|
@@ -29,6 +29,63 @@ function createProvider(args) {
|
|
|
29
29
|
enumerable: true
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
|
+
info.rendererEvents.forEach(rendererEventName => {
|
|
33
|
+
if (!info.scopes[rendererEventName].has(scope))
|
|
34
|
+
return;
|
|
35
|
+
Object.defineProperty(target, rendererEventName, {
|
|
36
|
+
get() {
|
|
37
|
+
return (arg) => emitRendererEvent(rendererEventName, arg);
|
|
38
|
+
},
|
|
39
|
+
set() {
|
|
40
|
+
throw new Error(`Function '${rendererEventName}' is readonly`);
|
|
41
|
+
},
|
|
42
|
+
enumerable: true
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
info.mainEvents.forEach(mainEventName => {
|
|
46
|
+
if (!info.scopes[mainEventName].has(scope))
|
|
47
|
+
return;
|
|
48
|
+
const eventNameOn = `on${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
49
|
+
const eventNameOnce = `once${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
50
|
+
Object.defineProperty(target, eventNameOn, {
|
|
51
|
+
get() {
|
|
52
|
+
return (handler) => {
|
|
53
|
+
return handleMainEvent(mainEventName, 'on', (result) => {
|
|
54
|
+
if (result.error) {
|
|
55
|
+
errorHandler(result.error, mainEventName);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (result.promiseChannel)
|
|
59
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
60
|
+
handler(result.value);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
set() {
|
|
65
|
+
throw new Error(`Function '${eventNameOn}' is readonly`);
|
|
66
|
+
},
|
|
67
|
+
enumerable: true
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(target, eventNameOnce, {
|
|
70
|
+
get() {
|
|
71
|
+
return (handler) => {
|
|
72
|
+
return handleMainEvent(mainEventName, 'once', (result) => {
|
|
73
|
+
if (result.error) {
|
|
74
|
+
errorHandler(result.error, mainEventName);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (result.promiseChannel)
|
|
78
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
79
|
+
handler(result.value);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
set() {
|
|
84
|
+
throw new Error(`Function '${eventNameOnce}' is readonly`);
|
|
85
|
+
},
|
|
86
|
+
enumerable: true
|
|
87
|
+
});
|
|
88
|
+
});
|
|
32
89
|
info.properties.forEach(propName => {
|
|
33
90
|
if (!info.scopes[propName].has(scope))
|
|
34
91
|
return;
|
|
@@ -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
|
*
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ipcMain } from 'electron';
|
|
2
|
+
import { Access, IPCChannel, Scope } from '../enums';
|
|
3
|
+
const publicInfo = {
|
|
4
|
+
properties: new Set(),
|
|
5
|
+
functions: new Set(),
|
|
6
|
+
mainEvents: new Set(),
|
|
7
|
+
rendererEvents: new Set(),
|
|
8
|
+
accesses: {},
|
|
9
|
+
scopes: {}
|
|
10
|
+
};
|
|
11
|
+
ipcMain.on(IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
12
|
+
/**
|
|
13
|
+
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
14
|
+
*
|
|
15
|
+
* @param name - name by which the event will be accessed
|
|
16
|
+
* @param scopes - event scopes
|
|
17
|
+
*/
|
|
18
|
+
export function publicMainEvent(name, receiver = ((v = undefined) => v), scopes = [Scope.preload, Scope.renderer]) {
|
|
19
|
+
const { mainEvents } = publicInfo;
|
|
20
|
+
const mainEmitChannel = IPCChannel.mainEventEmit + name;
|
|
21
|
+
const mainHandleChannel = IPCChannel.mainEventOn + name;
|
|
22
|
+
const mainHandleChannelOnce = IPCChannel.mainEventOnce + name;
|
|
23
|
+
let senders = [];
|
|
24
|
+
let sendersOnce = [];
|
|
25
|
+
mainEvents.add(name);
|
|
26
|
+
if (!publicInfo.scopes[name])
|
|
27
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
28
|
+
ipcMain.removeAllListeners(mainHandleChannel);
|
|
29
|
+
ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
30
|
+
ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
31
|
+
ipcMain.on(mainHandleChannelOnce, ({ sender }) => !sendersOnce.includes(sender) && sendersOnce.push(sender));
|
|
32
|
+
return (...args) => {
|
|
33
|
+
function filterSenders() {
|
|
34
|
+
senders = senders.filter(sender => !sender.isDestroyed());
|
|
35
|
+
sendersOnce = sendersOnce.filter(sender => !sender.isDestroyed());
|
|
36
|
+
}
|
|
37
|
+
filterSenders();
|
|
38
|
+
const allSenders = [...senders, ...sendersOnce];
|
|
39
|
+
try {
|
|
40
|
+
const result = receiver(...args);
|
|
41
|
+
if (result instanceof Promise) {
|
|
42
|
+
result
|
|
43
|
+
.then(value => {
|
|
44
|
+
filterSenders();
|
|
45
|
+
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { value }));
|
|
46
|
+
sendersOnce = [];
|
|
47
|
+
})
|
|
48
|
+
.catch(reason => {
|
|
49
|
+
filterSenders();
|
|
50
|
+
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { error: String(reason) }));
|
|
51
|
+
sendersOnce = [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
allSenders.forEach(sender => sender.send(mainEmitChannel, { value: result }));
|
|
56
|
+
sendersOnce = [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
allSenders.forEach(sender => sender.send(mainEmitChannel, { error: String(error) }));
|
|
61
|
+
sendersOnce = [];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
67
|
+
*
|
|
68
|
+
* @param name - name by which the event will be accessed
|
|
69
|
+
* @param scopes - event scopes
|
|
70
|
+
*/
|
|
71
|
+
export function publicRendererEvent(name, receiver = ((v = undefined) => v), scopes = [Scope.preload, Scope.renderer]) {
|
|
72
|
+
if (name.startsWith('on')) {
|
|
73
|
+
name = name.replace('on', '');
|
|
74
|
+
name = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
75
|
+
}
|
|
76
|
+
const { rendererEvents } = publicInfo;
|
|
77
|
+
const rendererEmitChannel = IPCChannel.rendererEventEmit + name;
|
|
78
|
+
const handlers = new Set();
|
|
79
|
+
const handlersOnce = new Set();
|
|
80
|
+
rendererEvents.add(name);
|
|
81
|
+
if (!publicInfo.scopes[name])
|
|
82
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
83
|
+
ipcMain.removeAllListeners(rendererEmitChannel);
|
|
84
|
+
ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
85
|
+
if (result.error)
|
|
86
|
+
throw new Error(result.error);
|
|
87
|
+
const converted = receiver(result.value);
|
|
88
|
+
handlers.forEach(handler => handler(converted));
|
|
89
|
+
handlersOnce.forEach(handler => handler(converted));
|
|
90
|
+
handlersOnce.clear();
|
|
91
|
+
});
|
|
92
|
+
return (handler, isOnce = false) => {
|
|
93
|
+
if (isOnce) {
|
|
94
|
+
handlersOnce.add(handler);
|
|
95
|
+
return () => handlersOnce.delete(handler);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
handlers.add(handler);
|
|
99
|
+
return () => handlers.delete(handler);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Makes the function available for **renderer** and **preload** processes.
|
|
105
|
+
*
|
|
106
|
+
* _only for function_
|
|
107
|
+
* @param name - name by which the function will be accessed
|
|
108
|
+
* @param func - linked function
|
|
109
|
+
* @param scopes - function scopes
|
|
110
|
+
*/
|
|
111
|
+
export function publicFunction(name, func, scopes = [Scope.preload, Scope.renderer]) {
|
|
112
|
+
const { functions } = publicInfo;
|
|
113
|
+
const channel = IPCChannel.functionCall + name;
|
|
114
|
+
functions.add(name);
|
|
115
|
+
if (!publicInfo.scopes[name])
|
|
116
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
117
|
+
ipcMain.removeAllListeners(channel);
|
|
118
|
+
ipcMain.on(channel, (e, ...args) => {
|
|
119
|
+
try {
|
|
120
|
+
const result = func(...args);
|
|
121
|
+
if (result instanceof Promise) {
|
|
122
|
+
const promiseChannel = channel + IPCChannel.promisePostfix;
|
|
123
|
+
result
|
|
124
|
+
.then(value => e.sender.send(promiseChannel, { value }))
|
|
125
|
+
.catch(reason => e.sender.send(promiseChannel, { error: String(reason) }));
|
|
126
|
+
e.returnValue = { promiseChannel };
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
e.returnValue = { value: result };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
e.returnValue = { error: String(error) };
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Makes the function available for **renderer** and **preload** processes.
|
|
139
|
+
*
|
|
140
|
+
* _only for variables_
|
|
141
|
+
* @param name - name by which the variable will be accessed
|
|
142
|
+
* @param value - variable getter/setter
|
|
143
|
+
* @param scopes - variable scopes
|
|
144
|
+
*/
|
|
145
|
+
export function publicVariable(name, value, scopes = [Scope.renderer, Scope.preload]) {
|
|
146
|
+
const { properties } = publicInfo;
|
|
147
|
+
const getChannel = IPCChannel.propertyGet + name;
|
|
148
|
+
const setChannel = IPCChannel.propertySet + name;
|
|
149
|
+
const { get: getter, set: setter } = value;
|
|
150
|
+
properties.add(name);
|
|
151
|
+
if (!publicInfo.scopes[name])
|
|
152
|
+
publicInfo.scopes[name] = new Set(scopes);
|
|
153
|
+
if (!publicInfo.accesses[name]) {
|
|
154
|
+
const accesses = [];
|
|
155
|
+
getter && accesses.push(Access.get);
|
|
156
|
+
setter && accesses.push(Access.set);
|
|
157
|
+
publicInfo.accesses[name] = new Set(accesses);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const accesses = publicInfo.accesses[name];
|
|
161
|
+
getter && accesses.add(Access.get);
|
|
162
|
+
setter && accesses.add(Access.set);
|
|
163
|
+
}
|
|
164
|
+
if (getter) {
|
|
165
|
+
ipcMain.removeAllListeners(getChannel);
|
|
166
|
+
ipcMain.on(getChannel, event => {
|
|
167
|
+
try {
|
|
168
|
+
const result = getter();
|
|
169
|
+
event.returnValue = { value: result };
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
event.returnValue = { error };
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (setter) {
|
|
177
|
+
ipcMain.removeAllListeners(setChannel);
|
|
178
|
+
ipcMain.on(setChannel, (event, ...args) => {
|
|
179
|
+
try {
|
|
180
|
+
setter(args[0]);
|
|
181
|
+
event.returnValue = { value: null };
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
event.returnValue = { error };
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export function addScope(key, scope) {
|
|
190
|
+
publicInfo.scopes[key] = new Set([scope]);
|
|
191
|
+
}
|
|
192
|
+
export function addAccess(key, access) {
|
|
193
|
+
publicInfo.accesses[key] = new Set([access]);
|
|
194
|
+
}
|
package/{lib → esm}/types.d.ts
RENAMED
|
@@ -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/package.json
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emr-bridge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Allows you to easily give access to main methods from the renderer process",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "esm/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"compile": "tsc --project ./tsconfig.json && tsc --project ./tsconfig.cjs.json"
|
|
8
8
|
},
|
|
9
|
-
"types": "
|
|
9
|
+
"types": "esm/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"
|
|
11
|
+
"esm",
|
|
12
12
|
"cjs"
|
|
13
13
|
],
|
|
14
14
|
"typesVersions": {
|
|
15
15
|
"*": {
|
|
16
16
|
".": [
|
|
17
|
-
"./
|
|
17
|
+
"./esm/index.d.ts"
|
|
18
18
|
],
|
|
19
19
|
"renderer": [
|
|
20
|
-
"./
|
|
20
|
+
"./esm/renderer.d.ts"
|
|
21
21
|
],
|
|
22
22
|
"preload": [
|
|
23
|
-
"./
|
|
23
|
+
"./esm/preload.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"exp": [
|
|
26
|
+
"./esm/exp.d.ts"
|
|
24
27
|
],
|
|
25
28
|
"main": [
|
|
26
|
-
"./
|
|
29
|
+
"./esm/index.d.ts"
|
|
30
|
+
],
|
|
31
|
+
"main/exp": [
|
|
32
|
+
"./esm/exp.d.ts"
|
|
27
33
|
],
|
|
28
34
|
"cjs": [
|
|
29
35
|
"./cjs/index.d.ts"
|
|
@@ -34,21 +40,31 @@
|
|
|
34
40
|
"cjs/preload": [
|
|
35
41
|
"./cjs/preload.d.ts"
|
|
36
42
|
],
|
|
43
|
+
"cjs/exp": [
|
|
44
|
+
"./cjs/exp.d.ts"
|
|
45
|
+
],
|
|
37
46
|
"cjs/main": [
|
|
38
47
|
"./cjs/index.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"cjs/main/exp": [
|
|
50
|
+
"./cjs/exp.d.ts"
|
|
39
51
|
]
|
|
40
52
|
}
|
|
41
53
|
},
|
|
42
54
|
"exports": {
|
|
43
|
-
".": "./
|
|
55
|
+
".": "./esm/index.js",
|
|
56
|
+
"./renderer": "./esm/renderer.js",
|
|
57
|
+
"./preload": "./esm/preload.js",
|
|
58
|
+
"./exp": "./esm/exp.js",
|
|
59
|
+
"./main": "./esm/index.js",
|
|
60
|
+
"./main/exp": "./esm/exp.js",
|
|
61
|
+
"./package.json": "./package.json",
|
|
44
62
|
"./cjs": "./cjs/index.js",
|
|
63
|
+
"./cjs/exp": "./cjs/exp.js",
|
|
45
64
|
"./cjs/renderer": "./cjs/renderer.js",
|
|
46
65
|
"./cjs/preload": "./cjs/preload.js",
|
|
47
66
|
"./cjs/main": "./cjs/index.js",
|
|
48
|
-
"./
|
|
49
|
-
"./preload": "./lib/preload.js",
|
|
50
|
-
"./main": "./lib/index.js",
|
|
51
|
-
"./package.json": "./package.json"
|
|
67
|
+
"./cjs/main/exp": "./cjs/exp.js"
|
|
52
68
|
},
|
|
53
69
|
"repository": {
|
|
54
70
|
"type": "git",
|
package/lib/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
|
-
export { providePublic, publicMethod as publicMethodExp, publicProperty as publicPropertyExp, publicStaticMethod as publicStaticMethodExp, publicStaticProperty as publicStaticPropertyExp } from './scripts/oldDecorators';
|
|
4
|
-
export { publicFunction, publicVariable } from './scripts/publish';
|
|
5
|
-
export type { IPublishMethodArgs, IPublishPropertyArgs, PublicFunction, PublicProperty } from './types';
|
package/lib/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
|
-
export { providePublic, publicMethod as publicMethodExp, publicProperty as publicPropertyExp, publicStaticMethod as publicStaticMethodExp, publicStaticProperty as publicStaticPropertyExp } from './scripts/oldDecorators';
|
|
4
|
-
export { publicFunction, publicVariable } from './scripts/publish';
|
package/lib/scripts/Main.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
getVariable(name) {
|
|
19
|
-
return ipcRenderer.sendSync(IPCChannel.propertyGet + name);
|
|
20
|
-
},
|
|
21
|
-
setVariable(name, value) {
|
|
22
|
-
return ipcRenderer.sendSync(IPCChannel.propertySet + name, value);
|
|
23
|
-
},
|
|
24
|
-
waitPromise(channel) {
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
ipcRenderer.once(channel, (_, result) => {
|
|
27
|
-
if (result.error)
|
|
28
|
-
reject(result.error);
|
|
29
|
-
else
|
|
30
|
-
resolve(result.value);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
export default Main;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { IPublishMethodArgs, IPublishPropertyArgs } 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 property available for **renderer** and **preload** processes.
|
|
62
|
-
*
|
|
63
|
-
* _only for static_
|
|
64
|
-
*
|
|
65
|
-
* _experimental decorators_
|
|
66
|
-
*/
|
|
67
|
-
export declare function publicStaticProperty(): PropertyDecorator;
|
|
68
|
-
/**
|
|
69
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
70
|
-
*
|
|
71
|
-
* _only for static_
|
|
72
|
-
*
|
|
73
|
-
* _experimental decorators_
|
|
74
|
-
* @param name - name by which the property will be accessed
|
|
75
|
-
*/
|
|
76
|
-
export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
77
|
-
/**
|
|
78
|
-
* Makes the property 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 publicStaticProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
86
|
-
/**
|
|
87
|
-
* Makes the property 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 publicProperty(): PropertyDecorator;
|
|
96
|
-
/**
|
|
97
|
-
* Makes the property 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 property will be accessed
|
|
105
|
-
*/
|
|
106
|
-
export declare function publicProperty(name: string): PropertyDecorator;
|
|
107
|
-
/**
|
|
108
|
-
* Makes the property 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 publicProperty(args: IPublishPropertyArgs): PropertyDecorator;
|
|
118
|
-
/**
|
|
119
|
-
* Binds all public entities of a class to a specific instance.
|
|
120
|
-
*
|
|
121
|
-
* _only for class instance_
|
|
122
|
-
*/
|
|
123
|
-
export declare function providePublic<InstanceType>(instance: InstanceType): InstanceType;
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
|
26
|
-
};
|
|
27
|
-
info.functions.forEach(funcName => {
|
|
28
|
-
Object.defineProperty(provider.provided.functions, funcName, {
|
|
29
|
-
value(...args) {
|
|
30
|
-
return ipcRenderer.sendSync(IPCChannel.functionCall + funcName, ...args);
|
|
31
|
-
},
|
|
32
|
-
enumerable: true
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
info.properties.forEach(propName => {
|
|
36
|
-
Object.defineProperty(provider.provided.properties, propName, {
|
|
37
|
-
get() {
|
|
38
|
-
return ipcRenderer.sendSync(IPCChannel.propertyGet + propName);
|
|
39
|
-
},
|
|
40
|
-
set(value) {
|
|
41
|
-
ipcRenderer.sendSync(IPCChannel.propertySet + propName, value);
|
|
42
|
-
},
|
|
43
|
-
enumerable: true
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
if (contextIsolation)
|
|
47
|
-
contextBridge.exposeInMainWorld('__provider__', provider);
|
|
48
|
-
else
|
|
49
|
-
window.__provider__ = provider;
|
|
50
|
-
}
|
|
51
|
-
export default provideFromMain;
|