emr-bridge 1.6.2 → 1.7.1
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/cjs/errors.d.ts +28 -0
- package/cjs/errors.js +39 -0
- package/cjs/exp.d.ts +4 -4
- package/cjs/exp.js +16 -16
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +15 -15
- package/cjs/main.d.ts +4 -4
- package/cjs/main.js +15 -15
- package/cjs/preload.d.ts +3 -3
- package/cjs/preload.js +4 -4
- package/cjs/renderer.d.ts +2 -2
- package/cjs/renderer.js +2 -2
- package/cjs/scripts/{Bridge.d.ts → bridge.d.ts} +2 -2
- package/cjs/scripts/bridge.js +57 -0
- package/{esm/scripts/Main.d.ts → cjs/scripts/main.d.ts} +2 -2
- package/cjs/scripts/main.js +72 -0
- package/cjs/scripts/{newDecorators.d.ts → new-decorators.d.ts} +5 -5
- package/cjs/scripts/{newDecorators.js → new-decorators.js} +14 -14
- package/cjs/scripts/{oldDecorators.d.ts → old-decorators.d.ts} +7 -7
- package/cjs/scripts/{oldDecorators.js → old-decorators.js} +10 -10
- package/cjs/scripts/preload-provider.js +96 -0
- package/cjs/scripts/provider.d.ts +25 -3
- package/cjs/scripts/provider.js +97 -93
- package/cjs/scripts/publish.d.ts +2 -2
- package/cjs/scripts/publish.js +36 -33
- package/cjs/scripts/renderer-tunnels.d.ts +47 -0
- package/cjs/scripts/renderer-tunnels.js +115 -0
- package/cjs/types.d.ts +32 -39
- package/esm/errors.d.ts +28 -0
- package/esm/errors.js +27 -0
- package/esm/exp.d.ts +4 -4
- package/esm/exp.js +3 -3
- package/esm/index.d.ts +4 -4
- package/esm/index.js +3 -3
- package/esm/main.d.ts +4 -4
- package/esm/main.js +3 -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/{Bridge.d.ts → bridge.d.ts} +2 -2
- package/esm/scripts/bridge.js +52 -0
- package/{cjs/scripts/Main.d.ts → esm/scripts/main.d.ts} +2 -2
- package/esm/scripts/main.js +67 -0
- package/esm/scripts/{newDecorators.d.ts → new-decorators.d.ts} +5 -5
- package/esm/scripts/{newDecorators.js → new-decorators.js} +1 -1
- package/esm/scripts/{oldDecorators.d.ts → old-decorators.d.ts} +7 -7
- package/esm/scripts/{oldDecorators.js → old-decorators.js} +1 -1
- package/esm/scripts/preload-provider.js +91 -0
- package/esm/scripts/provider.d.ts +25 -3
- package/esm/scripts/provider.js +96 -93
- package/esm/scripts/publish.d.ts +2 -2
- package/esm/scripts/publish.js +19 -16
- package/esm/scripts/renderer-tunnels.d.ts +47 -0
- package/esm/scripts/renderer-tunnels.js +109 -0
- package/esm/types.d.ts +32 -39
- package/package.json +2 -1
- package/cjs/scripts/Bridge.js +0 -58
- package/cjs/scripts/Main.js +0 -85
- package/cjs/scripts/preloadProvider.js +0 -92
- package/esm/scripts/Bridge.js +0 -53
- package/esm/scripts/Main.js +0 -80
- package/esm/scripts/preloadProvider.js +0 -87
- /package/cjs/scripts/{preloadProvider.d.ts → preload-provider.d.ts} +0 -0
- /package/esm/scripts/{preloadProvider.d.ts → preload-provider.d.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
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 electron_1 = __importDefault(require("electron"));
|
|
7
|
+
const enums_js_1 = require("../enums.js");
|
|
8
|
+
class FunctionTunnel {
|
|
9
|
+
#tunnel;
|
|
10
|
+
constructor(name) {
|
|
11
|
+
this.#tunnel = new IPCTunnel(enums_js_1.IPCChannel.functionCall + name);
|
|
12
|
+
}
|
|
13
|
+
call(args = { args: [] }) {
|
|
14
|
+
return this.#tunnel.request(args);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class PropertyTunnel {
|
|
18
|
+
#getTunnel;
|
|
19
|
+
#setTunnel;
|
|
20
|
+
constructor(name) {
|
|
21
|
+
this.#getTunnel = new IPCTunnel(enums_js_1.IPCChannel.propertyGet + name);
|
|
22
|
+
this.#setTunnel = new IPCTunnel(enums_js_1.IPCChannel.propertySet + name);
|
|
23
|
+
}
|
|
24
|
+
get() {
|
|
25
|
+
return this.#getTunnel.request();
|
|
26
|
+
}
|
|
27
|
+
set(value) {
|
|
28
|
+
return this.#setTunnel.request({ args: [value] });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class PromiseTunnel {
|
|
32
|
+
#tunnel;
|
|
33
|
+
constructor(channel) {
|
|
34
|
+
this.#tunnel = new IPCTunnel(channel);
|
|
35
|
+
}
|
|
36
|
+
wait(secret) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const handler = (_, { error, value, secret: resSecret }) => {
|
|
39
|
+
if (secret !== undefined && resSecret !== secret)
|
|
40
|
+
return;
|
|
41
|
+
if (error)
|
|
42
|
+
reject(error);
|
|
43
|
+
else
|
|
44
|
+
resolve(value);
|
|
45
|
+
this.#tunnel.removeListener(handler);
|
|
46
|
+
};
|
|
47
|
+
this.#tunnel.on(handler);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class MainEventTunnel {
|
|
52
|
+
#emitTunnel;
|
|
53
|
+
#onTunnel;
|
|
54
|
+
#onceTunnel;
|
|
55
|
+
constructor(name) {
|
|
56
|
+
this.#emitTunnel = new IPCTunnel(enums_js_1.IPCChannel.mainEventEmit + name);
|
|
57
|
+
this.#onTunnel = new IPCTunnel(enums_js_1.IPCChannel.mainEventOn + name);
|
|
58
|
+
this.#onceTunnel = new IPCTunnel(enums_js_1.IPCChannel.mainEventOnce + name);
|
|
59
|
+
}
|
|
60
|
+
on(handler) {
|
|
61
|
+
const listener = (_, result) => handler(result);
|
|
62
|
+
this.#onTunnel.response();
|
|
63
|
+
this.#emitTunnel.on(listener);
|
|
64
|
+
return () => this.#emitTunnel.removeListener(listener);
|
|
65
|
+
}
|
|
66
|
+
once(handler) {
|
|
67
|
+
const listener = (_, result) => handler(result);
|
|
68
|
+
this.#onceTunnel.response();
|
|
69
|
+
this.#emitTunnel.once(listener);
|
|
70
|
+
return () => this.#emitTunnel.removeListener(listener);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class RendererEventTunnel {
|
|
74
|
+
#emitTunnel;
|
|
75
|
+
constructor(name) {
|
|
76
|
+
this.#emitTunnel = new IPCTunnel(enums_js_1.IPCChannel.rendererEventEmit + name);
|
|
77
|
+
}
|
|
78
|
+
emit(value) {
|
|
79
|
+
this.#emitTunnel.response({ value });
|
|
80
|
+
}
|
|
81
|
+
error(error) {
|
|
82
|
+
this.#emitTunnel.response({ error });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class IPCTunnel {
|
|
86
|
+
channel;
|
|
87
|
+
#ipcRenderer = electron_1.default.ipcRenderer;
|
|
88
|
+
static Function = FunctionTunnel;
|
|
89
|
+
static Property = PropertyTunnel;
|
|
90
|
+
static Promise = PromiseTunnel;
|
|
91
|
+
static MainEvent = MainEventTunnel;
|
|
92
|
+
static RendererEvent = RendererEventTunnel;
|
|
93
|
+
constructor(channel) {
|
|
94
|
+
this.channel = channel;
|
|
95
|
+
}
|
|
96
|
+
request(args = { args: [] }) {
|
|
97
|
+
return this.#ipcRenderer.sendSync(this.channel, args);
|
|
98
|
+
}
|
|
99
|
+
response(args = {}) {
|
|
100
|
+
this.#ipcRenderer.send(this.channel, args);
|
|
101
|
+
}
|
|
102
|
+
on(listener) {
|
|
103
|
+
this.#ipcRenderer.on(this.channel, listener);
|
|
104
|
+
}
|
|
105
|
+
once(listener) {
|
|
106
|
+
this.#ipcRenderer.once(this.channel, listener);
|
|
107
|
+
}
|
|
108
|
+
removeListener(listener) {
|
|
109
|
+
this.#ipcRenderer.removeListener(this.channel, listener);
|
|
110
|
+
}
|
|
111
|
+
removeAllListeners() {
|
|
112
|
+
this.#ipcRenderer.removeAllListeners(this.channel);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.default = IPCTunnel;
|
package/cjs/types.d.ts
CHANGED
|
@@ -1,81 +1,74 @@
|
|
|
1
1
|
import type { Scope } from './enums';
|
|
2
2
|
import { Access } from './enums';
|
|
3
|
-
export interface
|
|
3
|
+
export interface Target {
|
|
4
4
|
as<T>(): T;
|
|
5
5
|
}
|
|
6
6
|
export type ClassMethodDecorator = <This, Args extends any[], Return>(method: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => void;
|
|
7
|
-
export type ClassPropertyDecorator = <This,
|
|
8
|
-
export type ClassGetterDecorator = <This,
|
|
9
|
-
export type ClassSetterDecorator = <This,
|
|
10
|
-
export type PublishSetterArgs = Omit<
|
|
11
|
-
export type PublishGetterArgs = Omit<
|
|
12
|
-
export interface
|
|
7
|
+
export type ClassPropertyDecorator = <This, Value>(target: undefined, context: ClassFieldDecoratorContext<This, Value>) => void;
|
|
8
|
+
export type ClassGetterDecorator = <This, Value>(getter: () => Value, context: ClassGetterDecoratorContext<This, Value>) => void;
|
|
9
|
+
export type ClassSetterDecorator = <This, Value>(setter: (value: Value) => void, context: ClassSetterDecoratorContext<This, Value>) => void;
|
|
10
|
+
export type PublishSetterArgs = Omit<PublishPropertyArgs, 'access'>;
|
|
11
|
+
export type PublishGetterArgs = Omit<PublishPropertyArgs, 'access'>;
|
|
12
|
+
export interface IPCResult {
|
|
13
13
|
value?: any;
|
|
14
14
|
error?: string;
|
|
15
15
|
promiseChannel?: string;
|
|
16
|
+
secret?: number;
|
|
16
17
|
}
|
|
17
|
-
export interface
|
|
18
|
+
export interface IPCRequest {
|
|
19
|
+
args: any[];
|
|
20
|
+
secret?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface PublishMethodArgs {
|
|
18
23
|
name?: string;
|
|
19
24
|
scope?: Scope;
|
|
20
25
|
}
|
|
21
|
-
export interface
|
|
26
|
+
export interface PublishMainEventArgs {
|
|
22
27
|
name?: string;
|
|
23
28
|
scope?: Scope;
|
|
24
29
|
}
|
|
25
|
-
export interface
|
|
30
|
+
export interface PublishRendererEventArgs {
|
|
26
31
|
name?: string;
|
|
27
32
|
scope?: Scope;
|
|
28
33
|
procFn?: EventReceiver;
|
|
29
34
|
}
|
|
30
|
-
export interface
|
|
35
|
+
export interface PublishPropertyArgs {
|
|
31
36
|
name?: string;
|
|
32
37
|
scope?: Scope;
|
|
33
38
|
access?: Access;
|
|
34
39
|
}
|
|
35
|
-
export interface ICreateProviderArgs {
|
|
36
|
-
info: IInfo;
|
|
37
|
-
scope: Scope;
|
|
38
|
-
handleMainEvent(name: string, type: 'on' | 'once', handler: EventHandler<IIPCResult>): EventUnsubscriber;
|
|
39
|
-
emitRendererEvent(name: string, arg: any): void;
|
|
40
|
-
callFunction(name: string, ...args: any[]): IIPCResult;
|
|
41
|
-
getVariable(name: string): IIPCResult;
|
|
42
|
-
setVariable(name: string, value: any): IIPCResult | undefined;
|
|
43
|
-
waitPromise(channel: string): Promise<any>;
|
|
44
|
-
}
|
|
45
|
-
export type Scopes = Map<string, Set<Scope>>;
|
|
46
|
-
export type Accesses = Map<string, Set<Access>>;
|
|
47
40
|
export type RendererEvent<T = void> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
48
41
|
export type MainEvent<T = void> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
49
42
|
export type EventEmitter = (...args: any[]) => any;
|
|
50
43
|
export type EventReceiver<I = void, O = I> = (input: I) => O;
|
|
51
44
|
export type EventUnsubscriber = () => void;
|
|
52
45
|
export type EventHandler<T = void> = (result: T) => void;
|
|
53
|
-
export
|
|
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 {
|
|
54
52
|
__register__?(instance: any): void;
|
|
55
53
|
}
|
|
56
|
-
export interface
|
|
57
|
-
getInfo():
|
|
58
|
-
waitPromise(name: string, resolve: (value: any) => void, reject?: (reason?: any) => void): void;
|
|
54
|
+
export interface GlobalProvider {
|
|
55
|
+
getInfo(): Info;
|
|
56
|
+
waitPromise(name: string, resolve: (value: any) => void, reject?: (reason?: any) => void, secret?: number): void;
|
|
59
57
|
provided: {
|
|
60
|
-
functions: Record<string, (
|
|
61
|
-
mainEvents: Record<string, (type: 'on' | 'once', handler: EventHandler<
|
|
58
|
+
functions: Record<string, (secret: number, args: any[]) => IPCResult>;
|
|
59
|
+
mainEvents: Record<string, (type: 'on' | 'once', handler: EventHandler<IPCResult>) => EventUnsubscriber>;
|
|
62
60
|
rendererEvents: Record<string, (arg: any) => void>;
|
|
63
61
|
properties: Record<string, {
|
|
64
|
-
get():
|
|
65
|
-
set(val: any):
|
|
62
|
+
get(): IPCResult;
|
|
63
|
+
set(val: any): IPCResult;
|
|
66
64
|
}>;
|
|
67
65
|
};
|
|
68
66
|
}
|
|
69
|
-
export
|
|
70
|
-
export type PublicProperty<T> = {
|
|
71
|
-
get?(): T;
|
|
72
|
-
set?(value: T): void;
|
|
73
|
-
};
|
|
74
|
-
export interface IInfo {
|
|
67
|
+
export interface Info {
|
|
75
68
|
properties: Set<string>;
|
|
76
69
|
functions: Set<string>;
|
|
77
70
|
mainEvents: Set<string>;
|
|
78
71
|
rendererEvents: Set<string>;
|
|
79
|
-
scopes:
|
|
80
|
-
accesses:
|
|
72
|
+
scopes: Map<string, Set<Scope>>;
|
|
73
|
+
accesses: Map<string, Set<Access>>;
|
|
81
74
|
}
|
package/esm/errors.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Scope } from './enums.js';
|
|
2
|
+
export declare class NoSetAccessError extends Error {
|
|
3
|
+
constructor(name: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class NoGetAccessError extends Error {
|
|
6
|
+
constructor(name: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class NotProvidedIntoScopeError extends Error {
|
|
9
|
+
constructor(name: string, scope: Scope);
|
|
10
|
+
}
|
|
11
|
+
export declare class NotProvidedFromMain extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
export declare class GlobalProviderNotFoundError extends Error {
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
17
|
+
export declare class TrySetReadonlyError extends Error {
|
|
18
|
+
constructor(name: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class TryUseBridgeInPreload extends Error {
|
|
21
|
+
constructor();
|
|
22
|
+
}
|
|
23
|
+
export declare class TryUseMainInRenderer extends Error {
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
export declare class TryUseMainInMain extends Error {
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
package/esm/errors.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class NoSetAccessError extends Error {
|
|
2
|
+
constructor(name) { super(`No access to setting '${name}'`); }
|
|
3
|
+
}
|
|
4
|
+
export class NoGetAccessError extends Error {
|
|
5
|
+
constructor(name) { super(`No access to getting '${name}'`); }
|
|
6
|
+
}
|
|
7
|
+
export class NotProvidedIntoScopeError extends Error {
|
|
8
|
+
constructor(name, scope) { super(`'${name}' is not provided into ${scope} scope`); }
|
|
9
|
+
}
|
|
10
|
+
export class NotProvidedFromMain extends Error {
|
|
11
|
+
constructor() { super('Public methods from main is not provided. Call any publish methods to provide it from main process.'); }
|
|
12
|
+
}
|
|
13
|
+
export class GlobalProviderNotFoundError extends Error {
|
|
14
|
+
constructor() { super('Required methods not provided. Call "provideFromMain" in preload process.'); }
|
|
15
|
+
}
|
|
16
|
+
export class TrySetReadonlyError extends Error {
|
|
17
|
+
constructor(name) { super(`'${name}' is readonly`); }
|
|
18
|
+
}
|
|
19
|
+
export class TryUseBridgeInPreload extends Error {
|
|
20
|
+
constructor() { super('"Bridge" is unavailable in main process. In preload use "Main" instead.'); }
|
|
21
|
+
}
|
|
22
|
+
export class TryUseMainInRenderer extends Error {
|
|
23
|
+
constructor() { super('"Main" is unavailable in renderer process. Use "Bridge" instead'); }
|
|
24
|
+
}
|
|
25
|
+
export class TryUseMainInMain extends Error {
|
|
26
|
+
constructor() { super('"Main" is unavailable in main process.'); }
|
|
27
|
+
}
|
package/esm/exp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
|
-
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber,
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/old-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
|
4
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, MainEvent, PublicFunction, PublicProperty, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, RendererEvent } from './types.js';
|
package/esm/exp.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/old-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
|
-
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber,
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/new-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
|
4
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, MainEvent, PublicFunction, PublicProperty, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, RendererEvent } from './types.js';
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/new-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
package/esm/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
|
-
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber,
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/new-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
|
4
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, MainEvent, PublicFunction, PublicProperty, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, RendererEvent } from './types.js';
|
package/esm/main.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Access, Scope } from './enums';
|
|
2
|
-
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/
|
|
3
|
-
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
1
|
+
export { Access, Scope } from './enums.js';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/new-decorators.js';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish.js';
|
package/esm/preload.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as Main } from './scripts/
|
|
2
|
-
export { default as provideFromMain } from './scripts/
|
|
3
|
-
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber,
|
|
1
|
+
export { default as Main } from './scripts/main.js';
|
|
2
|
+
export { default as provideFromMain } from './scripts/preload-provider.js';
|
|
3
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, MainEvent, PublicFunction, PublicProperty, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, RendererEvent } from './types.js';
|
package/esm/preload.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as Main } from './scripts/
|
|
2
|
-
export { default as provideFromMain } from './scripts/
|
|
1
|
+
export { default as Main } from './scripts/main.js';
|
|
2
|
+
export { default as provideFromMain } from './scripts/preload-provider.js';
|
package/esm/renderer.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as Bridge } from './scripts/
|
|
2
|
-
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber,
|
|
1
|
+
export { default as Bridge } from './scripts/bridge.js';
|
|
2
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, MainEvent, PublicFunction, PublicProperty, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, RendererEvent } from './types.js';
|
package/esm/renderer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as Bridge } from './scripts/
|
|
1
|
+
export { default as Bridge } from './scripts/bridge.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Target } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Bridge between `renderer` and `main` processes.
|
|
4
4
|
*
|
|
5
5
|
* _only for renderer process_
|
|
6
6
|
*/
|
|
7
|
-
declare let Bridge:
|
|
7
|
+
declare let Bridge: Target;
|
|
8
8
|
export default Bridge;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Scope } from '../enums.js';
|
|
2
|
+
import { GlobalProviderNotFoundError, TryUseBridgeInPreload } from '../errors.js';
|
|
3
|
+
import Provider from './provider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Bridge between `renderer` and `main` processes.
|
|
6
|
+
*
|
|
7
|
+
* _only for renderer process_
|
|
8
|
+
*/
|
|
9
|
+
let Bridge = new Proxy({ as: () => throwError() }, {
|
|
10
|
+
get: () => throwError(),
|
|
11
|
+
set: () => throwError(),
|
|
12
|
+
apply: () => throwError()
|
|
13
|
+
});
|
|
14
|
+
class ProviderIntoRenderer extends Provider {
|
|
15
|
+
#globalProvider = window.__provider__;
|
|
16
|
+
constructor() { super(); this.init(); }
|
|
17
|
+
info = this.#globalProvider.getInfo();
|
|
18
|
+
scope = Scope.renderer;
|
|
19
|
+
callFunction(name, secret, args) {
|
|
20
|
+
return this.#globalProvider.provided.functions[name](secret, args);
|
|
21
|
+
}
|
|
22
|
+
getVariable(name) {
|
|
23
|
+
return this.#globalProvider.provided.properties[name].get();
|
|
24
|
+
}
|
|
25
|
+
setVariable(name, value) {
|
|
26
|
+
return this.#globalProvider.provided.properties[name].set(value);
|
|
27
|
+
}
|
|
28
|
+
waitPromise(channel, secret) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
this.#globalProvider.waitPromise(channel, resolve, reject, secret);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
handleMainEvent(name, type, handler) {
|
|
34
|
+
return this.#globalProvider.provided.mainEvents[name](type, handler);
|
|
35
|
+
}
|
|
36
|
+
emitRendererEvent(name, arg) {
|
|
37
|
+
this.#globalProvider.provided.rendererEvents[name](arg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
41
|
+
let throwError;
|
|
42
|
+
if (typeof window === 'undefined') {
|
|
43
|
+
throwError = () => { throw new TryUseBridgeInPreload(); };
|
|
44
|
+
}
|
|
45
|
+
else if (!window.__provider__) {
|
|
46
|
+
throwError = () => { throw new GlobalProviderNotFoundError(); };
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Выполняется только в web
|
|
50
|
+
Bridge = new ProviderIntoRenderer();
|
|
51
|
+
}
|
|
52
|
+
export default Bridge;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Target } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Bridge between `preload` and `main` processes.
|
|
4
4
|
*
|
|
5
5
|
* _only for preload process_
|
|
6
6
|
*/
|
|
7
|
-
declare let Main:
|
|
7
|
+
declare let Main: Target;
|
|
8
8
|
export default Main;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import electron from 'electron';
|
|
2
|
+
import { IPCChannel, Scope } from '../enums.js';
|
|
3
|
+
import { NotProvidedFromMain, TryUseMainInMain, TryUseMainInRenderer } from '../errors.js';
|
|
4
|
+
import Provider from './provider.js';
|
|
5
|
+
import IPCTunnel from './renderer-tunnels.js';
|
|
6
|
+
/**
|
|
7
|
+
* Bridge between `preload` and `main` processes.
|
|
8
|
+
*
|
|
9
|
+
* _only for preload process_
|
|
10
|
+
*/
|
|
11
|
+
let Main = new Proxy({ as() { throwError(); } }, {
|
|
12
|
+
get() { throwError(); },
|
|
13
|
+
set() { throwError(); },
|
|
14
|
+
apply() { throwError(); }
|
|
15
|
+
});
|
|
16
|
+
class ProviderIntoPreload extends Provider {
|
|
17
|
+
#ipcRenderer = electron.ipcRenderer;
|
|
18
|
+
info = this.#ipcRenderer.sendSync(IPCChannel.getPublicInfo);
|
|
19
|
+
scope = Scope.preload;
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
if (!this.info)
|
|
23
|
+
throw new NotProvidedFromMain();
|
|
24
|
+
}
|
|
25
|
+
callFunction(name, secret, args) {
|
|
26
|
+
return new IPCTunnel.Function(name).call({ args, secret });
|
|
27
|
+
}
|
|
28
|
+
getVariable(name) {
|
|
29
|
+
return new IPCTunnel.Property(name).get();
|
|
30
|
+
}
|
|
31
|
+
setVariable(name, value) {
|
|
32
|
+
return new IPCTunnel.Property(name).set(value);
|
|
33
|
+
}
|
|
34
|
+
async waitPromise(channel, secret) {
|
|
35
|
+
return await new IPCTunnel.Promise(channel).wait(secret);
|
|
36
|
+
}
|
|
37
|
+
handleMainEvent(name, type, handler) {
|
|
38
|
+
const tunnel = new IPCTunnel.MainEvent(name);
|
|
39
|
+
if (type === 'on')
|
|
40
|
+
return tunnel.on(handler);
|
|
41
|
+
else
|
|
42
|
+
return tunnel.once(handler);
|
|
43
|
+
}
|
|
44
|
+
emitRendererEvent(name, arg) {
|
|
45
|
+
const tunnel = new IPCTunnel.RendererEvent(name);
|
|
46
|
+
if (arg instanceof Promise) {
|
|
47
|
+
arg.then(value => tunnel.emit(value))
|
|
48
|
+
.catch(reason => tunnel.error(String(reason)));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
tunnel.emit(arg);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
56
|
+
let throwError;
|
|
57
|
+
if (typeof window !== 'undefined') {
|
|
58
|
+
throwError = () => { throw new TryUseMainInRenderer(); };
|
|
59
|
+
}
|
|
60
|
+
else if (!('ipcRenderer' in electron)) {
|
|
61
|
+
throwError = () => { throw new TryUseMainInMain(); };
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Выполняется только в NodeJS
|
|
65
|
+
Main = new ProviderIntoPreload();
|
|
66
|
+
}
|
|
67
|
+
export default Main;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, EventReceiver,
|
|
1
|
+
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, EventReceiver, PublishGetterArgs, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs, PublishSetterArgs } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
@@ -20,7 +20,7 @@ export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
|
20
20
|
*
|
|
21
21
|
* @param args - publish args
|
|
22
22
|
*/
|
|
23
|
-
export declare function publicMethod(args:
|
|
23
|
+
export declare function publicMethod(args: PublishMethodArgs): ClassMethodDecorator;
|
|
24
24
|
/**
|
|
25
25
|
* Makes the event available for **renderer** and **preload** processes.
|
|
26
26
|
*
|
|
@@ -42,7 +42,7 @@ export declare function publicClassMainEvent(name: string): ClassMethodDecorator
|
|
|
42
42
|
*
|
|
43
43
|
* @param args - publish args
|
|
44
44
|
*/
|
|
45
|
-
export declare function publicClassMainEvent(args:
|
|
45
|
+
export declare function publicClassMainEvent(args: PublishMainEventArgs): ClassMethodDecorator;
|
|
46
46
|
/**
|
|
47
47
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
48
48
|
*
|
|
@@ -81,7 +81,7 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
81
81
|
*
|
|
82
82
|
* @param args - publish args
|
|
83
83
|
*/
|
|
84
|
-
export declare function publicClassRendererEvent(args:
|
|
84
|
+
export declare function publicClassRendererEvent(args: PublishRendererEventArgs): ClassPropertyDecorator;
|
|
85
85
|
/**
|
|
86
86
|
* Makes the property available for **renderer** and **preload** processes.
|
|
87
87
|
*
|
|
@@ -103,7 +103,7 @@ export declare function publicProperty(name: string): ClassPropertyDecorator;
|
|
|
103
103
|
*
|
|
104
104
|
* @param args - publish args
|
|
105
105
|
*/
|
|
106
|
-
export declare function publicProperty(args:
|
|
106
|
+
export declare function publicProperty(args: PublishPropertyArgs): ClassPropertyDecorator;
|
|
107
107
|
/**
|
|
108
108
|
* Makes the property getter available for **renderer** and **preload** processes.
|
|
109
109
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish';
|
|
1
|
+
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish.js';
|
|
2
2
|
export function publicMethod(arg) {
|
|
3
3
|
return (method, context) => {
|
|
4
4
|
let name = String(context.name);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventReceiver,
|
|
1
|
+
import type { EventReceiver, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
@@ -23,7 +23,7 @@ export declare function publicStaticMethod(name: string): MethodDecorator;
|
|
|
23
23
|
*
|
|
24
24
|
* @param args - publish args
|
|
25
25
|
*/
|
|
26
|
-
export declare function publicStaticMethod(args:
|
|
26
|
+
export declare function publicStaticMethod(args: PublishMethodArgs): MethodDecorator;
|
|
27
27
|
/**
|
|
28
28
|
* Makes the method available for **renderer** and **preload** processes.
|
|
29
29
|
*
|
|
@@ -51,7 +51,7 @@ export declare function publicMethod(name: string): MethodDecorator;
|
|
|
51
51
|
*
|
|
52
52
|
* @param args - publish args
|
|
53
53
|
*/
|
|
54
|
-
export declare function publicMethod(args:
|
|
54
|
+
export declare function publicMethod(args: PublishMethodArgs): MethodDecorator;
|
|
55
55
|
/**
|
|
56
56
|
* Makes the event available for **renderer** and **preload** processes.
|
|
57
57
|
*
|
|
@@ -79,7 +79,7 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
|
79
79
|
*
|
|
80
80
|
* @param args - publish args
|
|
81
81
|
*/
|
|
82
|
-
export declare function publicClassMainEvent(args:
|
|
82
|
+
export declare function publicClassMainEvent(args: PublishMainEventArgs): MethodDecorator;
|
|
83
83
|
/**
|
|
84
84
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
85
85
|
*
|
|
@@ -123,7 +123,7 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
123
123
|
*
|
|
124
124
|
* @param args - publish args
|
|
125
125
|
*/
|
|
126
|
-
export declare function publicClassRendererEvent(args:
|
|
126
|
+
export declare function publicClassRendererEvent(args: PublishRendererEventArgs): PropertyDecorator;
|
|
127
127
|
/**
|
|
128
128
|
* Makes the property available for **renderer** and **preload** processes.
|
|
129
129
|
*
|
|
@@ -148,7 +148,7 @@ export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
|
148
148
|
*
|
|
149
149
|
* @param args - publish args
|
|
150
150
|
*/
|
|
151
|
-
export declare function publicStaticProperty(args:
|
|
151
|
+
export declare function publicStaticProperty(args: PublishPropertyArgs): PropertyDecorator;
|
|
152
152
|
/**
|
|
153
153
|
* Makes the property available for **renderer** and **preload** processes.
|
|
154
154
|
*
|
|
@@ -176,7 +176,7 @@ export declare function publicProperty(name: string): PropertyDecorator;
|
|
|
176
176
|
*
|
|
177
177
|
* @param args - publish args
|
|
178
178
|
*/
|
|
179
|
-
export declare function publicProperty(args:
|
|
179
|
+
export declare function publicProperty(args: PublishPropertyArgs): PropertyDecorator;
|
|
180
180
|
/**
|
|
181
181
|
* Binds all public entities of a class to a specific instance.
|
|
182
182
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish';
|
|
1
|
+
import { addAccess, addScope, publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './publish.js';
|
|
2
2
|
export function publicStaticMethod(arg) {
|
|
3
3
|
return (target, key) => {
|
|
4
4
|
let name = String(key);
|