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
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { contextBridge, ipcRenderer } from 'electron';
|
|
2
|
+
import { IpcChannel } from '../enums.js';
|
|
3
|
+
import { NotProvidedFromMain, TryProvideFromMainInMain, TryProvideFromMainInRenderer } from '../errors.js';
|
|
4
|
+
import { ErrorThrower } from './helpers/index.js';
|
|
3
5
|
import IPCTunnel from './renderer-tunnels.js';
|
|
4
6
|
/** Выбрасывает ошибку если используется не в том процессе */
|
|
5
|
-
let
|
|
6
|
-
if (
|
|
7
|
-
|
|
7
|
+
let canThrowError = () => { };
|
|
8
|
+
if (!ipcRenderer) {
|
|
9
|
+
canThrowError = ErrorThrower.throws(TryProvideFromMainInMain);
|
|
8
10
|
}
|
|
9
|
-
else if (!
|
|
10
|
-
|
|
11
|
+
else if (!contextBridge) {
|
|
12
|
+
canThrowError = ErrorThrower.throws(TryProvideFromMainInRenderer);
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Sets access to main from renderer
|
|
@@ -15,21 +17,32 @@ else if (!('contextBridge' in electron)) {
|
|
|
15
17
|
* @param contextIsolation - _default_: `true`
|
|
16
18
|
*/
|
|
17
19
|
function provideFromMain(contextIsolation = true) {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
canThrowError();
|
|
21
|
+
const entitiesInfo = ipcRenderer.sendSync(IpcChannel.getPublicInfo);
|
|
22
|
+
if (!entitiesInfo) {
|
|
23
|
+
throw new NotProvidedFromMain();
|
|
24
|
+
}
|
|
21
25
|
const provider = {
|
|
22
|
-
|
|
23
|
-
waitPromise(channel, resolve, reject,
|
|
24
|
-
new IPCTunnel.Promise(channel).wait(
|
|
26
|
+
getEntitiesInfo: () => entitiesInfo,
|
|
27
|
+
waitPromise(channel, resolve, reject, id) {
|
|
28
|
+
new IPCTunnel.Promise(channel).wait(id)
|
|
25
29
|
.then(resolve)
|
|
26
30
|
.catch(reject);
|
|
27
31
|
},
|
|
28
|
-
|
|
32
|
+
entities: {
|
|
29
33
|
functions: getFunctions(),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
variables: getProperties(),
|
|
35
|
+
events: {
|
|
36
|
+
emit(name, value) {
|
|
37
|
+
new IPCTunnel.Event(name).emit(value);
|
|
38
|
+
},
|
|
39
|
+
on(name, listener) {
|
|
40
|
+
return new IPCTunnel.Event(name).on(listener);
|
|
41
|
+
},
|
|
42
|
+
once(name, listener) {
|
|
43
|
+
return new IPCTunnel.Event(name).once(listener);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
47
|
};
|
|
35
48
|
if (contextIsolation) {
|
|
@@ -40,16 +53,16 @@ function provideFromMain(contextIsolation = true) {
|
|
|
40
53
|
}
|
|
41
54
|
function getFunctions() {
|
|
42
55
|
const result = {};
|
|
43
|
-
for (const name of
|
|
44
|
-
result[name] = (
|
|
45
|
-
return new IPCTunnel.Function(name).call({ args,
|
|
56
|
+
for (const name of entitiesInfo.functions) {
|
|
57
|
+
result[name] = (id, args) => {
|
|
58
|
+
return new IPCTunnel.Function(name).call({ args, id: id });
|
|
46
59
|
};
|
|
47
60
|
}
|
|
48
61
|
return result;
|
|
49
62
|
}
|
|
50
63
|
function getProperties() {
|
|
51
64
|
const result = {};
|
|
52
|
-
for (const name of
|
|
65
|
+
for (const name of entitiesInfo.variables) {
|
|
53
66
|
const tunnel = new IPCTunnel.Property(name);
|
|
54
67
|
result[name] = {
|
|
55
68
|
get: () => tunnel.get(),
|
|
@@ -58,34 +71,5 @@ function provideFromMain(contextIsolation = true) {
|
|
|
58
71
|
}
|
|
59
72
|
return result;
|
|
60
73
|
}
|
|
61
|
-
function getMainEvents() {
|
|
62
|
-
const result = {};
|
|
63
|
-
for (const name of info.mainEvents) {
|
|
64
|
-
result[name] = (type, handler) => {
|
|
65
|
-
const tunnel = new IPCTunnel.MainEvent(name);
|
|
66
|
-
if (type === 'on')
|
|
67
|
-
return tunnel.on(handler);
|
|
68
|
-
else
|
|
69
|
-
return tunnel.once(handler);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
function getRendererEvents() {
|
|
75
|
-
const result = {};
|
|
76
|
-
for (const name of info.rendererEvents) {
|
|
77
|
-
result[name] = (arg) => {
|
|
78
|
-
const tunnel = new IPCTunnel.RendererEvent(name);
|
|
79
|
-
if (arg instanceof Promise) {
|
|
80
|
-
arg.then(value => tunnel.emit(value))
|
|
81
|
-
.catch(reason => tunnel.error(String(reason)));
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
tunnel.emit(arg);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
74
|
}
|
|
91
75
|
export default provideFromMain;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
protected abstract info: Info;
|
|
5
|
-
protected abstract scope: Scope;
|
|
6
|
-
protected abstract getVariable(name: string): IPCResult;
|
|
7
|
-
protected abstract setVariable(name: string, value: any): IPCResult;
|
|
8
|
-
protected abstract callFunction(name: string, secret: number, args: any[]): IPCResult;
|
|
9
|
-
protected abstract waitPromise(channel: string, secret?: number): Promise<any>;
|
|
10
|
-
protected abstract emitRendererEvent(name: string, arg: any): void;
|
|
11
|
-
protected abstract handleMainEvent(name: string, type: 'on' | 'once', handler: EventHandler<IPCResult>): EventUnsubscriber;
|
|
12
|
-
as<T>(): T;
|
|
1
|
+
import type { EventListener, EventUnsubscribe, IBridge, IEntitiesInfo, IHasSnapshot, IResult } from '../types.js';
|
|
2
|
+
export default abstract class Provider implements IBridge {
|
|
3
|
+
protected abstract entitiesInfo: IEntitiesInfo;
|
|
13
4
|
protected readonly target: any;
|
|
5
|
+
as<TTarget>(): IBridge & TTarget;
|
|
6
|
+
emit(name: string, arg: any): void;
|
|
7
|
+
on<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
8
|
+
once<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
|
|
9
|
+
call<TFunc extends (...args: any[]) => InstanceType<TClass>, TClass extends {
|
|
10
|
+
new (): IHasSnapshot;
|
|
11
|
+
}>(func: TFunc, Class: TClass, args: Parameters<TFunc>): InstanceType<TClass>;
|
|
12
|
+
protected abstract getVariable<T = any>(name: string): IResult<T>;
|
|
13
|
+
protected abstract setVariable<T>(name: string, value: T): IResult<T>;
|
|
14
|
+
protected abstract callFunction<T = any>(name: string, id: string, args: any[]): IResult<T>;
|
|
15
|
+
protected abstract waitPromise<T = any>(channel: string, id?: string): Promise<T>;
|
|
16
|
+
protected abstract emitEvent(name: string, arg: any): void;
|
|
17
|
+
protected abstract handleEvent(name: string, type: 'on' | 'once', handler: EventListener<IResult>): EventUnsubscribe;
|
|
14
18
|
protected init(): void;
|
|
15
|
-
protected
|
|
19
|
+
protected handleError(channel: string, error?: string): void | never;
|
|
16
20
|
protected initFunctions(): void;
|
|
17
|
-
protected initRendererEvents(): void;
|
|
18
|
-
protected initMainEvents(): void;
|
|
19
21
|
protected initProperties(): void;
|
|
20
22
|
protected define(name: string, attrs?: {
|
|
21
23
|
get?: () => any;
|
package/esm/scripts/provider.js
CHANGED
|
@@ -1,113 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { NoSetAccessError, TrySetReadonlyError } from '../errors.js';
|
|
2
|
+
import { ErrorThrower, Id, Transfer } from './helpers/index.js';
|
|
3
3
|
export default class Provider {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
}
|
|
6
36
|
init() {
|
|
7
37
|
this.initFunctions();
|
|
8
38
|
this.initProperties();
|
|
9
|
-
this.initMainEvents();
|
|
10
|
-
this.initRendererEvents();
|
|
11
39
|
}
|
|
12
|
-
|
|
40
|
+
handleError(channel, error) {
|
|
41
|
+
if (!error) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
13
44
|
throw new Error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
14
45
|
}
|
|
15
46
|
initFunctions() {
|
|
16
|
-
for (const name of this.
|
|
47
|
+
for (const name of this.entitiesInfo.functions) {
|
|
17
48
|
this.define(name, {
|
|
18
49
|
value: (...args) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
initRendererEvents() {
|
|
32
|
-
for (const name of this.info.rendererEvents) {
|
|
33
|
-
this.define(name, {
|
|
34
|
-
value: (arg) => {
|
|
35
|
-
this.emitRendererEvent(name, arg);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
initMainEvents() {
|
|
41
|
-
for (const name of this.info.mainEvents) {
|
|
42
|
-
const eventNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
43
|
-
const eventNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
|
|
44
|
-
this.define(eventNameOn, {
|
|
45
|
-
value: (handler) => {
|
|
46
|
-
return this.handleMainEvent(name, 'on', ({ error, value }) => {
|
|
47
|
-
if (error) {
|
|
48
|
-
this.errorHandler(error, name);
|
|
49
|
-
}
|
|
50
|
-
handler(value);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this.define(eventNameOnce, {
|
|
55
|
-
value: (handler) => {
|
|
56
|
-
return this.handleMainEvent(name, 'once', ({ error, value }) => {
|
|
57
|
-
if (error) {
|
|
58
|
-
this.errorHandler(error, name);
|
|
59
|
-
}
|
|
60
|
-
handler(value);
|
|
61
|
-
});
|
|
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;
|
|
62
57
|
}
|
|
63
58
|
});
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
61
|
initProperties() {
|
|
67
|
-
for (const name of this.
|
|
62
|
+
for (const name of this.entitiesInfo.variables) {
|
|
68
63
|
this.define(name, {
|
|
69
|
-
get:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
set: this.info.accesses.get(name).has(Access.set)
|
|
79
|
-
? (value) => {
|
|
80
|
-
const { error } = this.setVariable(name, value);
|
|
81
|
-
if (error) {
|
|
82
|
-
this.errorHandler(error, name);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
: () => { throw new NoSetAccessError(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
|
+
}
|
|
86
73
|
});
|
|
87
74
|
}
|
|
88
75
|
}
|
|
89
76
|
define(name, attrs) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else {
|
|
105
|
-
descriptor = {
|
|
106
|
-
get: attrs?.get || (() => { throw new NoSetAccessError(name); }),
|
|
107
|
-
set: attrs?.set || (() => { throw new TrySetReadonlyError(name); }),
|
|
108
|
-
enumerable: true
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
Object.defineProperty(this.target, name, descriptor);
|
|
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);
|
|
112
91
|
}
|
|
113
92
|
}
|
package/esm/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;
|