emr-bridge 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/cjs/scripts/helpers/transfer.js +1 -1
- package/cjs/scripts/helpers/web-contents-events-container.d.ts +2 -7
- package/cjs/scripts/helpers/web-contents-events-container.js +14 -20
- package/cjs/scripts/main/publish.d.ts +2 -2
- package/cjs/scripts/main/publish.js +3 -5
- package/esm/scripts/helpers/transfer.js +1 -1
- package/esm/scripts/helpers/web-contents-events-container.d.ts +2 -7
- package/esm/scripts/helpers/web-contents-events-container.js +14 -20
- package/esm/scripts/main/publish.d.ts +2 -2
- package/esm/scripts/main/publish.js +3 -5
- package/package.json +2 -2
- package/cjs/enums.d.ts +0 -10
- package/cjs/enums.js +0 -14
- package/cjs/index.d.ts +0 -4
- package/cjs/index.js +0 -16
- package/cjs/main.d.ts +0 -2
- package/cjs/main.js +0 -9
- package/cjs/preload.d.ts +0 -3
- package/cjs/preload.js +0 -10
- package/cjs/renderer.d.ts +0 -2
- package/cjs/renderer.js +0 -8
- package/cjs/scripts/bridge.d.ts +0 -8
- package/cjs/scripts/bridge.js +0 -69
- package/cjs/scripts/helpers/error-thrower.d.ts +0 -3
- package/cjs/scripts/helpers/error-thrower.js +0 -8
- package/cjs/scripts/helpers/main-event.d.ts +0 -8
- package/cjs/scripts/helpers/main-event.js +0 -15
- package/cjs/scripts/helpers/web-contents-container.d.ts +0 -12
- package/cjs/scripts/helpers/web-contents-container.js +0 -34
- package/cjs/scripts/preload-bridge.d.ts +0 -20
- package/cjs/scripts/preload-bridge.js +0 -76
- package/cjs/scripts/preload-provider.d.ts +0 -7
- package/cjs/scripts/preload-provider.js +0 -80
- package/cjs/scripts/provider.d.ts +0 -27
- package/cjs/scripts/provider.js +0 -95
- package/cjs/scripts/publish.d.ts +0 -41
- package/cjs/scripts/publish.js +0 -154
- package/cjs/scripts/renderer-tunnels.d.ts +0 -45
- package/cjs/scripts/renderer-tunnels.js +0 -110
- package/esm/enums.d.ts +0 -10
- package/esm/enums.js +0 -11
- package/esm/helpers.d.ts +0 -41
- package/esm/helpers.js +0 -96
- package/esm/index.d.ts +0 -4
- package/esm/index.js +0 -3
- package/esm/main.d.ts +0 -2
- package/esm/main.js +0 -1
- package/esm/preload.d.ts +0 -3
- package/esm/preload.js +0 -2
- package/esm/renderer.d.ts +0 -2
- package/esm/renderer.js +0 -1
- package/esm/scripts/bridge.d.ts +0 -8
- package/esm/scripts/bridge.js +0 -64
- package/esm/scripts/helpers/electron-importer.d.ts +0 -4
- package/esm/scripts/helpers/electron-importer.js +0 -16
- package/esm/scripts/helpers/error-thrower.d.ts +0 -3
- package/esm/scripts/helpers/error-thrower.js +0 -5
- package/esm/scripts/helpers/main-event.d.ts +0 -8
- package/esm/scripts/helpers/main-event.js +0 -12
- package/esm/scripts/helpers/web-contents-container.d.ts +0 -12
- package/esm/scripts/helpers/web-contents-container.js +0 -31
- package/esm/scripts/main.d.ts +0 -8
- package/esm/scripts/main.js +0 -69
- package/esm/scripts/preload-bridge.d.ts +0 -20
- package/esm/scripts/preload-bridge.js +0 -68
- package/esm/scripts/preload-provider.d.ts +0 -7
- package/esm/scripts/preload-provider.js +0 -75
- package/esm/scripts/provider.d.ts +0 -27
- package/esm/scripts/provider.js +0 -92
- package/esm/scripts/publish.d.ts +0 -41
- package/esm/scripts/publish.js +0 -147
- package/esm/scripts/renderer-tunnels.d.ts +0 -45
- package/esm/scripts/renderer-tunnels.js +0 -107
package/esm/scripts/provider.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { NoSetAccessError, TrySetReadonlyError } from '../errors.js';
|
|
2
|
-
import { ErrorThrower, Id, Transfer } from './helpers/index.js';
|
|
3
|
-
export default class Provider {
|
|
4
|
-
target = {
|
|
5
|
-
as: () => this.as(),
|
|
6
|
-
emit: (...args) => this.emit(...args),
|
|
7
|
-
on: (...args) => this.on(...args),
|
|
8
|
-
once: (...args) => this.once(...args),
|
|
9
|
-
call: (...args) => this.call(...args)
|
|
10
|
-
};
|
|
11
|
-
as() {
|
|
12
|
-
return this.target;
|
|
13
|
-
}
|
|
14
|
-
emit(name, arg) {
|
|
15
|
-
this.emitEvent(name, arg);
|
|
16
|
-
}
|
|
17
|
-
on(name, listener) {
|
|
18
|
-
return this.handleEvent(name, 'on', ({ value, error }) => {
|
|
19
|
-
this.handleError(`event: ${name}`, error);
|
|
20
|
-
listener(value);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
once(name, listener) {
|
|
24
|
-
return this.handleEvent(name, 'once', ({ value, error }) => {
|
|
25
|
-
this.handleError(`event: ${name}`, error);
|
|
26
|
-
listener(value);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
call(func, Class, args) {
|
|
30
|
-
const value = func(...args);
|
|
31
|
-
if (Transfer.isSnapshotValue(value)) {
|
|
32
|
-
return Transfer.getFromSnapshot(value, Class);
|
|
33
|
-
}
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
init() {
|
|
37
|
-
this.initFunctions();
|
|
38
|
-
this.initProperties();
|
|
39
|
-
}
|
|
40
|
-
handleError(channel, error) {
|
|
41
|
-
if (!error) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
throw new Error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
45
|
-
}
|
|
46
|
-
initFunctions() {
|
|
47
|
-
for (const name of this.entitiesInfo.functions) {
|
|
48
|
-
this.define(name, {
|
|
49
|
-
value: (...args) => {
|
|
50
|
-
const id = Id.generate();
|
|
51
|
-
const preparedArgs = args.map(arg => Transfer.toTransferable(arg));
|
|
52
|
-
const { error, promiseChannel, value } = this.callFunction(name, id, preparedArgs);
|
|
53
|
-
this.handleError(name, error);
|
|
54
|
-
return promiseChannel
|
|
55
|
-
? this.waitPromise(promiseChannel, id)
|
|
56
|
-
: value;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
initProperties() {
|
|
62
|
-
for (const name of this.entitiesInfo.variables) {
|
|
63
|
-
this.define(name, {
|
|
64
|
-
get: () => {
|
|
65
|
-
const { error, value } = this.getVariable(name);
|
|
66
|
-
this.handleError(name, error);
|
|
67
|
-
return value;
|
|
68
|
-
},
|
|
69
|
-
set: (value) => {
|
|
70
|
-
const { error } = this.setVariable(name, value);
|
|
71
|
-
this.handleError(name, error);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
define(name, attrs) {
|
|
77
|
-
const hasValue = Boolean(attrs?.value);
|
|
78
|
-
const defaultDescriptor = {
|
|
79
|
-
get: () => attrs.value,
|
|
80
|
-
set: ErrorThrower.throws(TrySetReadonlyError, name),
|
|
81
|
-
enumerable: true
|
|
82
|
-
};
|
|
83
|
-
const noValueDescriptor = {
|
|
84
|
-
get: attrs?.get || ErrorThrower.throws(NoSetAccessError, name),
|
|
85
|
-
set: attrs?.set || ErrorThrower.throws(TrySetReadonlyError, name),
|
|
86
|
-
enumerable: true
|
|
87
|
-
};
|
|
88
|
-
Object.defineProperty(this.target, name, hasValue
|
|
89
|
-
? defaultDescriptor
|
|
90
|
-
: noValueDescriptor);
|
|
91
|
-
}
|
|
92
|
-
}
|
package/esm/scripts/publish.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { EventListener, EventUnsubscribe, IHasSnapshot, IPublicProperty, PublicFunction } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Call the event from **main** process.
|
|
4
|
-
*
|
|
5
|
-
* @param name - event name
|
|
6
|
-
*/
|
|
7
|
-
export declare function emitEvent(name: string, value?: any): void;
|
|
8
|
-
/**
|
|
9
|
-
* Handle event from **main** process.
|
|
10
|
-
*
|
|
11
|
-
* @param name - event name
|
|
12
|
-
* @param listener - event handler
|
|
13
|
-
*/
|
|
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;
|
|
22
|
-
/**
|
|
23
|
-
* Makes the function available for **renderer** and **preload** processes.
|
|
24
|
-
*
|
|
25
|
-
* _only for function_
|
|
26
|
-
*
|
|
27
|
-
* @param name - name by which the function will be accessed
|
|
28
|
-
* @param func - linked function
|
|
29
|
-
*/
|
|
30
|
-
export declare function publicFunction<TFunc extends PublicFunction>(name: string, func: TFunc, receives?: {
|
|
31
|
-
new (): IHasSnapshot;
|
|
32
|
-
}[]): void;
|
|
33
|
-
/**
|
|
34
|
-
* Makes the function available for **renderer** and **preload** processes.
|
|
35
|
-
*
|
|
36
|
-
* _only for variables_
|
|
37
|
-
*
|
|
38
|
-
* @param name - name by which the variable will be accessed
|
|
39
|
-
* @param value - variable getter/setter
|
|
40
|
-
*/
|
|
41
|
-
export declare function publicVariable<T>(name: string, value: IPublicProperty<T>): void;
|
package/esm/scripts/publish.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { ipcMain } from 'electron';
|
|
2
|
-
import { IpcChannel } from '../enums.js';
|
|
3
|
-
import { PublishMethodsUnavailable } from '../errors.js';
|
|
4
|
-
import { Env, ErrorThrower, IpcResult, MainEvent, Transfer, WebContentsContainer } from './helpers/index.js';
|
|
5
|
-
const entitiesInfo = {
|
|
6
|
-
variables: new Set(),
|
|
7
|
-
functions: new Set()
|
|
8
|
-
};
|
|
9
|
-
const mainEventHandlers = new WebContentsContainer();
|
|
10
|
-
/** Выбрасывает ошибку если используется не в том процессе */
|
|
11
|
-
const canThrowError = (Env.global.hasWindow || !ipcMain)
|
|
12
|
-
? ErrorThrower.throws(PublishMethodsUnavailable)
|
|
13
|
-
: () => { };
|
|
14
|
-
ipcMain?.on(IpcChannel.getPublicInfo, e => new MainEvent(e).return(entitiesInfo));
|
|
15
|
-
ipcMain?.on(IpcChannel.eventOn, (e, { value }) => mainEventHandlers.addOn(value, e.sender));
|
|
16
|
-
ipcMain?.on(IpcChannel.eventOnce, (e, { value }) => mainEventHandlers.addOn(value, e.sender));
|
|
17
|
-
/**
|
|
18
|
-
* Call the event from **main** process.
|
|
19
|
-
*
|
|
20
|
-
* @param name - event name
|
|
21
|
-
*/
|
|
22
|
-
export function emitEvent(name, value) {
|
|
23
|
-
canThrowError();
|
|
24
|
-
const emitChannel = IpcChannel.eventEmit + name;
|
|
25
|
-
try {
|
|
26
|
-
if (value instanceof Promise) {
|
|
27
|
-
value
|
|
28
|
-
.then(val => {
|
|
29
|
-
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, IpcResult.withValue(val)));
|
|
30
|
-
mainEventHandlers.clearOnce(name);
|
|
31
|
-
})
|
|
32
|
-
.catch(reason => {
|
|
33
|
-
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, IpcResult.withError(reason)));
|
|
34
|
-
mainEventHandlers.clearOnce(name);
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, IpcResult.withValue(value)));
|
|
39
|
-
mainEventHandlers.clearOnce(name);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
mainEventHandlers.getAll(name).forEach(sender => sender.send(emitChannel, IpcResult.withError(error)));
|
|
43
|
-
mainEventHandlers.clearOnce(name);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Handle event from **main** process.
|
|
48
|
-
*
|
|
49
|
-
* @param name - event name
|
|
50
|
-
* @param listener - event handler
|
|
51
|
-
*/
|
|
52
|
-
export function on(name, listener) {
|
|
53
|
-
canThrowError();
|
|
54
|
-
const emitChannel = IpcChannel.eventEmit + name;
|
|
55
|
-
const handler = (_, { value }) => listener(value);
|
|
56
|
-
ipcMain.on(emitChannel, handler);
|
|
57
|
-
return () => ipcMain.removeListener(emitChannel, handler);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Handle event from **main** process.
|
|
61
|
-
*
|
|
62
|
-
* @param name - event name
|
|
63
|
-
* @param listener - event handler
|
|
64
|
-
*/
|
|
65
|
-
export function once(name, listener) {
|
|
66
|
-
canThrowError();
|
|
67
|
-
const emitChannel = IpcChannel.eventEmit + name;
|
|
68
|
-
const handler = (_, { value }) => listener(value);
|
|
69
|
-
ipcMain.once(emitChannel, handler);
|
|
70
|
-
return () => ipcMain.removeListener(emitChannel, handler);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Makes the function available for **renderer** and **preload** processes.
|
|
74
|
-
*
|
|
75
|
-
* _only for function_
|
|
76
|
-
*
|
|
77
|
-
* @param name - name by which the function will be accessed
|
|
78
|
-
* @param func - linked function
|
|
79
|
-
*/
|
|
80
|
-
export function publicFunction(name, func, receives = []) {
|
|
81
|
-
canThrowError();
|
|
82
|
-
const channel = IpcChannel.functionCall + name;
|
|
83
|
-
entitiesInfo.functions.add(name);
|
|
84
|
-
ipcMain.removeAllListeners(channel);
|
|
85
|
-
ipcMain.on(channel, (e, { args, id }) => {
|
|
86
|
-
const event = new MainEvent(e);
|
|
87
|
-
try {
|
|
88
|
-
const preparedArgs = args.map((arg, index) => (Transfer.isSnapshotValue(arg) && receives[index]
|
|
89
|
-
? Transfer.getFromSnapshot(arg, receives[index])
|
|
90
|
-
: arg));
|
|
91
|
-
const result = func(...preparedArgs);
|
|
92
|
-
if (result instanceof Promise) {
|
|
93
|
-
const promiseChannel = channel + IpcChannel.promisePostfix;
|
|
94
|
-
result
|
|
95
|
-
.then(value => event.send(promiseChannel, IpcResult.withValue(value, id)))
|
|
96
|
-
.catch(reason => event.send(promiseChannel, IpcResult.withError(reason, id)));
|
|
97
|
-
event.return(IpcResult.withPromise(promiseChannel));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
event.return(IpcResult.withValue(result));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
event.return(IpcResult.withError(error));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Makes the function available for **renderer** and **preload** processes.
|
|
110
|
-
*
|
|
111
|
-
* _only for variables_
|
|
112
|
-
*
|
|
113
|
-
* @param name - name by which the variable will be accessed
|
|
114
|
-
* @param value - variable getter/setter
|
|
115
|
-
*/
|
|
116
|
-
export function publicVariable(name, value) {
|
|
117
|
-
canThrowError();
|
|
118
|
-
const getChannel = IpcChannel.propertyGet + name;
|
|
119
|
-
const setChannel = IpcChannel.propertySet + name;
|
|
120
|
-
const { get: getter, set: setter } = value;
|
|
121
|
-
entitiesInfo.variables.add(name);
|
|
122
|
-
if (getter) {
|
|
123
|
-
ipcMain.removeAllListeners(getChannel);
|
|
124
|
-
ipcMain.on(getChannel, e => {
|
|
125
|
-
const event = new MainEvent(e);
|
|
126
|
-
try {
|
|
127
|
-
event.return(IpcResult.withValue(getter()));
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
event.return(IpcResult.withError(error));
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
if (setter) {
|
|
135
|
-
ipcMain.removeAllListeners(setChannel);
|
|
136
|
-
ipcMain.on(setChannel, (e, { args }) => {
|
|
137
|
-
const event = new MainEvent(e);
|
|
138
|
-
try {
|
|
139
|
-
setter(args.at(0));
|
|
140
|
-
event.return(IpcResult.withValue(null));
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
event.return(IpcResult.withError(error));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { IpcRendererEvent } from 'electron';
|
|
2
|
-
import type { EventListener, EventUnsubscribe, IRequest, IResult } from '../types.js';
|
|
3
|
-
declare class FunctionTunnel {
|
|
4
|
-
private readonly tunnel;
|
|
5
|
-
constructor(name: string);
|
|
6
|
-
call(args?: IRequest): IResult;
|
|
7
|
-
}
|
|
8
|
-
declare class PropertyTunnel {
|
|
9
|
-
private readonly getTunnel;
|
|
10
|
-
private readonly setTunnel;
|
|
11
|
-
constructor(name: string);
|
|
12
|
-
get(): IResult;
|
|
13
|
-
set(value: any): IResult;
|
|
14
|
-
}
|
|
15
|
-
declare class PromiseTunnel {
|
|
16
|
-
private readonly tunnel;
|
|
17
|
-
constructor(channel: string);
|
|
18
|
-
wait(id?: string): Promise<any>;
|
|
19
|
-
}
|
|
20
|
-
declare class EventTunnel {
|
|
21
|
-
private readonly name;
|
|
22
|
-
private readonly emitTunnel;
|
|
23
|
-
private readonly onTunnel;
|
|
24
|
-
private readonly onceTunnel;
|
|
25
|
-
constructor(name: string);
|
|
26
|
-
on(listener: EventListener<IResult>): EventUnsubscribe;
|
|
27
|
-
once(listener: EventListener<IResult>): EventUnsubscribe;
|
|
28
|
-
emit(value: any): void;
|
|
29
|
-
error(error: string): void;
|
|
30
|
-
}
|
|
31
|
-
export default class IPCTunnel {
|
|
32
|
-
private channel;
|
|
33
|
-
static readonly Function: typeof FunctionTunnel;
|
|
34
|
-
static readonly Property: typeof PropertyTunnel;
|
|
35
|
-
static readonly Promise: typeof PromiseTunnel;
|
|
36
|
-
static readonly Event: typeof EventTunnel;
|
|
37
|
-
constructor(channel: string);
|
|
38
|
-
request(args?: IRequest): IResult;
|
|
39
|
-
response(args?: IResult): void;
|
|
40
|
-
on(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
41
|
-
once(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
42
|
-
removeListener(listener: (event: IpcRendererEvent, ...args: any[]) => void): void;
|
|
43
|
-
removeAllListeners(): void;
|
|
44
|
-
}
|
|
45
|
-
export {};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ipcRenderer } from 'electron';
|
|
2
|
-
import { IpcChannel } from '../enums.js';
|
|
3
|
-
import { IpcResult } from './helpers/index.js';
|
|
4
|
-
class FunctionTunnel {
|
|
5
|
-
tunnel;
|
|
6
|
-
constructor(name) {
|
|
7
|
-
this.tunnel = new IPCTunnel(IpcChannel.functionCall + name);
|
|
8
|
-
}
|
|
9
|
-
call(args = { args: [] }) {
|
|
10
|
-
return this.tunnel.request(args);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
class PropertyTunnel {
|
|
14
|
-
getTunnel;
|
|
15
|
-
setTunnel;
|
|
16
|
-
constructor(name) {
|
|
17
|
-
this.getTunnel = new IPCTunnel(IpcChannel.propertyGet + name);
|
|
18
|
-
this.setTunnel = new IPCTunnel(IpcChannel.propertySet + name);
|
|
19
|
-
}
|
|
20
|
-
get() {
|
|
21
|
-
return this.getTunnel.request();
|
|
22
|
-
}
|
|
23
|
-
set(value) {
|
|
24
|
-
return this.setTunnel.request({ args: [value] });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
class PromiseTunnel {
|
|
28
|
-
tunnel;
|
|
29
|
-
constructor(channel) {
|
|
30
|
-
this.tunnel = new IPCTunnel(channel);
|
|
31
|
-
}
|
|
32
|
-
wait(id) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const handler = (_, { error, value, id: resSecret }) => {
|
|
35
|
-
if (id !== undefined && resSecret !== id) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (error) {
|
|
39
|
-
reject(error);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
resolve(value);
|
|
43
|
-
}
|
|
44
|
-
this.tunnel.removeListener(handler);
|
|
45
|
-
};
|
|
46
|
-
this.tunnel.on(handler);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class EventTunnel {
|
|
51
|
-
name;
|
|
52
|
-
emitTunnel;
|
|
53
|
-
onTunnel;
|
|
54
|
-
onceTunnel;
|
|
55
|
-
constructor(name) {
|
|
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);
|
|
60
|
-
}
|
|
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
|
-
}
|
|
73
|
-
emit(value) {
|
|
74
|
-
this.emitTunnel.response({ value });
|
|
75
|
-
}
|
|
76
|
-
error(error) {
|
|
77
|
-
this.emitTunnel.response({ error });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export default class IPCTunnel {
|
|
81
|
-
channel;
|
|
82
|
-
static Function = FunctionTunnel;
|
|
83
|
-
static Property = PropertyTunnel;
|
|
84
|
-
static Promise = PromiseTunnel;
|
|
85
|
-
static Event = EventTunnel;
|
|
86
|
-
constructor(channel) {
|
|
87
|
-
this.channel = channel;
|
|
88
|
-
}
|
|
89
|
-
request(args = { args: [] }) {
|
|
90
|
-
return ipcRenderer.sendSync(this.channel, args);
|
|
91
|
-
}
|
|
92
|
-
response(args = {}) {
|
|
93
|
-
ipcRenderer.send(this.channel, args);
|
|
94
|
-
}
|
|
95
|
-
on(listener) {
|
|
96
|
-
ipcRenderer.on(this.channel, listener);
|
|
97
|
-
}
|
|
98
|
-
once(listener) {
|
|
99
|
-
ipcRenderer.once(this.channel, listener);
|
|
100
|
-
}
|
|
101
|
-
removeListener(listener) {
|
|
102
|
-
ipcRenderer.removeListener(this.channel, listener);
|
|
103
|
-
}
|
|
104
|
-
removeAllListeners() {
|
|
105
|
-
ipcRenderer.removeAllListeners(this.channel);
|
|
106
|
-
}
|
|
107
|
-
}
|