emr-bridge 1.7.1 → 2.0.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/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/errors.d.ts +42 -10
- package/cjs/errors.js +77 -23
- package/cjs/scripts/base-bridge.d.ts +95 -0
- package/cjs/scripts/base-bridge.js +128 -0
- package/cjs/scripts/helpers/env.d.ts +19 -0
- package/cjs/scripts/helpers/env.js +28 -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/transfer.d.ts +33 -0
- package/cjs/scripts/helpers/transfer.js +57 -0
- package/cjs/scripts/helpers/web-contents-events-container.d.ts +51 -0
- package/cjs/scripts/helpers/web-contents-events-container.js +75 -0
- package/cjs/scripts/main/publish.d.ts +36 -0
- package/cjs/scripts/main/publish.js +184 -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/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/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/errors.d.ts +42 -10
- package/esm/errors.js +69 -16
- package/esm/scripts/base-bridge.d.ts +95 -0
- package/esm/scripts/base-bridge.js +125 -0
- package/esm/scripts/helpers/env.d.ts +19 -0
- package/esm/scripts/helpers/env.js +25 -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/transfer.d.ts +33 -0
- package/esm/scripts/helpers/transfer.js +54 -0
- package/esm/scripts/helpers/web-contents-events-container.d.ts +51 -0
- package/esm/scripts/helpers/web-contents-events-container.js +72 -0
- package/esm/scripts/main/publish.d.ts +36 -0
- package/esm/scripts/main/publish.js +177 -0
- 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/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/types.d.ts +189 -64
- package/package.json +23 -41
- package/cjs/enums.d.ts +0 -19
- package/cjs/enums.js +0 -25
- package/cjs/exp.d.ts +0 -4
- package/cjs/exp.js +0 -19
- package/cjs/index.d.ts +0 -4
- package/cjs/index.js +0 -18
- package/cjs/main.d.ts +0 -4
- package/cjs/main.js +0 -18
- 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 -57
- 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/cjs/scripts/preload-provider.d.ts +0 -7
- package/cjs/scripts/preload-provider.js +0 -96
- package/cjs/scripts/provider.d.ts +0 -25
- package/cjs/scripts/provider.js +0 -116
- package/cjs/scripts/publish.d.ts +0 -40
- package/cjs/scripts/publish.js +0 -232
- package/cjs/scripts/renderer-tunnels.d.ts +0 -47
- package/cjs/scripts/renderer-tunnels.js +0 -115
- package/esm/enums.d.ts +0 -19
- package/esm/enums.js +0 -22
- package/esm/exp.d.ts +0 -4
- package/esm/exp.js +0 -3
- package/esm/index.d.ts +0 -4
- package/esm/index.js +0 -3
- package/esm/main.d.ts +0 -4
- package/esm/main.js +0 -3
- 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 -52
- package/esm/scripts/main.d.ts +0 -8
- package/esm/scripts/main.js +0 -67
- package/esm/scripts/new-decorators.d.ts +0 -150
- package/esm/scripts/new-decorators.js +0 -132
- package/esm/scripts/old-decorators.d.ts +0 -185
- package/esm/scripts/old-decorators.js +0 -122
- package/esm/scripts/preload-provider.d.ts +0 -7
- package/esm/scripts/preload-provider.js +0 -91
- package/esm/scripts/provider.d.ts +0 -25
- package/esm/scripts/provider.js +0 -113
- package/esm/scripts/publish.d.ts +0 -40
- package/esm/scripts/publish.js +0 -220
- package/esm/scripts/renderer-tunnels.d.ts +0 -47
- package/esm/scripts/renderer-tunnels.js +0 -109
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicSetter = exports.publicGetter = exports.publicProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = void 0;
|
|
4
|
-
const publish_js_1 = require("./publish.js");
|
|
5
|
-
function publicMethod(arg) {
|
|
6
|
-
return (method, context) => {
|
|
7
|
-
let name = String(context.name);
|
|
8
|
-
if (arg) {
|
|
9
|
-
if (typeof arg === 'string') {
|
|
10
|
-
name = arg;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
name = arg.name ?? name;
|
|
14
|
-
if (arg.scope)
|
|
15
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
context.addInitializer(function () {
|
|
19
|
-
(0, publish_js_1.publicFunction)(name, method.bind(this));
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.publicMethod = publicMethod;
|
|
24
|
-
function publicClassMainEvent(arg) {
|
|
25
|
-
return (method, context) => {
|
|
26
|
-
let name = String(context.name);
|
|
27
|
-
if (arg) {
|
|
28
|
-
if (typeof arg === 'string') {
|
|
29
|
-
name = arg;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
name = arg.name ?? name;
|
|
33
|
-
if (arg.scope)
|
|
34
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
context.addInitializer(function () {
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
this[context.name] = (0, publish_js_1.publicMainEvent)(name, method.bind(this));
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.publicClassMainEvent = publicClassMainEvent;
|
|
44
|
-
function publicClassRendererEvent(arg) {
|
|
45
|
-
return (_, context) => {
|
|
46
|
-
let name = String(context.name);
|
|
47
|
-
let receiver = (v) => v;
|
|
48
|
-
if (arg) {
|
|
49
|
-
if (typeof arg === 'string') {
|
|
50
|
-
name = arg;
|
|
51
|
-
}
|
|
52
|
-
else if (typeof arg === 'object') {
|
|
53
|
-
name = arg.name ?? String(context.name);
|
|
54
|
-
receiver = arg.procFn ?? receiver;
|
|
55
|
-
if (arg.scope)
|
|
56
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
receiver = arg;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
context.addInitializer(function () {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
this[context.name] = (0, publish_js_1.publicRendererEvent)(name, receiver);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
exports.publicClassRendererEvent = publicClassRendererEvent;
|
|
69
|
-
function publicProperty(arg) {
|
|
70
|
-
return (_, context) => {
|
|
71
|
-
const key = String(context.name);
|
|
72
|
-
let name = key;
|
|
73
|
-
if (arg) {
|
|
74
|
-
if (typeof arg === 'string') {
|
|
75
|
-
name = arg;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
name = arg.name ?? name;
|
|
79
|
-
if (arg.scope)
|
|
80
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
81
|
-
if (arg.access)
|
|
82
|
-
(0, publish_js_1.addAccess)(name, arg.access);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
context.addInitializer(function () {
|
|
86
|
-
(0, publish_js_1.publicVariable)(name, {
|
|
87
|
-
get: () => {
|
|
88
|
-
// @ts-expect-error
|
|
89
|
-
return this[key];
|
|
90
|
-
},
|
|
91
|
-
set: (value) => {
|
|
92
|
-
// @ts-expect-error
|
|
93
|
-
this[key] = value;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
exports.publicProperty = publicProperty;
|
|
100
|
-
function publicGetter(arg) {
|
|
101
|
-
return (getter, context) => {
|
|
102
|
-
let name = String(context.name);
|
|
103
|
-
if (arg) {
|
|
104
|
-
if (typeof arg === 'string') {
|
|
105
|
-
name = arg;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
name = arg.name ?? name;
|
|
109
|
-
if (arg.scope)
|
|
110
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
context.addInitializer(function () {
|
|
114
|
-
(0, publish_js_1.publicVariable)(name, {
|
|
115
|
-
get: getter.bind(this)
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
exports.publicGetter = publicGetter;
|
|
121
|
-
function publicSetter(arg) {
|
|
122
|
-
return (setter, context) => {
|
|
123
|
-
let name = String(context.name);
|
|
124
|
-
if (arg) {
|
|
125
|
-
if (typeof arg === 'string') {
|
|
126
|
-
name = arg;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
name = arg.name ?? name;
|
|
130
|
-
if (arg.scope)
|
|
131
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
context.addInitializer(function () {
|
|
135
|
-
(0, publish_js_1.publicVariable)(name, {
|
|
136
|
-
set: setter.bind(this)
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
exports.publicSetter = publicSetter;
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { EventReceiver, PublishMainEventArgs, PublishMethodArgs, PublishPropertyArgs, PublishRendererEventArgs } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
4
|
-
*
|
|
5
|
-
* _only for static_
|
|
6
|
-
* _experimental decorators_
|
|
7
|
-
*/
|
|
8
|
-
export declare function publicStaticMethod(): MethodDecorator;
|
|
9
|
-
/**
|
|
10
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
11
|
-
*
|
|
12
|
-
* _only for static_
|
|
13
|
-
* _experimental decorators_
|
|
14
|
-
*
|
|
15
|
-
* @param name - name by which the method will be accessed
|
|
16
|
-
*/
|
|
17
|
-
export declare function publicStaticMethod(name: string): MethodDecorator;
|
|
18
|
-
/**
|
|
19
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
20
|
-
*
|
|
21
|
-
* _only for static_
|
|
22
|
-
* _experimental decorators_
|
|
23
|
-
*
|
|
24
|
-
* @param args - publish args
|
|
25
|
-
*/
|
|
26
|
-
export declare function publicStaticMethod(args: PublishMethodArgs): MethodDecorator;
|
|
27
|
-
/**
|
|
28
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
29
|
-
*
|
|
30
|
-
* _only for non-static_
|
|
31
|
-
* _experimental decorators_
|
|
32
|
-
* _required `providePublic(classInstance)`_
|
|
33
|
-
*/
|
|
34
|
-
export declare function publicMethod(): MethodDecorator;
|
|
35
|
-
/**
|
|
36
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
37
|
-
*
|
|
38
|
-
* _only for non-static_
|
|
39
|
-
* _experimental decorators_
|
|
40
|
-
* _required `providePublic(classInstance)`_
|
|
41
|
-
*
|
|
42
|
-
* @param name - name by which the method will be accessed
|
|
43
|
-
*/
|
|
44
|
-
export declare function publicMethod(name: string): MethodDecorator;
|
|
45
|
-
/**
|
|
46
|
-
* Makes the method available for **renderer** and **preload** processes.
|
|
47
|
-
*
|
|
48
|
-
* _only for non-static_
|
|
49
|
-
* _experimental decorators_
|
|
50
|
-
* _required `providePublic(classInstance)`_
|
|
51
|
-
*
|
|
52
|
-
* @param args - publish args
|
|
53
|
-
*/
|
|
54
|
-
export declare function publicMethod(args: PublishMethodArgs): MethodDecorator;
|
|
55
|
-
/**
|
|
56
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
57
|
-
*
|
|
58
|
-
* _only for non-static_
|
|
59
|
-
* _experimental decorators_
|
|
60
|
-
* _required `providePublic(classInstance)`_
|
|
61
|
-
*/
|
|
62
|
-
export declare function publicClassMainEvent(): MethodDecorator;
|
|
63
|
-
/**
|
|
64
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
65
|
-
*
|
|
66
|
-
* _only for non-static_
|
|
67
|
-
* _experimental decorators_
|
|
68
|
-
* _required `providePublic(classInstance)`_
|
|
69
|
-
*
|
|
70
|
-
* @param name - name by which the event will be accessed
|
|
71
|
-
*/
|
|
72
|
-
export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
73
|
-
/**
|
|
74
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
75
|
-
*
|
|
76
|
-
* _only for non-static_
|
|
77
|
-
* _experimental decorators_
|
|
78
|
-
* _required `providePublic(classInstance)`_
|
|
79
|
-
*
|
|
80
|
-
* @param args - publish args
|
|
81
|
-
*/
|
|
82
|
-
export declare function publicClassMainEvent(args: PublishMainEventArgs): MethodDecorator;
|
|
83
|
-
/**
|
|
84
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
85
|
-
*
|
|
86
|
-
* _only for non-static_
|
|
87
|
-
* _experimental decorators_
|
|
88
|
-
*/
|
|
89
|
-
export declare function publicClassRendererEvent(): PropertyDecorator;
|
|
90
|
-
/**
|
|
91
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
92
|
-
*
|
|
93
|
-
* _only for non-static_
|
|
94
|
-
* _experimental decorators_
|
|
95
|
-
*
|
|
96
|
-
* @param name - name by which the event will be accessed
|
|
97
|
-
*/
|
|
98
|
-
export declare function publicClassRendererEvent(name: string): PropertyDecorator;
|
|
99
|
-
/**
|
|
100
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
101
|
-
*
|
|
102
|
-
* _only for non-static_
|
|
103
|
-
* _experimental decorators_
|
|
104
|
-
*
|
|
105
|
-
* @param receiver - linked receiver
|
|
106
|
-
*/
|
|
107
|
-
export declare function publicClassRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
108
|
-
/**
|
|
109
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
110
|
-
*
|
|
111
|
-
* _only for non-static_
|
|
112
|
-
* _experimental decorators_
|
|
113
|
-
*
|
|
114
|
-
* @param name - name by which the event will be accessed
|
|
115
|
-
* @param receiver - linked receiver
|
|
116
|
-
*/
|
|
117
|
-
export declare function publicClassRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
|
|
118
|
-
/**
|
|
119
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
120
|
-
*
|
|
121
|
-
* _only for non-static_
|
|
122
|
-
* _experimental decorators_
|
|
123
|
-
*
|
|
124
|
-
* @param args - publish args
|
|
125
|
-
*/
|
|
126
|
-
export declare function publicClassRendererEvent(args: PublishRendererEventArgs): PropertyDecorator;
|
|
127
|
-
/**
|
|
128
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
129
|
-
*
|
|
130
|
-
* _only for static_
|
|
131
|
-
* _experimental decorators_
|
|
132
|
-
*/
|
|
133
|
-
export declare function publicStaticProperty(): PropertyDecorator;
|
|
134
|
-
/**
|
|
135
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
136
|
-
*
|
|
137
|
-
* _only for static_
|
|
138
|
-
* _experimental decorators_
|
|
139
|
-
*
|
|
140
|
-
* @param name - name by which the property will be accessed
|
|
141
|
-
*/
|
|
142
|
-
export declare function publicStaticProperty(name: string): PropertyDecorator;
|
|
143
|
-
/**
|
|
144
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
145
|
-
*
|
|
146
|
-
* _only for static_
|
|
147
|
-
* _experimental decorators_
|
|
148
|
-
*
|
|
149
|
-
* @param args - publish args
|
|
150
|
-
*/
|
|
151
|
-
export declare function publicStaticProperty(args: PublishPropertyArgs): PropertyDecorator;
|
|
152
|
-
/**
|
|
153
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
154
|
-
*
|
|
155
|
-
* _only for non-static_
|
|
156
|
-
* _experimental decorators_
|
|
157
|
-
* _required `providePublic(classInstance)`_
|
|
158
|
-
*/
|
|
159
|
-
export declare function publicProperty(): PropertyDecorator;
|
|
160
|
-
/**
|
|
161
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
162
|
-
*
|
|
163
|
-
* _only for non-static_
|
|
164
|
-
* _experimental decorators_
|
|
165
|
-
* _required `providePublic(classInstance)`_
|
|
166
|
-
*
|
|
167
|
-
* @param name - name by which the property will be accessed
|
|
168
|
-
*/
|
|
169
|
-
export declare function publicProperty(name: string): PropertyDecorator;
|
|
170
|
-
/**
|
|
171
|
-
* Makes the property available for **renderer** and **preload** processes.
|
|
172
|
-
*
|
|
173
|
-
* _only for non-static_
|
|
174
|
-
* _experimental decorators_
|
|
175
|
-
* _required `providePublic(classInstance)`_
|
|
176
|
-
*
|
|
177
|
-
* @param args - publish args
|
|
178
|
-
*/
|
|
179
|
-
export declare function publicProperty(args: PublishPropertyArgs): PropertyDecorator;
|
|
180
|
-
/**
|
|
181
|
-
* Binds all public entities of a class to a specific instance.
|
|
182
|
-
*
|
|
183
|
-
* _only for class instance_
|
|
184
|
-
*/
|
|
185
|
-
export declare function providePublic<InstanceType>(instance: InstanceType): InstanceType;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
|
|
4
|
-
const publish_js_1 = require("./publish.js");
|
|
5
|
-
function publicStaticMethod(arg) {
|
|
6
|
-
return (target, key) => {
|
|
7
|
-
let name = String(key);
|
|
8
|
-
if (arg) {
|
|
9
|
-
if (typeof arg === 'string') {
|
|
10
|
-
name = arg;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
name = arg.name ?? String(key);
|
|
14
|
-
if (arg.scope)
|
|
15
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
(0, publish_js_1.publicFunction)(name, (...args) => target[key](...args));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
exports.publicStaticMethod = publicStaticMethod;
|
|
22
|
-
function publicMethod(arg) {
|
|
23
|
-
return (tgt, key, _) => {
|
|
24
|
-
const target = tgt;
|
|
25
|
-
const prevRegister = target.__register__ ?? (() => { });
|
|
26
|
-
target.__register__ = instance => {
|
|
27
|
-
prevRegister(instance);
|
|
28
|
-
publicStaticMethod(arg)(instance, key, _);
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
exports.publicMethod = publicMethod;
|
|
33
|
-
function publicClassMainEvent(arg) {
|
|
34
|
-
return (tgt, key, _) => {
|
|
35
|
-
const target = tgt;
|
|
36
|
-
const prevRegister = target.__register__ ?? (() => { });
|
|
37
|
-
target.__register__ = instance => {
|
|
38
|
-
prevRegister(instance);
|
|
39
|
-
let name = String(key);
|
|
40
|
-
if (arg) {
|
|
41
|
-
if (typeof arg === 'string') {
|
|
42
|
-
name = arg;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
name = arg.name ?? String(key);
|
|
46
|
-
if (arg.scope)
|
|
47
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
instance[key] = (0, publish_js_1.publicMainEvent)(name, instance[key].bind(instance));
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
exports.publicClassMainEvent = publicClassMainEvent;
|
|
55
|
-
function publicClassRendererEvent(arg) {
|
|
56
|
-
return (tgt, key) => {
|
|
57
|
-
const target = tgt;
|
|
58
|
-
const prevRegister = target.__register__ ?? (() => { });
|
|
59
|
-
target.__register__ = instance => {
|
|
60
|
-
prevRegister(instance);
|
|
61
|
-
let name = String(key);
|
|
62
|
-
let receiver = (v) => v;
|
|
63
|
-
if (arg) {
|
|
64
|
-
if (typeof arg === 'string') {
|
|
65
|
-
name = arg;
|
|
66
|
-
}
|
|
67
|
-
else if (typeof arg === 'object') {
|
|
68
|
-
name = arg.name ?? String(key);
|
|
69
|
-
receiver = arg.procFn ?? receiver;
|
|
70
|
-
if (arg.scope)
|
|
71
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
receiver = arg;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
instance[key] = (0, publish_js_1.publicRendererEvent)(name, receiver);
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
exports.publicClassRendererEvent = publicClassRendererEvent;
|
|
82
|
-
function publicStaticProperty(arg) {
|
|
83
|
-
return (target, key) => {
|
|
84
|
-
let name = String(key);
|
|
85
|
-
if (arg) {
|
|
86
|
-
if (typeof arg === 'string') {
|
|
87
|
-
name = arg;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
name = arg.name ?? String(key);
|
|
91
|
-
if (arg.scope)
|
|
92
|
-
(0, publish_js_1.addScope)(name, arg.scope);
|
|
93
|
-
if (arg.access)
|
|
94
|
-
(0, publish_js_1.addAccess)(name, arg.access);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
(0, publish_js_1.publicVariable)(name, {
|
|
98
|
-
get() {
|
|
99
|
-
return target[key];
|
|
100
|
-
},
|
|
101
|
-
set(value) {
|
|
102
|
-
target[key] = value;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
exports.publicStaticProperty = publicStaticProperty;
|
|
108
|
-
function publicProperty(arg) {
|
|
109
|
-
return (tgt, key) => {
|
|
110
|
-
const target = tgt;
|
|
111
|
-
const prevRegister = target.__register__ ?? (() => { });
|
|
112
|
-
target.__register__ = instance => {
|
|
113
|
-
prevRegister(instance);
|
|
114
|
-
publicStaticProperty(arg)(instance, key);
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
exports.publicProperty = publicProperty;
|
|
119
|
-
/**
|
|
120
|
-
* Binds all public entities of a class to a specific instance.
|
|
121
|
-
*
|
|
122
|
-
* _only for class instance_
|
|
123
|
-
*/
|
|
124
|
-
function providePublic(instance) {
|
|
125
|
-
const target = instance;
|
|
126
|
-
if (!target.__register__)
|
|
127
|
-
throw new Error('Public methods not defined');
|
|
128
|
-
target.__register__(instance);
|
|
129
|
-
target.__register__ = undefined;
|
|
130
|
-
return instance;
|
|
131
|
-
}
|
|
132
|
-
exports.providePublic = providePublic;
|
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
const renderer_tunnels_js_1 = __importDefault(require("./renderer-tunnels.js"));
|
|
9
|
-
/** Выбрасывает ошибку если используется не в том процессе */
|
|
10
|
-
let mayThrowError = () => { };
|
|
11
|
-
if (typeof window === 'undefined') {
|
|
12
|
-
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in main process.'); };
|
|
13
|
-
}
|
|
14
|
-
else if (!('contextBridge' in electron_1.default)) {
|
|
15
|
-
mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in renderer process.'); };
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Sets access to main from renderer
|
|
19
|
-
*
|
|
20
|
-
* @param contextIsolation - _default_: `true`
|
|
21
|
-
*/
|
|
22
|
-
function provideFromMain(contextIsolation = true) {
|
|
23
|
-
mayThrowError();
|
|
24
|
-
const { contextBridge, ipcRenderer } = electron_1.default;
|
|
25
|
-
const info = ipcRenderer.sendSync(enums_js_1.IPCChannel.getPublicInfo);
|
|
26
|
-
const provider = {
|
|
27
|
-
getInfo: () => info,
|
|
28
|
-
waitPromise(channel, resolve, reject, secret) {
|
|
29
|
-
new renderer_tunnels_js_1.default.Promise(channel).wait(secret)
|
|
30
|
-
.then(resolve)
|
|
31
|
-
.catch(reject);
|
|
32
|
-
},
|
|
33
|
-
provided: {
|
|
34
|
-
functions: getFunctions(),
|
|
35
|
-
properties: getProperties(),
|
|
36
|
-
mainEvents: getMainEvents(),
|
|
37
|
-
rendererEvents: getRendererEvents(),
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
if (contextIsolation) {
|
|
41
|
-
contextBridge.exposeInMainWorld('__provider__', provider);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
window.__provider__ = provider;
|
|
45
|
-
}
|
|
46
|
-
function getFunctions() {
|
|
47
|
-
const result = {};
|
|
48
|
-
for (const name of info.functions) {
|
|
49
|
-
result[name] = (secret, args) => {
|
|
50
|
-
return new renderer_tunnels_js_1.default.Function(name).call({ args, secret });
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
function getProperties() {
|
|
56
|
-
const result = {};
|
|
57
|
-
for (const name of info.properties) {
|
|
58
|
-
const tunnel = new renderer_tunnels_js_1.default.Property(name);
|
|
59
|
-
result[name] = {
|
|
60
|
-
get: () => tunnel.get(),
|
|
61
|
-
set: (value) => tunnel.set(value)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
function getMainEvents() {
|
|
67
|
-
const result = {};
|
|
68
|
-
for (const name of info.mainEvents) {
|
|
69
|
-
result[name] = (type, handler) => {
|
|
70
|
-
const tunnel = new renderer_tunnels_js_1.default.MainEvent(name);
|
|
71
|
-
if (type === 'on')
|
|
72
|
-
return tunnel.on(handler);
|
|
73
|
-
else
|
|
74
|
-
return tunnel.once(handler);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
function getRendererEvents() {
|
|
80
|
-
const result = {};
|
|
81
|
-
for (const name of info.rendererEvents) {
|
|
82
|
-
result[name] = (arg) => {
|
|
83
|
-
const tunnel = new renderer_tunnels_js_1.default.RendererEvent(name);
|
|
84
|
-
if (arg instanceof Promise) {
|
|
85
|
-
arg.then(value => tunnel.emit(value))
|
|
86
|
-
.catch(reason => tunnel.error(String(reason)));
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
tunnel.emit(arg);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.default = provideFromMain;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Scope } from '../enums.js';
|
|
2
|
-
import type { EventHandler, EventUnsubscriber, IPCResult, Info, Target } from '../types.js';
|
|
3
|
-
export default abstract class Provider implements Target {
|
|
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;
|
|
13
|
-
protected readonly target: any;
|
|
14
|
-
protected init(): void;
|
|
15
|
-
protected errorHandler(error: string, channel: string): never;
|
|
16
|
-
protected initFunctions(): void;
|
|
17
|
-
protected initRendererEvents(): void;
|
|
18
|
-
protected initMainEvents(): void;
|
|
19
|
-
protected initProperties(): void;
|
|
20
|
-
protected define(name: string, attrs?: {
|
|
21
|
-
get?: () => any;
|
|
22
|
-
set?: (v: any) => void;
|
|
23
|
-
value?: any;
|
|
24
|
-
}): void;
|
|
25
|
-
}
|
package/cjs/scripts/provider.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const enums_js_1 = require("../enums.js");
|
|
4
|
-
const errors_js_1 = require("../errors.js");
|
|
5
|
-
class Provider {
|
|
6
|
-
as() { return this.target; }
|
|
7
|
-
target = {};
|
|
8
|
-
init() {
|
|
9
|
-
this.initFunctions();
|
|
10
|
-
this.initProperties();
|
|
11
|
-
this.initMainEvents();
|
|
12
|
-
this.initRendererEvents();
|
|
13
|
-
}
|
|
14
|
-
errorHandler(error, channel) {
|
|
15
|
-
throw new Error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
16
|
-
}
|
|
17
|
-
initFunctions() {
|
|
18
|
-
for (const name of this.info.functions) {
|
|
19
|
-
this.define(name, {
|
|
20
|
-
value: (...args) => {
|
|
21
|
-
const secret = Math.random();
|
|
22
|
-
const { error, promiseChannel, value } = this.callFunction(name, secret, args);
|
|
23
|
-
if (error) {
|
|
24
|
-
this.errorHandler(error, name);
|
|
25
|
-
}
|
|
26
|
-
if (promiseChannel)
|
|
27
|
-
return this.waitPromise(promiseChannel, secret);
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
initRendererEvents() {
|
|
34
|
-
for (const name of this.info.rendererEvents) {
|
|
35
|
-
this.define(name, {
|
|
36
|
-
value: (arg) => {
|
|
37
|
-
this.emitRendererEvent(name, arg);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
initMainEvents() {
|
|
43
|
-
for (const name of this.info.mainEvents) {
|
|
44
|
-
const eventNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
45
|
-
const eventNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
|
|
46
|
-
this.define(eventNameOn, {
|
|
47
|
-
value: (handler) => {
|
|
48
|
-
return this.handleMainEvent(name, 'on', ({ error, value }) => {
|
|
49
|
-
if (error) {
|
|
50
|
-
this.errorHandler(error, name);
|
|
51
|
-
}
|
|
52
|
-
handler(value);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
this.define(eventNameOnce, {
|
|
57
|
-
value: (handler) => {
|
|
58
|
-
return this.handleMainEvent(name, 'once', ({ error, value }) => {
|
|
59
|
-
if (error) {
|
|
60
|
-
this.errorHandler(error, name);
|
|
61
|
-
}
|
|
62
|
-
handler(value);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
initProperties() {
|
|
69
|
-
for (const name of this.info.properties) {
|
|
70
|
-
this.define(name, {
|
|
71
|
-
get: this.info.accesses.get(name).has(enums_js_1.Access.get)
|
|
72
|
-
? () => {
|
|
73
|
-
const { error, value } = this.getVariable(name);
|
|
74
|
-
if (error) {
|
|
75
|
-
this.errorHandler(error, name);
|
|
76
|
-
}
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
: () => { throw new errors_js_1.NoGetAccessError(name); },
|
|
80
|
-
set: this.info.accesses.get(name).has(enums_js_1.Access.set)
|
|
81
|
-
? (value) => {
|
|
82
|
-
const { error } = this.setVariable(name, value);
|
|
83
|
-
if (error) {
|
|
84
|
-
this.errorHandler(error, name);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
: () => { throw new errors_js_1.NoSetAccessError(name); }
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
define(name, attrs) {
|
|
92
|
-
let descriptor;
|
|
93
|
-
if (!this.info.scopes.get(name).has(this.scope)) {
|
|
94
|
-
descriptor = {
|
|
95
|
-
get: () => { throw new errors_js_1.NotProvidedIntoScopeError(name, this.scope); },
|
|
96
|
-
set: () => { throw new errors_js_1.NotProvidedIntoScopeError(name, this.scope); }
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
else if (attrs?.value) {
|
|
100
|
-
descriptor = {
|
|
101
|
-
get: () => attrs.value,
|
|
102
|
-
set: () => { throw new errors_js_1.TrySetReadonlyError(name); },
|
|
103
|
-
enumerable: true
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
descriptor = {
|
|
108
|
-
get: attrs?.get || (() => { throw new errors_js_1.NoSetAccessError(name); }),
|
|
109
|
-
set: attrs?.set || (() => { throw new errors_js_1.TrySetReadonlyError(name); }),
|
|
110
|
-
enumerable: true
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
Object.defineProperty(this.target, name, descriptor);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.default = Provider;
|