emr-bridge 1.7.1 → 2.0.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 +173 -366
- package/cjs/entries/index.d.ts +1 -0
- package/cjs/entries/index.js +6 -0
- package/cjs/entries/main.d.ts +2 -0
- package/cjs/entries/main.js +27 -0
- package/cjs/entries/preload.d.ts +3 -0
- package/cjs/entries/preload.js +29 -0
- package/cjs/entries/renderer.d.ts +2 -0
- package/cjs/entries/renderer.js +27 -0
- package/cjs/enums.d.ts +5 -14
- package/cjs/enums.js +12 -23
- package/cjs/errors.d.ts +42 -10
- package/cjs/errors.js +77 -23
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +11 -13
- package/cjs/main.d.ts +2 -4
- package/cjs/main.js +4 -13
- package/cjs/preload.d.ts +2 -2
- package/cjs/preload.js +3 -3
- package/cjs/renderer.d.ts +1 -1
- package/cjs/scripts/base-bridge.d.ts +95 -0
- package/cjs/scripts/base-bridge.js +128 -0
- package/cjs/scripts/bridge.d.ts +3 -3
- package/cjs/scripts/bridge.js +48 -36
- package/cjs/scripts/helpers/env.d.ts +19 -0
- package/cjs/scripts/helpers/env.js +28 -0
- package/cjs/scripts/helpers/error-thrower.d.ts +3 -0
- package/cjs/scripts/helpers/error-thrower.js +8 -0
- package/cjs/scripts/helpers/errors.d.ts +12 -0
- package/cjs/scripts/helpers/errors.js +17 -0
- package/cjs/scripts/helpers/id.d.ts +9 -0
- package/cjs/scripts/helpers/id.js +14 -0
- package/cjs/scripts/helpers/index.d.ts +8 -0
- package/cjs/scripts/helpers/index.js +22 -0
- package/cjs/scripts/helpers/ipc-channel.d.ts +75 -0
- package/cjs/scripts/helpers/ipc-channel.js +78 -0
- package/cjs/scripts/helpers/ipc-event-in-main.d.ts +24 -0
- package/cjs/scripts/helpers/ipc-event-in-main.js +30 -0
- package/cjs/scripts/helpers/ipc-result.d.ts +26 -0
- package/cjs/scripts/helpers/ipc-result.js +48 -0
- package/cjs/scripts/helpers/main-event.d.ts +8 -0
- package/cjs/scripts/helpers/main-event.js +15 -0
- package/cjs/scripts/helpers/transfer.d.ts +33 -0
- package/cjs/scripts/helpers/transfer.js +57 -0
- package/cjs/scripts/helpers/web-contents-container.d.ts +12 -0
- package/cjs/scripts/helpers/web-contents-container.js +34 -0
- package/cjs/scripts/helpers/web-contents-events-container.d.ts +56 -0
- package/cjs/scripts/helpers/web-contents-events-container.js +81 -0
- package/cjs/scripts/main/publish.d.ts +36 -0
- package/cjs/scripts/main/publish.js +186 -0
- package/cjs/scripts/preload/bridge.d.ts +27 -0
- package/cjs/scripts/preload/bridge.js +85 -0
- package/cjs/scripts/preload/provider.d.ts +7 -0
- package/cjs/scripts/preload/provider.js +89 -0
- package/cjs/scripts/preload-bridge.d.ts +20 -0
- package/cjs/scripts/preload-bridge.js +76 -0
- package/cjs/scripts/preload-provider.js +34 -50
- package/cjs/scripts/provider.d.ts +17 -15
- package/cjs/scripts/provider.js +69 -90
- package/cjs/scripts/publish.d.ts +19 -18
- package/cjs/scripts/publish.js +96 -174
- package/cjs/scripts/renderer/bridge.d.ts +6 -0
- package/cjs/scripts/renderer/bridge.js +74 -0
- package/cjs/scripts/renderer/tunnels.d.ts +171 -0
- package/cjs/scripts/renderer/tunnels.js +205 -0
- package/cjs/scripts/renderer-tunnels.d.ts +19 -21
- package/cjs/scripts/renderer-tunnels.js +52 -57
- package/cjs/types.d.ts +189 -64
- package/esm/entries/index.d.ts +1 -0
- package/esm/entries/index.js +5 -0
- package/esm/entries/main.d.ts +2 -0
- package/esm/entries/main.js +5 -0
- package/esm/entries/preload.d.ts +3 -0
- package/esm/entries/preload.js +7 -0
- package/esm/entries/renderer.d.ts +2 -0
- package/esm/entries/renderer.js +6 -0
- package/esm/enums.d.ts +5 -14
- package/esm/enums.js +11 -22
- package/esm/errors.d.ts +42 -10
- package/esm/errors.js +69 -16
- package/esm/helpers.d.ts +41 -0
- package/esm/helpers.js +96 -0
- package/esm/index.d.ts +4 -4
- package/esm/index.js +3 -3
- package/esm/main.d.ts +2 -4
- package/esm/main.js +1 -3
- package/esm/preload.d.ts +2 -2
- package/esm/preload.js +1 -1
- package/esm/renderer.d.ts +1 -1
- package/esm/scripts/base-bridge.d.ts +95 -0
- package/esm/scripts/base-bridge.js +125 -0
- package/esm/scripts/bridge.d.ts +3 -3
- package/esm/scripts/bridge.js +49 -37
- package/esm/scripts/helpers/electron-importer.d.ts +4 -0
- package/esm/scripts/helpers/electron-importer.js +16 -0
- package/esm/scripts/helpers/env.d.ts +19 -0
- package/esm/scripts/helpers/env.js +25 -0
- package/esm/scripts/helpers/error-thrower.d.ts +3 -0
- package/esm/scripts/helpers/error-thrower.js +5 -0
- package/esm/scripts/helpers/errors.d.ts +12 -0
- package/esm/scripts/helpers/errors.js +14 -0
- package/esm/scripts/helpers/id.d.ts +9 -0
- package/esm/scripts/helpers/id.js +11 -0
- package/esm/scripts/helpers/index.d.ts +8 -0
- package/esm/scripts/helpers/index.js +8 -0
- package/esm/scripts/helpers/ipc-channel.d.ts +75 -0
- package/esm/scripts/helpers/ipc-channel.js +76 -0
- package/esm/scripts/helpers/ipc-event-in-main.d.ts +24 -0
- package/esm/scripts/helpers/ipc-event-in-main.js +27 -0
- package/esm/scripts/helpers/ipc-result.d.ts +26 -0
- package/esm/scripts/helpers/ipc-result.js +42 -0
- package/esm/scripts/helpers/main-event.d.ts +8 -0
- package/esm/scripts/helpers/main-event.js +12 -0
- package/esm/scripts/helpers/transfer.d.ts +33 -0
- package/esm/scripts/helpers/transfer.js +54 -0
- package/esm/scripts/helpers/web-contents-container.d.ts +12 -0
- package/esm/scripts/helpers/web-contents-container.js +31 -0
- package/esm/scripts/helpers/web-contents-events-container.d.ts +56 -0
- package/esm/scripts/helpers/web-contents-events-container.js +78 -0
- package/esm/scripts/main/publish.d.ts +36 -0
- package/esm/scripts/main/publish.js +179 -0
- package/esm/scripts/main.d.ts +3 -3
- package/esm/scripts/main.js +41 -39
- package/esm/scripts/preload/bridge.d.ts +27 -0
- package/esm/scripts/preload/bridge.js +77 -0
- package/esm/scripts/preload/provider.d.ts +7 -0
- package/esm/scripts/preload/provider.js +84 -0
- package/esm/scripts/preload-bridge.d.ts +20 -0
- package/esm/scripts/preload-bridge.js +68 -0
- package/esm/scripts/preload-provider.js +34 -50
- package/esm/scripts/provider.d.ts +17 -15
- package/esm/scripts/provider.js +70 -91
- package/esm/scripts/publish.d.ts +19 -18
- package/esm/scripts/publish.js +89 -162
- package/esm/scripts/renderer/bridge.d.ts +6 -0
- package/esm/scripts/renderer/bridge.js +69 -0
- package/esm/scripts/renderer/tunnels.d.ts +171 -0
- package/esm/scripts/renderer/tunnels.js +203 -0
- package/esm/scripts/renderer-tunnels.d.ts +19 -21
- package/esm/scripts/renderer-tunnels.js +53 -55
- package/esm/types.d.ts +189 -64
- package/package.json +23 -41
- package/cjs/exp.d.ts +0 -4
- package/cjs/exp.js +0 -19
- package/cjs/scripts/main.d.ts +0 -8
- package/cjs/scripts/main.js +0 -72
- package/cjs/scripts/new-decorators.d.ts +0 -150
- package/cjs/scripts/new-decorators.js +0 -141
- package/cjs/scripts/old-decorators.d.ts +0 -185
- package/cjs/scripts/old-decorators.js +0 -132
- package/esm/exp.d.ts +0 -4
- package/esm/exp.js +0 -3
- package/esm/scripts/new-decorators.d.ts +0 -150
- package/esm/scripts/new-decorators.js +0 -132
- package/esm/scripts/old-decorators.d.ts +0 -185
- package/esm/scripts/old-decorators.js +0 -122
package/cjs/scripts/publish.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { PublicFunction, PublicProperty, RendererEvent } from '../types.js';
|
|
1
|
+
import type { EventListener, EventUnsubscribe, IHasSnapshot, IPublicProperty, PublicFunction } from '../types.js';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Call the event from **main** process.
|
|
5
4
|
*
|
|
6
|
-
* @param name -
|
|
7
|
-
* @param procFn - function of processing before sending the event
|
|
8
|
-
* @param scopes - event scopes
|
|
5
|
+
* @param name - event name
|
|
9
6
|
*/
|
|
10
|
-
export declare function
|
|
7
|
+
export declare function emitEvent(name: string, value?: any): void;
|
|
11
8
|
/**
|
|
12
|
-
*
|
|
9
|
+
* Handle event from **main** process.
|
|
13
10
|
*
|
|
14
|
-
* @param name -
|
|
15
|
-
* @param
|
|
16
|
-
* @param scopes - event scopes
|
|
11
|
+
* @param name - event name
|
|
12
|
+
* @param listener - event handler
|
|
17
13
|
*/
|
|
18
|
-
export declare function
|
|
14
|
+
export declare function on<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
15
|
+
/**
|
|
16
|
+
* Handle event from **main** process.
|
|
17
|
+
*
|
|
18
|
+
* @param name - event name
|
|
19
|
+
* @param listener - event handler
|
|
20
|
+
*/
|
|
21
|
+
export declare function once<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
19
22
|
/**
|
|
20
23
|
* Makes the function available for **renderer** and **preload** processes.
|
|
21
24
|
*
|
|
@@ -23,9 +26,10 @@ export declare function publicRendererEvent<In = void, Out = In, ProcFn extends
|
|
|
23
26
|
*
|
|
24
27
|
* @param name - name by which the function will be accessed
|
|
25
28
|
* @param func - linked function
|
|
26
|
-
* @param scopes - function scopes
|
|
27
29
|
*/
|
|
28
|
-
export declare function publicFunction<
|
|
30
|
+
export declare function publicFunction<TFunc extends PublicFunction>(name: string, func: TFunc, receives?: {
|
|
31
|
+
new (): IHasSnapshot;
|
|
32
|
+
}[]): void;
|
|
29
33
|
/**
|
|
30
34
|
* Makes the function available for **renderer** and **preload** processes.
|
|
31
35
|
*
|
|
@@ -33,8 +37,5 @@ export declare function publicFunction<F extends PublicFunction>(name: string, f
|
|
|
33
37
|
*
|
|
34
38
|
* @param name - name by which the variable will be accessed
|
|
35
39
|
* @param value - variable getter/setter
|
|
36
|
-
* @param scopes - variable scopes
|
|
37
40
|
*/
|
|
38
|
-
export declare function publicVariable<T>(name: string, value:
|
|
39
|
-
export declare function addScope(key: string, scope: Scope): void;
|
|
40
|
-
export declare function addAccess(key: string, access: Access): void;
|
|
41
|
+
export declare function publicVariable<T>(name: string, value: IPublicProperty<T>): void;
|
package/cjs/scripts/publish.js
CHANGED
|
@@ -1,131 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
3
|
+
exports.emitEvent = emitEvent;
|
|
4
|
+
exports.on = on;
|
|
5
|
+
exports.once = once;
|
|
6
|
+
exports.publicFunction = publicFunction;
|
|
7
|
+
exports.publicVariable = publicVariable;
|
|
8
|
+
const electron_1 = require("electron");
|
|
8
9
|
const enums_js_1 = require("../enums.js");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
accesses: new Map(),
|
|
15
|
-
scopes: new Map()
|
|
10
|
+
const errors_js_1 = require("../errors.js");
|
|
11
|
+
const index_js_1 = require("./helpers/index.js");
|
|
12
|
+
const entitiesInfo = {
|
|
13
|
+
variables: new Set(),
|
|
14
|
+
functions: new Set()
|
|
16
15
|
};
|
|
16
|
+
const mainEventHandlers = new index_js_1.WebContentsContainer();
|
|
17
17
|
/** Выбрасывает ошибку если используется не в том процессе */
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
18
|
+
const canThrowError = (index_js_1.Env.global.hasWindow || !electron_1.ipcMain)
|
|
19
|
+
? index_js_1.ErrorThrower.throws(errors_js_1.PublishMethodsUnavailable)
|
|
20
|
+
: () => { };
|
|
21
|
+
electron_1.ipcMain?.on(enums_js_1.IpcChannel.getPublicInfo, e => new index_js_1.MainEvent(e).return(entitiesInfo));
|
|
22
|
+
electron_1.ipcMain?.on(enums_js_1.IpcChannel.eventOn, (e, { value }) => mainEventHandlers.addOn(value, e.sender));
|
|
23
|
+
electron_1.ipcMain?.on(enums_js_1.IpcChannel.eventOnce, (e, { value }) => mainEventHandlers.addOn(value, e.sender));
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Call the event from **main** process.
|
|
27
26
|
*
|
|
28
|
-
* @param name -
|
|
29
|
-
* @param procFn - function of processing before sending the event
|
|
30
|
-
* @param scopes - event scopes
|
|
27
|
+
* @param name - event name
|
|
31
28
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
ipcMain.removeAllListeners(mainHandleChannel);
|
|
49
|
-
ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
50
|
-
ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
51
|
-
ipcMain.on(mainHandleChannelOnce, ({ sender }) => !sendersOnce.includes(sender) && sendersOnce.push(sender));
|
|
52
|
-
return (...args) => {
|
|
53
|
-
function filterSenders() {
|
|
54
|
-
senders = senders.filter(sender => !sender.isDestroyed());
|
|
55
|
-
sendersOnce = sendersOnce.filter(sender => !sender.isDestroyed());
|
|
29
|
+
function emitEvent(name, value) {
|
|
30
|
+
canThrowError();
|
|
31
|
+
const emitChannel = enums_js_1.IpcChannel.eventEmit + name;
|
|
32
|
+
try {
|
|
33
|
+
if (value instanceof Promise) {
|
|
34
|
+
value
|
|
35
|
+
.then(val => {
|
|
36
|
+
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, index_js_1.IpcResult.withValue(val)));
|
|
37
|
+
mainEventHandlers.clearOnce(name);
|
|
38
|
+
})
|
|
39
|
+
.catch(reason => {
|
|
40
|
+
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, index_js_1.IpcResult.withError(reason)));
|
|
41
|
+
mainEventHandlers.clearOnce(name);
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
filterSenders();
|
|
65
|
-
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { value }));
|
|
66
|
-
sendersOnce = [];
|
|
67
|
-
})
|
|
68
|
-
.catch(reason => {
|
|
69
|
-
filterSenders();
|
|
70
|
-
[...senders, ...sendersOnce].forEach(sender => sender.send(mainEmitChannel, { error: String(reason?.stack || reason) }));
|
|
71
|
-
sendersOnce = [];
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
allSenders.forEach(sender => sender.send(mainEmitChannel, { value: result }));
|
|
76
|
-
sendersOnce = [];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
allSenders.forEach(sender => sender.send(mainEmitChannel, { error: String(error?.stack || error) }));
|
|
81
|
-
sendersOnce = [];
|
|
82
|
-
}
|
|
83
|
-
};
|
|
45
|
+
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, index_js_1.IpcResult.withValue(value)));
|
|
46
|
+
mainEventHandlers.clearOnce(name);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, index_js_1.IpcResult.withError(error)));
|
|
50
|
+
mainEventHandlers.clearOnce(name);
|
|
51
|
+
}
|
|
84
52
|
}
|
|
85
|
-
exports.publicMainEvent = publicMainEvent;
|
|
86
53
|
/**
|
|
87
|
-
*
|
|
54
|
+
* Handle event from **main** process.
|
|
88
55
|
*
|
|
89
|
-
* @param name -
|
|
90
|
-
* @param
|
|
91
|
-
* @param scopes - event scopes
|
|
56
|
+
* @param name - event name
|
|
57
|
+
* @param listener - event handler
|
|
92
58
|
*/
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const converted = procFn(value);
|
|
113
|
-
handlers.forEach(handler => handler(converted));
|
|
114
|
-
handlersOnce.forEach(handler => handler(converted));
|
|
115
|
-
handlersOnce.clear();
|
|
116
|
-
});
|
|
117
|
-
return (handler, isOnce = false) => {
|
|
118
|
-
if (isOnce) {
|
|
119
|
-
handlersOnce.add(handler);
|
|
120
|
-
return () => handlersOnce.delete(handler);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
handlers.add(handler);
|
|
124
|
-
return () => handlers.delete(handler);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
59
|
+
function on(name, listener) {
|
|
60
|
+
canThrowError();
|
|
61
|
+
const emitChannel = enums_js_1.IpcChannel.eventEmit + name;
|
|
62
|
+
const handler = (_, { value }) => listener(value);
|
|
63
|
+
electron_1.ipcMain.on(emitChannel, handler);
|
|
64
|
+
return () => electron_1.ipcMain.removeListener(emitChannel, handler);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Handle event from **main** process.
|
|
68
|
+
*
|
|
69
|
+
* @param name - event name
|
|
70
|
+
* @param listener - event handler
|
|
71
|
+
*/
|
|
72
|
+
function once(name, listener) {
|
|
73
|
+
canThrowError();
|
|
74
|
+
const emitChannel = enums_js_1.IpcChannel.eventEmit + name;
|
|
75
|
+
const handler = (_, { value }) => listener(value);
|
|
76
|
+
electron_1.ipcMain.once(emitChannel, handler);
|
|
77
|
+
return () => electron_1.ipcMain.removeListener(emitChannel, handler);
|
|
127
78
|
}
|
|
128
|
-
exports.publicRendererEvent = publicRendererEvent;
|
|
129
79
|
/**
|
|
130
80
|
* Makes the function available for **renderer** and **preload** processes.
|
|
131
81
|
*
|
|
@@ -133,38 +83,35 @@ exports.publicRendererEvent = publicRendererEvent;
|
|
|
133
83
|
*
|
|
134
84
|
* @param name - name by which the function will be accessed
|
|
135
85
|
* @param func - linked function
|
|
136
|
-
* @param scopes - function scopes
|
|
137
86
|
*/
|
|
138
|
-
function publicFunction(name, func,
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
publicInfo.scopes.set(name, new Set(scopes));
|
|
146
|
-
}
|
|
147
|
-
ipcMain.removeAllListeners(channel);
|
|
148
|
-
ipcMain.on(channel, (e, { args, secret }) => {
|
|
87
|
+
function publicFunction(name, func, receives = []) {
|
|
88
|
+
canThrowError();
|
|
89
|
+
const channel = enums_js_1.IpcChannel.functionCall + name;
|
|
90
|
+
entitiesInfo.functions.add(name);
|
|
91
|
+
electron_1.ipcMain.removeAllListeners(channel);
|
|
92
|
+
electron_1.ipcMain.on(channel, (e, { args, id }) => {
|
|
93
|
+
const event = new index_js_1.MainEvent(e);
|
|
149
94
|
try {
|
|
150
|
-
const
|
|
95
|
+
const preparedArgs = args.map((arg, index) => (index_js_1.Transfer.isSnapshotValue(arg) && receives[index]
|
|
96
|
+
? index_js_1.Transfer.getFromSnapshot(arg, receives[index])
|
|
97
|
+
: arg));
|
|
98
|
+
const result = func(...preparedArgs);
|
|
151
99
|
if (result instanceof Promise) {
|
|
152
|
-
const promiseChannel = channel + enums_js_1.
|
|
100
|
+
const promiseChannel = channel + enums_js_1.IpcChannel.promisePostfix;
|
|
153
101
|
result
|
|
154
|
-
.then(value =>
|
|
155
|
-
.catch(reason =>
|
|
156
|
-
|
|
102
|
+
.then(value => event.send(promiseChannel, index_js_1.IpcResult.withValue(value, id)))
|
|
103
|
+
.catch(reason => event.send(promiseChannel, index_js_1.IpcResult.withError(reason, id)));
|
|
104
|
+
event.return(index_js_1.IpcResult.withPromise(promiseChannel));
|
|
157
105
|
}
|
|
158
106
|
else {
|
|
159
|
-
|
|
107
|
+
event.return(index_js_1.IpcResult.withValue(result));
|
|
160
108
|
}
|
|
161
109
|
}
|
|
162
110
|
catch (error) {
|
|
163
|
-
|
|
111
|
+
event.return(index_js_1.IpcResult.withError(error));
|
|
164
112
|
}
|
|
165
113
|
});
|
|
166
114
|
}
|
|
167
|
-
exports.publicFunction = publicFunction;
|
|
168
115
|
/**
|
|
169
116
|
* Makes the function available for **renderer** and **preload** processes.
|
|
170
117
|
*
|
|
@@ -172,61 +119,36 @@ exports.publicFunction = publicFunction;
|
|
|
172
119
|
*
|
|
173
120
|
* @param name - name by which the variable will be accessed
|
|
174
121
|
* @param value - variable getter/setter
|
|
175
|
-
* @param scopes - variable scopes
|
|
176
122
|
*/
|
|
177
|
-
function publicVariable(name, value
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const getChannel = enums_js_1.IPCChannel.propertyGet + name;
|
|
182
|
-
const setChannel = enums_js_1.IPCChannel.propertySet + name;
|
|
123
|
+
function publicVariable(name, value) {
|
|
124
|
+
canThrowError();
|
|
125
|
+
const getChannel = enums_js_1.IpcChannel.propertyGet + name;
|
|
126
|
+
const setChannel = enums_js_1.IpcChannel.propertySet + name;
|
|
183
127
|
const { get: getter, set: setter } = value;
|
|
184
|
-
|
|
185
|
-
if (!publicInfo.scopes.has(name)) {
|
|
186
|
-
publicInfo.scopes.set(name, new Set(scopes));
|
|
187
|
-
}
|
|
188
|
-
if (!publicInfo.accesses.has(name)) {
|
|
189
|
-
const accesses = [];
|
|
190
|
-
getter && accesses.push(enums_js_1.Access.get);
|
|
191
|
-
setter && accesses.push(enums_js_1.Access.set);
|
|
192
|
-
publicInfo.accesses.set(name, new Set(accesses));
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
const accesses = publicInfo.accesses.get(name);
|
|
196
|
-
getter && accesses.add(enums_js_1.Access.get);
|
|
197
|
-
setter && accesses.add(enums_js_1.Access.set);
|
|
198
|
-
}
|
|
128
|
+
entitiesInfo.variables.add(name);
|
|
199
129
|
if (getter) {
|
|
200
|
-
ipcMain.removeAllListeners(getChannel);
|
|
201
|
-
ipcMain.on(getChannel,
|
|
130
|
+
electron_1.ipcMain.removeAllListeners(getChannel);
|
|
131
|
+
electron_1.ipcMain.on(getChannel, e => {
|
|
132
|
+
const event = new index_js_1.MainEvent(e);
|
|
202
133
|
try {
|
|
203
|
-
|
|
204
|
-
event.returnValue = { value: result };
|
|
134
|
+
event.return(index_js_1.IpcResult.withValue(getter()));
|
|
205
135
|
}
|
|
206
136
|
catch (error) {
|
|
207
|
-
event.
|
|
137
|
+
event.return(index_js_1.IpcResult.withError(error));
|
|
208
138
|
}
|
|
209
139
|
});
|
|
210
140
|
}
|
|
211
141
|
if (setter) {
|
|
212
|
-
ipcMain.removeAllListeners(setChannel);
|
|
213
|
-
ipcMain.on(setChannel, (
|
|
142
|
+
electron_1.ipcMain.removeAllListeners(setChannel);
|
|
143
|
+
electron_1.ipcMain.on(setChannel, (e, { args }) => {
|
|
144
|
+
const event = new index_js_1.MainEvent(e);
|
|
214
145
|
try {
|
|
215
146
|
setter(args.at(0));
|
|
216
|
-
event.
|
|
147
|
+
event.return(index_js_1.IpcResult.withValue(null));
|
|
217
148
|
}
|
|
218
149
|
catch (error) {
|
|
219
|
-
event.
|
|
150
|
+
event.return(index_js_1.IpcResult.withError(error));
|
|
220
151
|
}
|
|
221
152
|
});
|
|
222
153
|
}
|
|
223
154
|
}
|
|
224
|
-
exports.publicVariable = publicVariable;
|
|
225
|
-
function addScope(key, scope) {
|
|
226
|
-
publicInfo.scopes.set(key, new Set([scope]));
|
|
227
|
-
}
|
|
228
|
-
exports.addScope = addScope;
|
|
229
|
-
function addAccess(key, access) {
|
|
230
|
-
publicInfo.accesses.set(key, new Set([access]));
|
|
231
|
-
}
|
|
232
|
-
exports.addAccess = addAccess;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const errors_js_1 = require("../../errors.js");
|
|
7
|
+
const index_js_1 = require("../helpers/index.js");
|
|
8
|
+
const base_bridge_js_1 = __importDefault(require("../base-bridge.js"));
|
|
9
|
+
/**
|
|
10
|
+
* Мост renderer-main.
|
|
11
|
+
*/
|
|
12
|
+
class RendererBridge extends base_bridge_js_1.default {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
if (!index_js_1.Env.hasProvider) {
|
|
16
|
+
throw new errors_js_1.NotProvidedFromMainError();
|
|
17
|
+
}
|
|
18
|
+
this.globalProvider = window.__provider__;
|
|
19
|
+
this.entitiesInfo = this.globalProvider.getEntitiesInfo();
|
|
20
|
+
this.init();
|
|
21
|
+
}
|
|
22
|
+
callFunction(name, id, args) {
|
|
23
|
+
return this.globalProvider.entities.functions[name](id, args);
|
|
24
|
+
}
|
|
25
|
+
getVariable(name) {
|
|
26
|
+
return this.globalProvider.entities.variables[name].get();
|
|
27
|
+
}
|
|
28
|
+
setVariable(name, value) {
|
|
29
|
+
return this.globalProvider.entities.variables[name].set(value);
|
|
30
|
+
}
|
|
31
|
+
waitPromise(channel, id) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
this.globalProvider.waitPromise(channel, resolve, reject, id);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
handleEvent(name, type, listener) {
|
|
37
|
+
return type === 'on'
|
|
38
|
+
? this.globalProvider.entities.events.on(name, listener)
|
|
39
|
+
: this.globalProvider.entities.events.once(name, listener);
|
|
40
|
+
}
|
|
41
|
+
emitEvent(name, value) {
|
|
42
|
+
this.globalProvider.entities.events.emit(name, value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Получить функцию, бросающую исключение, если есть повод.
|
|
47
|
+
*/
|
|
48
|
+
function getErrorThrower() {
|
|
49
|
+
if (!index_js_1.Env.hasWindow) {
|
|
50
|
+
return index_js_1.Errors.getThrower(errors_js_1.WrongBridgeInPreloadError);
|
|
51
|
+
}
|
|
52
|
+
if (!index_js_1.Env.hasProvider) {
|
|
53
|
+
return index_js_1.Errors.getThrower(errors_js_1.GlobalProviderNotFoundError);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Получить мост renderer-main.
|
|
59
|
+
*/
|
|
60
|
+
function getBridge() {
|
|
61
|
+
const throwError = getErrorThrower();
|
|
62
|
+
if (throwError) {
|
|
63
|
+
return new Proxy({}, {
|
|
64
|
+
get: throwError,
|
|
65
|
+
set: throwError,
|
|
66
|
+
apply: throwError
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return new RendererBridge();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Мост renderer-main.
|
|
73
|
+
*/
|
|
74
|
+
exports.default = getBridge();
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { IpcRendererEvent } from 'electron';
|
|
2
|
+
import type { EventListener, EventUnsubscribe, IRequest, IResult } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* IPC туннель для функции.
|
|
5
|
+
*/
|
|
6
|
+
declare class FunctionTunnel {
|
|
7
|
+
/**
|
|
8
|
+
* Туннель.
|
|
9
|
+
*/
|
|
10
|
+
private readonly tunnel;
|
|
11
|
+
/**
|
|
12
|
+
* Создать IPC туннель для функции.
|
|
13
|
+
* @param name - Имя функции.
|
|
14
|
+
*/
|
|
15
|
+
constructor(name: string);
|
|
16
|
+
/**
|
|
17
|
+
* Вызвать функцию.
|
|
18
|
+
* @param args - Аргументы вызова.
|
|
19
|
+
* @returns Результат вызова.
|
|
20
|
+
*/
|
|
21
|
+
call(args?: IRequest): IResult;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Туннель для переменной.
|
|
25
|
+
*/
|
|
26
|
+
declare class VariableTunnel {
|
|
27
|
+
/**
|
|
28
|
+
* Туннель для получения значения.
|
|
29
|
+
*/
|
|
30
|
+
private readonly getTunnel;
|
|
31
|
+
/**
|
|
32
|
+
* Туннель для установки значения.
|
|
33
|
+
*/
|
|
34
|
+
private readonly setTunnel;
|
|
35
|
+
/**
|
|
36
|
+
* Создать туннель для переменной.
|
|
37
|
+
* @param name - Имя переменной.
|
|
38
|
+
*/
|
|
39
|
+
constructor(name: string);
|
|
40
|
+
/**
|
|
41
|
+
* Получить значение переменной.
|
|
42
|
+
*/
|
|
43
|
+
get(): IResult;
|
|
44
|
+
/**
|
|
45
|
+
* Установить значение переменной.
|
|
46
|
+
* @param value - Значение.
|
|
47
|
+
*/
|
|
48
|
+
set(value: any): IResult;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Туннель для обработки обещания.
|
|
52
|
+
*/
|
|
53
|
+
declare class PromiseTunnel {
|
|
54
|
+
/**
|
|
55
|
+
* Туннель.
|
|
56
|
+
*/
|
|
57
|
+
private readonly tunnel;
|
|
58
|
+
/**
|
|
59
|
+
* Создать туннель для обработки обещания.
|
|
60
|
+
* @param channel - Канал возвращающий обещание.
|
|
61
|
+
*/
|
|
62
|
+
constructor(channel: string);
|
|
63
|
+
/**
|
|
64
|
+
* Ожидать завершения обещания.
|
|
65
|
+
* @param id - Уникальный идентификатор.
|
|
66
|
+
*/
|
|
67
|
+
wait(id?: string): Promise<any>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Туннель для события.
|
|
71
|
+
*/
|
|
72
|
+
declare class EventTunnel {
|
|
73
|
+
private readonly name;
|
|
74
|
+
/**
|
|
75
|
+
* Туннель вызова события.
|
|
76
|
+
*/
|
|
77
|
+
private readonly emitTunnel;
|
|
78
|
+
/**
|
|
79
|
+
* Туннель обработки события.
|
|
80
|
+
*/
|
|
81
|
+
private readonly onTunnel;
|
|
82
|
+
/**
|
|
83
|
+
* Туннель однократной обработки события.
|
|
84
|
+
*/
|
|
85
|
+
private readonly onceTunnel;
|
|
86
|
+
/**
|
|
87
|
+
* Создать туннель для события.
|
|
88
|
+
* @param name - Имя события.
|
|
89
|
+
*/
|
|
90
|
+
constructor(name: string);
|
|
91
|
+
/**
|
|
92
|
+
* Добавить обработчик события.
|
|
93
|
+
* @param listener - Обработчик события.
|
|
94
|
+
* @returns Функция отписки от события.
|
|
95
|
+
*/
|
|
96
|
+
on(listener: EventListener<IResult>): EventUnsubscribe;
|
|
97
|
+
/**
|
|
98
|
+
* Добавить одноразовый обработчик события.
|
|
99
|
+
* @param listener - Обработчик события.
|
|
100
|
+
* @returns Функция отписки от события.
|
|
101
|
+
*/
|
|
102
|
+
once(listener: EventListener<IResult>): EventUnsubscribe;
|
|
103
|
+
/**
|
|
104
|
+
* Вызвать событие.
|
|
105
|
+
* @param value - Передаваемое значение.
|
|
106
|
+
*/
|
|
107
|
+
emit(value: any): void;
|
|
108
|
+
/**
|
|
109
|
+
* Бросить ошибку.
|
|
110
|
+
* @param error - Ошибка.
|
|
111
|
+
*/
|
|
112
|
+
error(error: Error | string): void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* IPC туннель.
|
|
116
|
+
*/
|
|
117
|
+
export default class IPCTunnel {
|
|
118
|
+
private channel;
|
|
119
|
+
/**
|
|
120
|
+
* Туннель для функции.
|
|
121
|
+
*/
|
|
122
|
+
static readonly Function: typeof FunctionTunnel;
|
|
123
|
+
/**
|
|
124
|
+
* Туннель для переменной.
|
|
125
|
+
*/
|
|
126
|
+
static readonly Variable: typeof VariableTunnel;
|
|
127
|
+
/**
|
|
128
|
+
* Туннель для обещания.
|
|
129
|
+
*/
|
|
130
|
+
static readonly Promise: typeof PromiseTunnel;
|
|
131
|
+
/**
|
|
132
|
+
* Туннель для события.
|
|
133
|
+
*/
|
|
134
|
+
static readonly Event: typeof EventTunnel;
|
|
135
|
+
/**
|
|
136
|
+
* Создать IPC туннель.
|
|
137
|
+
* @param channel - Канал.
|
|
138
|
+
*/
|
|
139
|
+
constructor(channel: string);
|
|
140
|
+
/**
|
|
141
|
+
* Отправить запрос.
|
|
142
|
+
* @param args - Аргументы запроса.
|
|
143
|
+
* @returns Результат запроса.
|
|
144
|
+
*/
|
|
145
|
+
request(args?: IRequest): IResult;
|
|
146
|
+
/**
|
|
147
|
+
* Отправить ответ.
|
|
148
|
+
* @param result - Результат.
|
|
149
|
+
*/
|
|
150
|
+
response(result?: IResult): void;
|
|
151
|
+
/**
|
|
152
|
+
* Добавить обработчик IPC.
|
|
153
|
+
* @param listener - Обработчик.
|
|
154
|
+
*/
|
|
155
|
+
on(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
156
|
+
/**
|
|
157
|
+
* Добавить одноразовый обработчик IPC.
|
|
158
|
+
* @param listener - Обработчик.
|
|
159
|
+
*/
|
|
160
|
+
once(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
161
|
+
/**
|
|
162
|
+
* Удалить обработчик IPC.
|
|
163
|
+
* @param listener - Обработчик.
|
|
164
|
+
*/
|
|
165
|
+
removeListener(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
166
|
+
/**
|
|
167
|
+
* Удалить все обработчики IPC.
|
|
168
|
+
*/
|
|
169
|
+
removeAllListeners(): void;
|
|
170
|
+
}
|
|
171
|
+
export {};
|