emr-bridge 1.7.0 → 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 +14 -16
- package/cjs/main.d.ts +2 -4
- package/cjs/main.js +7 -16
- package/cjs/preload.d.ts +3 -3
- package/cjs/preload.js +5 -5
- package/cjs/renderer.d.ts +2 -2
- package/cjs/renderer.js +2 -2
- 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 +51 -39
- 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 +37 -53
- package/cjs/scripts/provider.d.ts +17 -15
- package/cjs/scripts/provider.js +70 -91
- package/cjs/scripts/publish.d.ts +19 -18
- package/cjs/scripts/publish.js +97 -175
- 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 +53 -58
- 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 +3 -3
- package/esm/preload.js +2 -2
- package/esm/renderer.d.ts +2 -2
- package/esm/renderer.js +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 +50 -38
- 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 +43 -41
- 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 +35 -51
- 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 +24 -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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { ipcRenderer } from 'electron';
|
|
2
|
+
import { IpcChannel, IpcResult } from '../helpers/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* IPC туннель для функции.
|
|
5
|
+
*/
|
|
6
|
+
class FunctionTunnel {
|
|
7
|
+
/**
|
|
8
|
+
* Создать IPC туннель для функции.
|
|
9
|
+
* @param name - Имя функции.
|
|
10
|
+
*/
|
|
11
|
+
constructor(name) {
|
|
12
|
+
this.tunnel = new IPCTunnel(IpcChannel.func.call(name));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Вызвать функцию.
|
|
16
|
+
* @param args - Аргументы вызова.
|
|
17
|
+
* @returns Результат вызова.
|
|
18
|
+
*/
|
|
19
|
+
call(args = { args: [] }) {
|
|
20
|
+
return this.tunnel.request(args);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Туннель для переменной.
|
|
25
|
+
*/
|
|
26
|
+
class VariableTunnel {
|
|
27
|
+
/**
|
|
28
|
+
* Создать туннель для переменной.
|
|
29
|
+
* @param name - Имя переменной.
|
|
30
|
+
*/
|
|
31
|
+
constructor(name) {
|
|
32
|
+
this.getTunnel = new IPCTunnel(IpcChannel.prop.get(name));
|
|
33
|
+
this.setTunnel = new IPCTunnel(IpcChannel.prop.set(name));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Получить значение переменной.
|
|
37
|
+
*/
|
|
38
|
+
get() {
|
|
39
|
+
return this.getTunnel.request();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Установить значение переменной.
|
|
43
|
+
* @param value - Значение.
|
|
44
|
+
*/
|
|
45
|
+
set(value) {
|
|
46
|
+
return this.setTunnel.request({ args: [value] });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Туннель для обработки обещания.
|
|
51
|
+
*/
|
|
52
|
+
class PromiseTunnel {
|
|
53
|
+
/**
|
|
54
|
+
* Создать туннель для обработки обещания.
|
|
55
|
+
* @param channel - Канал возвращающий обещание.
|
|
56
|
+
*/
|
|
57
|
+
constructor(channel) {
|
|
58
|
+
this.tunnel = new IPCTunnel(channel);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ожидать завершения обещания.
|
|
62
|
+
* @param id - Уникальный идентификатор.
|
|
63
|
+
*/
|
|
64
|
+
wait(id) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const handler = (_, { error, value, id: resultId }) => {
|
|
67
|
+
if (id !== undefined && resultId !== id) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (error) {
|
|
71
|
+
reject(error);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
resolve(value);
|
|
75
|
+
}
|
|
76
|
+
this.tunnel.removeListener(handler);
|
|
77
|
+
};
|
|
78
|
+
this.tunnel.on(handler);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Туннель для события.
|
|
84
|
+
*/
|
|
85
|
+
class EventTunnel {
|
|
86
|
+
/**
|
|
87
|
+
* Создать туннель для события.
|
|
88
|
+
* @param name - Имя события.
|
|
89
|
+
*/
|
|
90
|
+
constructor(name) {
|
|
91
|
+
this.name = name;
|
|
92
|
+
this.emitTunnel = new IPCTunnel(IpcChannel.event.emit(name));
|
|
93
|
+
this.onTunnel = new IPCTunnel(IpcChannel.event.on());
|
|
94
|
+
this.onceTunnel = new IPCTunnel(IpcChannel.event.once());
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Добавить обработчик события.
|
|
98
|
+
* @param listener - Обработчик события.
|
|
99
|
+
* @returns Функция отписки от события.
|
|
100
|
+
*/
|
|
101
|
+
on(listener) {
|
|
102
|
+
const handler = (_, result) => listener(result);
|
|
103
|
+
this.onTunnel.response(IpcResult.createWithValue(this.name));
|
|
104
|
+
this.emitTunnel.on(handler);
|
|
105
|
+
return () => this.emitTunnel.removeListener(handler);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Добавить одноразовый обработчик события.
|
|
109
|
+
* @param listener - Обработчик события.
|
|
110
|
+
* @returns Функция отписки от события.
|
|
111
|
+
*/
|
|
112
|
+
once(listener) {
|
|
113
|
+
const handler = (_, result) => listener(result);
|
|
114
|
+
this.onceTunnel.response(IpcResult.createWithValue(this.name));
|
|
115
|
+
this.emitTunnel.once(handler);
|
|
116
|
+
return () => this.emitTunnel.removeListener(handler);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Вызвать событие.
|
|
120
|
+
* @param value - Передаваемое значение.
|
|
121
|
+
*/
|
|
122
|
+
emit(value) {
|
|
123
|
+
this.emitTunnel.response({ value });
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Бросить ошибку.
|
|
127
|
+
* @param error - Ошибка.
|
|
128
|
+
*/
|
|
129
|
+
error(error) {
|
|
130
|
+
this.emitTunnel.response({ error: String(error) });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* IPC туннель.
|
|
135
|
+
*/
|
|
136
|
+
class IPCTunnel {
|
|
137
|
+
/**
|
|
138
|
+
* Создать IPC туннель.
|
|
139
|
+
* @param channel - Канал.
|
|
140
|
+
*/
|
|
141
|
+
constructor(channel) {
|
|
142
|
+
this.channel = channel;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Отправить запрос.
|
|
146
|
+
* @param args - Аргументы запроса.
|
|
147
|
+
* @returns Результат запроса.
|
|
148
|
+
*/
|
|
149
|
+
request(args = { args: [] }) {
|
|
150
|
+
return ipcRenderer.sendSync(this.channel, args);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Отправить ответ.
|
|
154
|
+
* @param result - Результат.
|
|
155
|
+
*/
|
|
156
|
+
response(result = {}) {
|
|
157
|
+
ipcRenderer.send(this.channel, result);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Добавить обработчик IPC.
|
|
161
|
+
* @param listener - Обработчик.
|
|
162
|
+
*/
|
|
163
|
+
on(listener) {
|
|
164
|
+
ipcRenderer.on(this.channel, listener);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Добавить одноразовый обработчик IPC.
|
|
168
|
+
* @param listener - Обработчик.
|
|
169
|
+
*/
|
|
170
|
+
once(listener) {
|
|
171
|
+
ipcRenderer.once(this.channel, listener);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Удалить обработчик IPC.
|
|
175
|
+
* @param listener - Обработчик.
|
|
176
|
+
*/
|
|
177
|
+
removeListener(listener) {
|
|
178
|
+
ipcRenderer.removeListener(this.channel, listener);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Удалить все обработчики IPC.
|
|
182
|
+
*/
|
|
183
|
+
removeAllListeners() {
|
|
184
|
+
ipcRenderer.removeAllListeners(this.channel);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Туннель для функции.
|
|
189
|
+
*/
|
|
190
|
+
IPCTunnel.Function = FunctionTunnel;
|
|
191
|
+
/**
|
|
192
|
+
* Туннель для переменной.
|
|
193
|
+
*/
|
|
194
|
+
IPCTunnel.Variable = VariableTunnel;
|
|
195
|
+
/**
|
|
196
|
+
* Туннель для обещания.
|
|
197
|
+
*/
|
|
198
|
+
IPCTunnel.Promise = PromiseTunnel;
|
|
199
|
+
/**
|
|
200
|
+
* Туннель для события.
|
|
201
|
+
*/
|
|
202
|
+
IPCTunnel.Event = EventTunnel;
|
|
203
|
+
export default IPCTunnel;
|
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
import type { IpcRendererEvent } from 'electron';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EventListener, EventUnsubscribe, IRequest, IResult } from '../types.js';
|
|
3
3
|
declare class FunctionTunnel {
|
|
4
|
-
|
|
4
|
+
private readonly tunnel;
|
|
5
5
|
constructor(name: string);
|
|
6
|
-
call(args?:
|
|
6
|
+
call(args?: IRequest): IResult;
|
|
7
7
|
}
|
|
8
8
|
declare class PropertyTunnel {
|
|
9
|
-
|
|
9
|
+
private readonly getTunnel;
|
|
10
|
+
private readonly setTunnel;
|
|
10
11
|
constructor(name: string);
|
|
11
|
-
get():
|
|
12
|
-
set(value: any):
|
|
12
|
+
get(): IResult;
|
|
13
|
+
set(value: any): IResult;
|
|
13
14
|
}
|
|
14
15
|
declare class PromiseTunnel {
|
|
15
|
-
|
|
16
|
+
private readonly tunnel;
|
|
16
17
|
constructor(channel: string);
|
|
17
|
-
wait(
|
|
18
|
+
wait(id?: string): Promise<any>;
|
|
18
19
|
}
|
|
19
|
-
declare class
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
declare class RendererEventTunnel {
|
|
26
|
-
#private;
|
|
20
|
+
declare class EventTunnel {
|
|
21
|
+
private readonly name;
|
|
22
|
+
private readonly emitTunnel;
|
|
23
|
+
private readonly onTunnel;
|
|
24
|
+
private readonly onceTunnel;
|
|
27
25
|
constructor(name: string);
|
|
26
|
+
on(listener: EventListener<IResult>): EventUnsubscribe;
|
|
27
|
+
once(listener: EventListener<IResult>): EventUnsubscribe;
|
|
28
28
|
emit(value: any): void;
|
|
29
29
|
error(error: string): void;
|
|
30
30
|
}
|
|
31
31
|
export default class IPCTunnel {
|
|
32
|
-
#private;
|
|
33
32
|
private channel;
|
|
34
33
|
static readonly Function: typeof FunctionTunnel;
|
|
35
34
|
static readonly Property: typeof PropertyTunnel;
|
|
36
35
|
static readonly Promise: typeof PromiseTunnel;
|
|
37
|
-
static readonly
|
|
38
|
-
static readonly RendererEvent: typeof RendererEventTunnel;
|
|
36
|
+
static readonly Event: typeof EventTunnel;
|
|
39
37
|
constructor(channel: string);
|
|
40
|
-
request(args?:
|
|
41
|
-
response(args?:
|
|
38
|
+
request(args?: IRequest): IResult;
|
|
39
|
+
response(args?: IResult): void;
|
|
42
40
|
on(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
43
41
|
once(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
44
42
|
removeListener(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
@@ -1,109 +1,107 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { ipcRenderer } from 'electron';
|
|
2
|
+
import { IpcChannel } from '../enums.js';
|
|
3
|
+
import { IpcResult } from './helpers/index.js';
|
|
3
4
|
class FunctionTunnel {
|
|
4
|
-
|
|
5
|
+
tunnel;
|
|
5
6
|
constructor(name) {
|
|
6
|
-
this
|
|
7
|
+
this.tunnel = new IPCTunnel(IpcChannel.functionCall + name);
|
|
7
8
|
}
|
|
8
9
|
call(args = { args: [] }) {
|
|
9
|
-
return this
|
|
10
|
+
return this.tunnel.request(args);
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
class PropertyTunnel {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
getTunnel;
|
|
15
|
+
setTunnel;
|
|
15
16
|
constructor(name) {
|
|
16
|
-
this
|
|
17
|
-
this
|
|
17
|
+
this.getTunnel = new IPCTunnel(IpcChannel.propertyGet + name);
|
|
18
|
+
this.setTunnel = new IPCTunnel(IpcChannel.propertySet + name);
|
|
18
19
|
}
|
|
19
20
|
get() {
|
|
20
|
-
return this
|
|
21
|
+
return this.getTunnel.request();
|
|
21
22
|
}
|
|
22
23
|
set(value) {
|
|
23
|
-
return this
|
|
24
|
+
return this.setTunnel.request({ args: [value] });
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
class PromiseTunnel {
|
|
27
|
-
|
|
28
|
+
tunnel;
|
|
28
29
|
constructor(channel) {
|
|
29
|
-
this
|
|
30
|
+
this.tunnel = new IPCTunnel(channel);
|
|
30
31
|
}
|
|
31
|
-
wait(
|
|
32
|
+
wait(id) {
|
|
32
33
|
return new Promise((resolve, reject) => {
|
|
33
|
-
const handler = (_, { error, value,
|
|
34
|
-
if (
|
|
34
|
+
const handler = (_, { error, value, id: resSecret }) => {
|
|
35
|
+
if (id !== undefined && resSecret !== id) {
|
|
35
36
|
return;
|
|
36
|
-
|
|
37
|
+
}
|
|
38
|
+
if (error) {
|
|
37
39
|
reject(error);
|
|
38
|
-
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
39
42
|
resolve(value);
|
|
40
|
-
|
|
43
|
+
}
|
|
44
|
+
this.tunnel.removeListener(handler);
|
|
41
45
|
};
|
|
42
|
-
this
|
|
46
|
+
this.tunnel.on(handler);
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
class
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
class EventTunnel {
|
|
51
|
+
name;
|
|
52
|
+
emitTunnel;
|
|
53
|
+
onTunnel;
|
|
54
|
+
onceTunnel;
|
|
50
55
|
constructor(name) {
|
|
51
|
-
this
|
|
52
|
-
this
|
|
53
|
-
this
|
|
54
|
-
|
|
55
|
-
on(handler) {
|
|
56
|
-
const listener = (_, result) => handler(result);
|
|
57
|
-
this.#onTunnel.response();
|
|
58
|
-
this.#emitTunnel.on(listener);
|
|
59
|
-
return () => this.#emitTunnel.removeListener(listener);
|
|
60
|
-
}
|
|
61
|
-
once(handler) {
|
|
62
|
-
const listener = (_, result) => handler(result);
|
|
63
|
-
this.#onceTunnel.response();
|
|
64
|
-
this.#emitTunnel.once(listener);
|
|
65
|
-
return () => this.#emitTunnel.removeListener(listener);
|
|
56
|
+
this.name = name;
|
|
57
|
+
this.emitTunnel = new IPCTunnel(IpcChannel.eventEmit + name);
|
|
58
|
+
this.onTunnel = new IPCTunnel(IpcChannel.eventOn);
|
|
59
|
+
this.onceTunnel = new IPCTunnel(IpcChannel.eventOnce);
|
|
66
60
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
on(listener) {
|
|
62
|
+
const handler = (_, result) => listener(result);
|
|
63
|
+
this.onTunnel.response(IpcResult.withValue(this.name));
|
|
64
|
+
this.emitTunnel.on(handler);
|
|
65
|
+
return () => this.emitTunnel.removeListener(handler);
|
|
66
|
+
}
|
|
67
|
+
once(listener) {
|
|
68
|
+
const handler = (_, result) => listener(result);
|
|
69
|
+
this.onceTunnel.response(IpcResult.withValue(this.name));
|
|
70
|
+
this.emitTunnel.once(handler);
|
|
71
|
+
return () => this.emitTunnel.removeListener(handler);
|
|
72
72
|
}
|
|
73
73
|
emit(value) {
|
|
74
|
-
this
|
|
74
|
+
this.emitTunnel.response({ value });
|
|
75
75
|
}
|
|
76
76
|
error(error) {
|
|
77
|
-
this
|
|
77
|
+
this.emitTunnel.response({ error });
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
export default class IPCTunnel {
|
|
81
81
|
channel;
|
|
82
|
-
#ipcRenderer = electron.ipcRenderer;
|
|
83
82
|
static Function = FunctionTunnel;
|
|
84
83
|
static Property = PropertyTunnel;
|
|
85
84
|
static Promise = PromiseTunnel;
|
|
86
|
-
static
|
|
87
|
-
static RendererEvent = RendererEventTunnel;
|
|
85
|
+
static Event = EventTunnel;
|
|
88
86
|
constructor(channel) {
|
|
89
87
|
this.channel = channel;
|
|
90
88
|
}
|
|
91
89
|
request(args = { args: [] }) {
|
|
92
|
-
return
|
|
90
|
+
return ipcRenderer.sendSync(this.channel, args);
|
|
93
91
|
}
|
|
94
92
|
response(args = {}) {
|
|
95
|
-
|
|
93
|
+
ipcRenderer.send(this.channel, args);
|
|
96
94
|
}
|
|
97
95
|
on(listener) {
|
|
98
|
-
|
|
96
|
+
ipcRenderer.on(this.channel, listener);
|
|
99
97
|
}
|
|
100
98
|
once(listener) {
|
|
101
|
-
|
|
99
|
+
ipcRenderer.once(this.channel, listener);
|
|
102
100
|
}
|
|
103
101
|
removeListener(listener) {
|
|
104
|
-
|
|
102
|
+
ipcRenderer.removeListener(this.channel, listener);
|
|
105
103
|
}
|
|
106
104
|
removeAllListeners() {
|
|
107
|
-
|
|
105
|
+
ipcRenderer.removeAllListeners(this.channel);
|
|
108
106
|
}
|
|
109
107
|
}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,74 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Мост до main.
|
|
3
|
+
*/
|
|
4
|
+
export interface IBridge {
|
|
5
|
+
/**
|
|
6
|
+
* Вернуть в качестве типа.
|
|
7
|
+
*/
|
|
8
|
+
as<TTarget>(): IBridge & TTarget;
|
|
9
|
+
/**
|
|
10
|
+
* Вызвать событие.
|
|
11
|
+
* @param name - Имя события.
|
|
12
|
+
* @param value - Передаваемое значение.
|
|
13
|
+
*/
|
|
14
|
+
emit<TValue = unknown>(name: string, value?: TValue): void;
|
|
15
|
+
/**
|
|
16
|
+
* Добавить обработчик события.
|
|
17
|
+
* @param name - Имя события.
|
|
18
|
+
* @param listener - Обработчик.
|
|
19
|
+
* @returns Функция отписки от события.
|
|
20
|
+
*/
|
|
21
|
+
on<TValue>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
22
|
+
/**
|
|
23
|
+
* Добавить одноразовый обработчик события.
|
|
24
|
+
* @param name - Имя события.
|
|
25
|
+
* @param listener - Обработчик.
|
|
26
|
+
* @returns Функция отписки от события.
|
|
27
|
+
*/
|
|
28
|
+
once<TValue>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
29
|
+
/**
|
|
30
|
+
* Вызвать функцию, возвращающую объект, не передаваемый стандартным путём.
|
|
31
|
+
* @param func - Вызываемая функция.
|
|
32
|
+
* @param Class - Класс, экземпляр которого будет возвращён функцией.
|
|
33
|
+
* @param args - Аргументы вызова функции.
|
|
34
|
+
* @returns Возвращённое функцией значение (преобразованное из снимка).
|
|
35
|
+
*/
|
|
36
|
+
call<TFunc extends (...args: any[]) => InstanceType<TClass>, TClass extends {
|
|
37
|
+
new (): IHasSnapshot;
|
|
38
|
+
}>(func: TFunc, Class: TClass, args: Parameters<TFunc>): InstanceType<TClass>;
|
|
39
|
+
/**
|
|
40
|
+
* Обернуть функцию, возвращающую экземпляр класса.
|
|
41
|
+
* @param func - Оригинальная функция.
|
|
42
|
+
* @param Class - Класс.
|
|
43
|
+
*/
|
|
44
|
+
returns<TFunc extends (...args: any[]) => InstanceType<TClass>, TClass extends {
|
|
45
|
+
new (): IHasSnapshot;
|
|
46
|
+
}>(func: TFunc, Class: TClass): TFunc;
|
|
5
47
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Работает со снимками.
|
|
50
|
+
*/
|
|
51
|
+
export interface IHasSnapshot<TSnapshot = unknown> {
|
|
52
|
+
/**
|
|
53
|
+
* Получить снимок.
|
|
54
|
+
* @returns Снимок.
|
|
55
|
+
*/
|
|
56
|
+
takeSnapshot(): TSnapshot;
|
|
57
|
+
/**
|
|
58
|
+
* Обновить из снимка.
|
|
59
|
+
* @param snapshot - Снимок.
|
|
60
|
+
*/
|
|
61
|
+
updateFromSnapshot(snapshot: TSnapshot): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Значение-снимок, передаваемое по IPC.
|
|
65
|
+
*/
|
|
66
|
+
export interface ISnapshotValue<TSnapshot = unknown> {
|
|
67
|
+
/**
|
|
68
|
+
* Тип значения.
|
|
69
|
+
*/
|
|
70
|
+
__type__: 'snapshot';
|
|
71
|
+
/**
|
|
72
|
+
* Снимок.
|
|
73
|
+
*/
|
|
74
|
+
__snapshot__: TSnapshot;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Передаваемый по IPC результат.
|
|
78
|
+
*/
|
|
79
|
+
export interface IResult<TValue = any> {
|
|
80
|
+
/**
|
|
81
|
+
* Значение.
|
|
82
|
+
*/
|
|
83
|
+
value?: TValue;
|
|
84
|
+
/**
|
|
85
|
+
* Ошибка.
|
|
86
|
+
*/
|
|
14
87
|
error?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Канал обработки обещания.
|
|
90
|
+
*/
|
|
15
91
|
promiseChannel?: string;
|
|
16
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Уникальный идентификатор.
|
|
94
|
+
*/
|
|
95
|
+
id?: string;
|
|
17
96
|
}
|
|
18
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Передаваемый по IPC запрос.
|
|
99
|
+
*/
|
|
100
|
+
export interface IRequest {
|
|
101
|
+
/**
|
|
102
|
+
* Аргументы.
|
|
103
|
+
*/
|
|
19
104
|
args: any[];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
scope?: Scope;
|
|
25
|
-
}
|
|
26
|
-
export interface PublishMainEventArgs {
|
|
27
|
-
name?: string;
|
|
28
|
-
scope?: Scope;
|
|
29
|
-
}
|
|
30
|
-
export interface PublishRendererEventArgs {
|
|
31
|
-
name?: string;
|
|
32
|
-
scope?: Scope;
|
|
33
|
-
procFn?: EventReceiver;
|
|
34
|
-
}
|
|
35
|
-
export interface PublishPropertyArgs {
|
|
36
|
-
name?: string;
|
|
37
|
-
scope?: Scope;
|
|
38
|
-
access?: Access;
|
|
39
|
-
}
|
|
40
|
-
export type RendererEvent<T = void> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
41
|
-
export type MainEvent<T = void> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
42
|
-
export type EventEmitter = (...args: any[]) => any;
|
|
43
|
-
export type EventReceiver<I = void, O = I> = (input: I) => O;
|
|
44
|
-
export type EventUnsubscriber = () => void;
|
|
45
|
-
export type EventHandler<T = void> = (result: T) => void;
|
|
46
|
-
export type PublicFunction = (...args: any[]) => any;
|
|
47
|
-
export interface PublicProperty<T> {
|
|
48
|
-
get?(): T;
|
|
49
|
-
set?(value: T): void;
|
|
50
|
-
}
|
|
51
|
-
export interface RendererPublic {
|
|
52
|
-
__register__?(instance: any): void;
|
|
105
|
+
/**
|
|
106
|
+
* Уникальный идентификатор.
|
|
107
|
+
*/
|
|
108
|
+
id?: string;
|
|
53
109
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Класс объекта, умеющего работать со снимками.
|
|
112
|
+
*/
|
|
113
|
+
export type HasSnapshotClass<TValue = unknown> = {
|
|
114
|
+
new (): IHasSnapshot<TValue>;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Функция отписки от события.
|
|
118
|
+
*/
|
|
119
|
+
export type EventUnsubscribe = () => void;
|
|
120
|
+
/**
|
|
121
|
+
* Обработчик события.
|
|
122
|
+
*/
|
|
123
|
+
export type EventListener<TResult = undefined> = TResult extends undefined ? () => void : (result: TResult) => void;
|
|
124
|
+
/**
|
|
125
|
+
* Провайдер обязательных функций для работы.
|
|
126
|
+
*/
|
|
127
|
+
export interface IGlobalProvider {
|
|
128
|
+
/**
|
|
129
|
+
* Получить информацию о сущностях.
|
|
130
|
+
* @returns Информация о сущностях.
|
|
131
|
+
*/
|
|
132
|
+
getEntitiesInfo(): IEntitiesInfo;
|
|
133
|
+
/**
|
|
134
|
+
* Ожидать завершения обещания.
|
|
135
|
+
* @param channel - Канал обработки обещания.
|
|
136
|
+
* @param onSuccess - Функция, вызываемая при успехе.
|
|
137
|
+
* @param onError - Функция, вызываемая при неудаче.
|
|
138
|
+
* @param id - Уникальный идентификатор.
|
|
139
|
+
*/
|
|
140
|
+
waitPromise(channel: string, onSuccess: (value: any) => void, onError?: (reason?: any) => void, id?: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Сущности.
|
|
143
|
+
*/
|
|
144
|
+
entities: {
|
|
145
|
+
/**
|
|
146
|
+
* Функции.
|
|
147
|
+
*/
|
|
148
|
+
functions: {
|
|
149
|
+
[name: string]: (id: string, args: any[]) => IResult;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* События.
|
|
153
|
+
*/
|
|
154
|
+
events: {
|
|
155
|
+
/**
|
|
156
|
+
* Добавить обработчик события.
|
|
157
|
+
* @param name - Имя события.
|
|
158
|
+
* @param listener - Обработчик события.
|
|
159
|
+
* @returns Функция отписки от события.
|
|
160
|
+
*/
|
|
161
|
+
on(name: string, listener: EventListener<IResult>): EventUnsubscribe;
|
|
162
|
+
/**
|
|
163
|
+
* Добавить одноразовы обработчик события.
|
|
164
|
+
* @param name - Имя события.
|
|
165
|
+
* @param listener - Обработчик события.
|
|
166
|
+
* @returns Функция отписки от события.
|
|
167
|
+
*/
|
|
168
|
+
once(name: string, listener: EventListener<IResult>): EventUnsubscribe;
|
|
169
|
+
/**
|
|
170
|
+
* Взывать событие.
|
|
171
|
+
* @param name - Имя события.
|
|
172
|
+
* @param value - Передаваемое значение.
|
|
173
|
+
*/
|
|
174
|
+
emit(name: string, value: any): void;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Переменные.
|
|
178
|
+
*/
|
|
179
|
+
variables: {
|
|
180
|
+
[name: string]: {
|
|
181
|
+
get(): IResult;
|
|
182
|
+
set(value: any): IResult;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
65
185
|
};
|
|
66
186
|
}
|
|
67
|
-
|
|
68
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Информация о сущностях.
|
|
189
|
+
*/
|
|
190
|
+
export interface IEntitiesInfo {
|
|
191
|
+
/**
|
|
192
|
+
* Доступные переменные.
|
|
193
|
+
*/
|
|
194
|
+
variables: Set<string>;
|
|
195
|
+
/**
|
|
196
|
+
* Доступные функции.
|
|
197
|
+
*/
|
|
69
198
|
functions: Set<string>;
|
|
70
|
-
mainEvents: Set<string>;
|
|
71
|
-
rendererEvents: Set<string>;
|
|
72
|
-
scopes: Map<string, Set<Scope>>;
|
|
73
|
-
accesses: Map<string, Set<Access>>;
|
|
74
199
|
}
|