emr-bridge 1.4.1 → 1.5.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/cjs/exp.d.ts +1 -1
- package/cjs/exp.js +1 -3
- package/cjs/scripts/Bridge.js +1 -2
- package/cjs/scripts/Main.js +1 -2
- package/cjs/scripts/newDecorators.js +2 -2
- package/cjs/scripts/oldDecorators.d.ts +0 -80
- package/cjs/scripts/oldDecorators.js +30 -42
- package/cjs/scripts/preloadProvider.js +1 -1
- package/cjs/scripts/provider.js +86 -133
- package/cjs/scripts/publish.js +19 -15
- package/cjs/types.d.ts +2 -2
- package/esm/exp.d.ts +1 -1
- package/esm/exp.js +1 -1
- package/esm/scripts/Bridge.js +1 -2
- package/esm/scripts/Main.js +1 -2
- package/esm/scripts/newDecorators.js +2 -2
- package/esm/scripts/oldDecorators.d.ts +0 -80
- package/esm/scripts/oldDecorators.js +29 -39
- package/esm/scripts/preloadProvider.js +1 -1
- package/esm/scripts/provider.js +87 -134
- package/esm/scripts/publish.js +19 -15
- package/esm/types.d.ts +2 -2
- package/package.json +1 -1
package/cjs/exp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty,
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/oldDecorators';
|
|
3
3
|
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
4
|
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/cjs/exp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.
|
|
3
|
+
exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.publicStaticProperty = exports.publicStaticMethod = exports.publicProperty = exports.publicMethod = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.providePublic = exports.Scope = exports.Access = void 0;
|
|
4
4
|
var enums_1 = require("./enums");
|
|
5
5
|
Object.defineProperty(exports, "Access", { enumerable: true, get: function () { return enums_1.Access; } });
|
|
6
6
|
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return enums_1.Scope; } });
|
|
@@ -10,10 +10,8 @@ Object.defineProperty(exports, "publicClassMainEvent", { enumerable: true, get:
|
|
|
10
10
|
Object.defineProperty(exports, "publicClassRendererEvent", { enumerable: true, get: function () { return oldDecorators_1.publicClassRendererEvent; } });
|
|
11
11
|
Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return oldDecorators_1.publicMethod; } });
|
|
12
12
|
Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return oldDecorators_1.publicProperty; } });
|
|
13
|
-
Object.defineProperty(exports, "publicStaticMainEvent", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMainEvent; } });
|
|
14
13
|
Object.defineProperty(exports, "publicStaticMethod", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMethod; } });
|
|
15
14
|
Object.defineProperty(exports, "publicStaticProperty", { enumerable: true, get: function () { return oldDecorators_1.publicStaticProperty; } });
|
|
16
|
-
Object.defineProperty(exports, "publicStaticRendererEvent", { enumerable: true, get: function () { return oldDecorators_1.publicStaticRendererEvent; } });
|
|
17
15
|
var publish_1 = require("./scripts/publish");
|
|
18
16
|
Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_1.publicFunction; } });
|
|
19
17
|
Object.defineProperty(exports, "publicMainEvent", { enumerable: true, get: function () { return publish_1.publicMainEvent; } });
|
package/cjs/scripts/Bridge.js
CHANGED
|
@@ -15,8 +15,7 @@ const info = provider.getInfo();
|
|
|
15
15
|
* _only for renderer process_
|
|
16
16
|
*/
|
|
17
17
|
const Bridge = (0, provider_1.default)({
|
|
18
|
-
info,
|
|
19
|
-
scope: enums_1.Scope.renderer,
|
|
18
|
+
info, scope: enums_1.Scope.renderer,
|
|
20
19
|
callFunction(name, ...args) {
|
|
21
20
|
return provider.provided.functions[name](...args);
|
|
22
21
|
},
|
package/cjs/scripts/Main.js
CHANGED
|
@@ -15,8 +15,7 @@ if (!info)
|
|
|
15
15
|
* _only for preload process_
|
|
16
16
|
*/
|
|
17
17
|
const Main = (0, provider_1.default)({
|
|
18
|
-
info,
|
|
19
|
-
scope: enums_1.Scope.preload,
|
|
18
|
+
info, scope: enums_1.Scope.preload,
|
|
20
19
|
callFunction(name, ...args) {
|
|
21
20
|
return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + name, ...args);
|
|
22
21
|
},
|
|
@@ -85,11 +85,11 @@ function publicProperty(arg) {
|
|
|
85
85
|
context.addInitializer(function () {
|
|
86
86
|
(0, publish_1.publicVariable)(name, {
|
|
87
87
|
get: () => {
|
|
88
|
-
// @ts-
|
|
88
|
+
// @ts-expect-error
|
|
89
89
|
return this[key];
|
|
90
90
|
},
|
|
91
91
|
set: (value) => {
|
|
92
|
-
// @ts-
|
|
92
|
+
// @ts-expect-error
|
|
93
93
|
this[key] = value;
|
|
94
94
|
}
|
|
95
95
|
});
|
|
@@ -57,32 +57,6 @@ export declare function publicMethod(name: string): MethodDecorator;
|
|
|
57
57
|
* @param args - publish args
|
|
58
58
|
*/
|
|
59
59
|
export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
60
|
-
/**
|
|
61
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
62
|
-
*
|
|
63
|
-
* _only for static_
|
|
64
|
-
*
|
|
65
|
-
* _experimental decorators_
|
|
66
|
-
*/
|
|
67
|
-
export declare function publicStaticMainEvent(): MethodDecorator;
|
|
68
|
-
/**
|
|
69
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
70
|
-
*
|
|
71
|
-
* _only for static_
|
|
72
|
-
*
|
|
73
|
-
* _experimental decorators_
|
|
74
|
-
* @param name - name by which the event will be accessed
|
|
75
|
-
*/
|
|
76
|
-
export declare function publicStaticMainEvent(name: string): MethodDecorator;
|
|
77
|
-
/**
|
|
78
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
79
|
-
*
|
|
80
|
-
* _only for static_
|
|
81
|
-
*
|
|
82
|
-
* _experimental decorators_
|
|
83
|
-
* @param args - publish args
|
|
84
|
-
*/
|
|
85
|
-
export declare function publicStaticMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
86
60
|
/**
|
|
87
61
|
* Makes the event available for **renderer** and **preload** processes.
|
|
88
62
|
*
|
|
@@ -115,60 +89,6 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
|
115
89
|
* @param args - publish args
|
|
116
90
|
*/
|
|
117
91
|
export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
118
|
-
/**
|
|
119
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
120
|
-
*
|
|
121
|
-
* _only for static_
|
|
122
|
-
*
|
|
123
|
-
* _experimental decorators_
|
|
124
|
-
*/
|
|
125
|
-
export declare function publicStaticRendererEvent(): PropertyDecorator;
|
|
126
|
-
/**
|
|
127
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
128
|
-
*
|
|
129
|
-
* _only for static_
|
|
130
|
-
*
|
|
131
|
-
* _experimental decorators_
|
|
132
|
-
* @param name - name by which the event will be accessed
|
|
133
|
-
*/
|
|
134
|
-
export declare function publicStaticRendererEvent(name: string): PropertyDecorator;
|
|
135
|
-
/**
|
|
136
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
137
|
-
*
|
|
138
|
-
* _only for static_
|
|
139
|
-
*
|
|
140
|
-
* _experimental decorators_
|
|
141
|
-
* @param receiver - linked receiver
|
|
142
|
-
*/
|
|
143
|
-
export declare function publicStaticRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
144
|
-
/**
|
|
145
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
146
|
-
*
|
|
147
|
-
* _only for static_
|
|
148
|
-
*
|
|
149
|
-
* _experimental decorators_
|
|
150
|
-
* @param name - name by which the event will be accessed
|
|
151
|
-
* @param receiver - linked receiver
|
|
152
|
-
*/
|
|
153
|
-
export declare function publicStaticRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
|
|
154
|
-
/**
|
|
155
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
156
|
-
*
|
|
157
|
-
* _only for static_
|
|
158
|
-
*
|
|
159
|
-
* _experimental decorators_
|
|
160
|
-
* @param args - publish args
|
|
161
|
-
*/
|
|
162
|
-
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
163
|
-
/**
|
|
164
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
165
|
-
*
|
|
166
|
-
* _only for static_
|
|
167
|
-
*
|
|
168
|
-
* _experimental decorators_
|
|
169
|
-
* @param args - publish args
|
|
170
|
-
*/
|
|
171
|
-
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
172
92
|
/**
|
|
173
93
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
174
94
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.
|
|
3
|
+
exports.providePublic = exports.publicProperty = exports.publicStaticProperty = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.publicMethod = exports.publicStaticMethod = void 0;
|
|
4
4
|
const publish_1 = require("./publish");
|
|
5
5
|
function publicStaticMethod(arg) {
|
|
6
6
|
return (target, key) => {
|
|
@@ -30,63 +30,51 @@ function publicMethod(arg) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
exports.publicMethod = publicMethod;
|
|
33
|
-
function publicStaticMainEvent(arg) {
|
|
34
|
-
return (target, key) => {
|
|
35
|
-
let name = String(key);
|
|
36
|
-
if (arg) {
|
|
37
|
-
if (typeof arg === 'string') {
|
|
38
|
-
name = arg;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
name = arg.name ?? String(key);
|
|
42
|
-
if (arg.scope)
|
|
43
|
-
(0, publish_1.addScope)(name, arg.scope);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
target[key] = (0, publish_1.publicMainEvent)(name, target[key].bind(target));
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
exports.publicStaticMainEvent = publicStaticMainEvent;
|
|
50
33
|
function publicClassMainEvent(arg) {
|
|
51
34
|
return (tgt, key, _) => {
|
|
52
35
|
const target = tgt;
|
|
53
36
|
const prevRegister = target.__register__ ?? (() => { });
|
|
54
37
|
target.__register__ = instance => {
|
|
55
38
|
prevRegister(instance);
|
|
56
|
-
|
|
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_1.addScope)(name, arg.scope);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
instance[key] = (0, publish_1.publicMainEvent)(name, instance[key].bind(instance));
|
|
57
51
|
};
|
|
58
52
|
};
|
|
59
53
|
}
|
|
60
54
|
exports.publicClassMainEvent = publicClassMainEvent;
|
|
61
|
-
function publicStaticRendererEvent(arg) {
|
|
62
|
-
return (target, key) => {
|
|
63
|
-
let name = String(key);
|
|
64
|
-
let receiver = (v) => v;
|
|
65
|
-
if (arg) {
|
|
66
|
-
if (typeof arg === 'string') {
|
|
67
|
-
name = arg;
|
|
68
|
-
}
|
|
69
|
-
else if (typeof arg === 'object') {
|
|
70
|
-
name = arg.name ?? String(key);
|
|
71
|
-
receiver = arg.receiver ?? receiver;
|
|
72
|
-
if (arg.scope)
|
|
73
|
-
(0, publish_1.addScope)(name, arg.scope);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
receiver = arg;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
target[key] = (0, publish_1.publicRendererEvent)(name, receiver);
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
exports.publicStaticRendererEvent = publicStaticRendererEvent;
|
|
83
55
|
function publicClassRendererEvent(arg) {
|
|
84
56
|
return (tgt, key) => {
|
|
85
57
|
const target = tgt;
|
|
86
58
|
const prevRegister = target.__register__ ?? (() => { });
|
|
87
59
|
target.__register__ = instance => {
|
|
88
60
|
prevRegister(instance);
|
|
89
|
-
|
|
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.receiver ?? receiver;
|
|
70
|
+
if (arg.scope)
|
|
71
|
+
(0, publish_1.addScope)(name, arg.scope);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
receiver = arg;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
instance[key] = (0, publish_1.publicRendererEvent)(name, receiver);
|
|
90
78
|
};
|
|
91
79
|
};
|
|
92
80
|
}
|
package/cjs/scripts/provider.js
CHANGED
|
@@ -7,153 +7,106 @@ function errorHandler(error, channel) {
|
|
|
7
7
|
function createProvider(args) {
|
|
8
8
|
const { info, scope, getVariable, setVariable, callFunction, handleMainEvent, waitPromise, emitRendererEvent } = args;
|
|
9
9
|
const target = {
|
|
10
|
-
as: () =>
|
|
10
|
+
as: () => target
|
|
11
11
|
};
|
|
12
|
+
function define(name, attrs) {
|
|
13
|
+
let descriptor;
|
|
14
|
+
if (!info.scopes.get(name).has(scope)) {
|
|
15
|
+
descriptor = {
|
|
16
|
+
get() { throw new Error(`'${name}' is not provided into ${scope} scope`); },
|
|
17
|
+
set() { throw new Error(`'${name}' is not provided into ${scope} scope`); }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else if (attrs?.value) {
|
|
21
|
+
descriptor = {
|
|
22
|
+
get: () => attrs.value,
|
|
23
|
+
set: () => { throw new Error(`'${name}' is readonly`); },
|
|
24
|
+
enumerable: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
descriptor = {
|
|
29
|
+
get: attrs?.get || (() => { throw new Error(`No access to getting '${name}'`); }),
|
|
30
|
+
set: attrs?.set || (() => { throw new Error(`'${name}' is readonly`); }),
|
|
31
|
+
enumerable: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(target, name, descriptor);
|
|
35
|
+
}
|
|
12
36
|
info.functions.forEach(funcName => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return waitPromise(result.promiseChannel);
|
|
25
|
-
return result.value;
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
set() {
|
|
29
|
-
throw new Error(`Function '${funcName}' is readonly`);
|
|
30
|
-
},
|
|
31
|
-
enumerable: true
|
|
37
|
+
define(funcName, {
|
|
38
|
+
value(...args) {
|
|
39
|
+
const result = callFunction(funcName, ...args);
|
|
40
|
+
if (result.error) {
|
|
41
|
+
errorHandler(result.error, funcName);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (result.promiseChannel)
|
|
45
|
+
return waitPromise(result.promiseChannel);
|
|
46
|
+
return result.value;
|
|
47
|
+
}
|
|
32
48
|
});
|
|
33
49
|
});
|
|
34
|
-
info.rendererEvents.forEach(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return (arg) => emitRendererEvent(rendererEventName, arg);
|
|
40
|
-
},
|
|
41
|
-
set() {
|
|
42
|
-
throw new Error(`Function '${rendererEventName}' is readonly`);
|
|
43
|
-
},
|
|
44
|
-
enumerable: true
|
|
50
|
+
info.rendererEvents.forEach(eventName => {
|
|
51
|
+
define(eventName, {
|
|
52
|
+
value(arg) {
|
|
53
|
+
emitRendererEvent(eventName, arg);
|
|
54
|
+
}
|
|
45
55
|
});
|
|
46
56
|
});
|
|
47
57
|
info.mainEvents.forEach(mainEventName => {
|
|
48
|
-
if (!info.scopes[mainEventName].has(scope))
|
|
49
|
-
return;
|
|
50
58
|
const eventNameOn = `on${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
51
59
|
const eventNameOnce = `once${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
set() {
|
|
67
|
-
throw new Error(`Function '${eventNameOn}' is readonly`);
|
|
68
|
-
},
|
|
69
|
-
enumerable: true
|
|
60
|
+
define(eventNameOn, {
|
|
61
|
+
value(handler) {
|
|
62
|
+
return handleMainEvent(mainEventName, 'on', (result) => {
|
|
63
|
+
if (result.error) {
|
|
64
|
+
errorHandler(result.error, mainEventName);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (result.promiseChannel)
|
|
68
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
69
|
+
handler(result.value);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
70
72
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
set() {
|
|
86
|
-
throw new Error(`Function '${eventNameOnce}' is readonly`);
|
|
87
|
-
},
|
|
88
|
-
enumerable: true
|
|
73
|
+
define(eventNameOnce, {
|
|
74
|
+
value(handler) {
|
|
75
|
+
return handleMainEvent(mainEventName, 'once', (result) => {
|
|
76
|
+
if (result.error) {
|
|
77
|
+
errorHandler(result.error, mainEventName);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (result.promiseChannel)
|
|
81
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
82
|
+
handler(result.value);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
89
85
|
});
|
|
90
86
|
});
|
|
91
87
|
info.properties.forEach(propName => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
setter = () => { throw new Error(`No access to setting the '${propName}' property`); };
|
|
113
|
-
Object.defineProperty(target, propName, {
|
|
114
|
-
get: getter,
|
|
115
|
-
set: setter,
|
|
116
|
-
enumerable: true
|
|
88
|
+
define(propName, {
|
|
89
|
+
get: info.accesses.get(propName).has(enums_1.Access.get)
|
|
90
|
+
? () => {
|
|
91
|
+
const result = getVariable(propName);
|
|
92
|
+
if (result.error) {
|
|
93
|
+
errorHandler(result.error, propName);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
return result.value;
|
|
97
|
+
}
|
|
98
|
+
: () => { throw new Error(`No access to getting the '${propName}' property`); },
|
|
99
|
+
set: info.accesses.get(propName).has(enums_1.Access.set)
|
|
100
|
+
? (value) => {
|
|
101
|
+
const result = setVariable(propName, value);
|
|
102
|
+
if (result?.error) {
|
|
103
|
+
errorHandler(result.error, propName);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
: () => { throw new Error(`No access to setting the '${propName}' property`); }
|
|
117
108
|
});
|
|
118
109
|
});
|
|
119
|
-
|
|
120
|
-
get(target, key) {
|
|
121
|
-
if (key in target)
|
|
122
|
-
return target[key];
|
|
123
|
-
const isFunction = info.functions.has(key);
|
|
124
|
-
const isProperty = info.properties.has(key);
|
|
125
|
-
if (!isFunction && !isProperty)
|
|
126
|
-
throw new Error(`'${key}' is not provided from main`);
|
|
127
|
-
if (!info.scopes[key].has(enums_1.Scope.renderer))
|
|
128
|
-
throw new Error(`'${key}' is not provided into renderer scope`);
|
|
129
|
-
if (isProperty && !info.accesses[key].has(enums_1.Access.get))
|
|
130
|
-
throw new Error(`No access to getting the '${key}' property`);
|
|
131
|
-
throw new Error(`Unknown error on get '${key}'`);
|
|
132
|
-
},
|
|
133
|
-
set(target, key, newValue) {
|
|
134
|
-
if (key in target) {
|
|
135
|
-
target[key] = newValue;
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
const isFunction = info.functions.has(key);
|
|
139
|
-
const isProperty = info.properties.has(key);
|
|
140
|
-
if (isFunction)
|
|
141
|
-
throw new Error(`Function '${key}' is readonly`);
|
|
142
|
-
if (!isProperty)
|
|
143
|
-
throw new Error(`Property '${key}' is not provided from main`);
|
|
144
|
-
if (!info.scopes[key].has(enums_1.Scope.renderer))
|
|
145
|
-
throw new Error(`'${key}' is not provided into renderer scope`);
|
|
146
|
-
if (!info.accesses[key].has(enums_1.Access.set))
|
|
147
|
-
throw new Error(`No access to setting the '${key}' property`);
|
|
148
|
-
throw new Error(`Unknown error on set '${key}'`);
|
|
149
|
-
},
|
|
150
|
-
ownKeys(target) {
|
|
151
|
-
return Object.keys(target);
|
|
152
|
-
},
|
|
153
|
-
has(target, key) {
|
|
154
|
-
return key in target;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return proxy;
|
|
110
|
+
return target;
|
|
158
111
|
}
|
|
159
112
|
exports.default = createProvider;
|
package/cjs/scripts/publish.js
CHANGED
|
@@ -8,8 +8,8 @@ const publicInfo = {
|
|
|
8
8
|
functions: new Set(),
|
|
9
9
|
mainEvents: new Set(),
|
|
10
10
|
rendererEvents: new Set(),
|
|
11
|
-
accesses:
|
|
12
|
-
scopes:
|
|
11
|
+
accesses: new Map(),
|
|
12
|
+
scopes: new Map()
|
|
13
13
|
};
|
|
14
14
|
electron_1.ipcMain.on(enums_1.IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
15
15
|
/**
|
|
@@ -26,8 +26,12 @@ function publicMainEvent(name, receiver = ((v = undefined) => v), scopes = [enum
|
|
|
26
26
|
let senders = [];
|
|
27
27
|
let sendersOnce = [];
|
|
28
28
|
mainEvents.add(name);
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const rendererNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
30
|
+
const rendererNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
|
|
31
|
+
if (!publicInfo.scopes.has(rendererNameOn)) {
|
|
32
|
+
publicInfo.scopes.set(rendererNameOn, new Set(scopes));
|
|
33
|
+
publicInfo.scopes.set(rendererNameOnce, new Set(scopes));
|
|
34
|
+
}
|
|
31
35
|
electron_1.ipcMain.removeAllListeners(mainHandleChannel);
|
|
32
36
|
electron_1.ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
33
37
|
electron_1.ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
@@ -82,8 +86,8 @@ function publicRendererEvent(name, receiver = ((v = undefined) => v), scopes = [
|
|
|
82
86
|
const handlers = new Set();
|
|
83
87
|
const handlersOnce = new Set();
|
|
84
88
|
rendererEvents.add(name);
|
|
85
|
-
if (!publicInfo.scopes
|
|
86
|
-
publicInfo.scopes
|
|
89
|
+
if (!publicInfo.scopes.has(name))
|
|
90
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
87
91
|
electron_1.ipcMain.removeAllListeners(rendererEmitChannel);
|
|
88
92
|
electron_1.ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
89
93
|
if (result.error)
|
|
@@ -117,8 +121,8 @@ function publicFunction(name, func, scopes = [enums_1.Scope.preload, enums_1.Sco
|
|
|
117
121
|
const { functions } = publicInfo;
|
|
118
122
|
const channel = enums_1.IPCChannel.functionCall + name;
|
|
119
123
|
functions.add(name);
|
|
120
|
-
if (!publicInfo.scopes
|
|
121
|
-
publicInfo.scopes
|
|
124
|
+
if (!publicInfo.scopes.has(name))
|
|
125
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
122
126
|
electron_1.ipcMain.removeAllListeners(channel);
|
|
123
127
|
electron_1.ipcMain.on(channel, (e, ...args) => {
|
|
124
128
|
try {
|
|
@@ -154,16 +158,16 @@ function publicVariable(name, value, scopes = [enums_1.Scope.renderer, enums_1.S
|
|
|
154
158
|
const setChannel = enums_1.IPCChannel.propertySet + name;
|
|
155
159
|
const { get: getter, set: setter } = value;
|
|
156
160
|
properties.add(name);
|
|
157
|
-
if (!publicInfo.scopes
|
|
158
|
-
publicInfo.scopes
|
|
159
|
-
if (!publicInfo.accesses
|
|
161
|
+
if (!publicInfo.scopes.has(name))
|
|
162
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
163
|
+
if (!publicInfo.accesses.has(name)) {
|
|
160
164
|
const accesses = [];
|
|
161
165
|
getter && accesses.push(enums_1.Access.get);
|
|
162
166
|
setter && accesses.push(enums_1.Access.set);
|
|
163
|
-
publicInfo.accesses
|
|
167
|
+
publicInfo.accesses.set(name, new Set(accesses));
|
|
164
168
|
}
|
|
165
169
|
else {
|
|
166
|
-
const accesses = publicInfo.accesses
|
|
170
|
+
const accesses = publicInfo.accesses.get(name);
|
|
167
171
|
getter && accesses.add(enums_1.Access.get);
|
|
168
172
|
setter && accesses.add(enums_1.Access.set);
|
|
169
173
|
}
|
|
@@ -194,10 +198,10 @@ function publicVariable(name, value, scopes = [enums_1.Scope.renderer, enums_1.S
|
|
|
194
198
|
}
|
|
195
199
|
exports.publicVariable = publicVariable;
|
|
196
200
|
function addScope(key, scope) {
|
|
197
|
-
publicInfo.scopes
|
|
201
|
+
publicInfo.scopes.set(key, new Set([scope]));
|
|
198
202
|
}
|
|
199
203
|
exports.addScope = addScope;
|
|
200
204
|
function addAccess(key, access) {
|
|
201
|
-
publicInfo.accesses
|
|
205
|
+
publicInfo.accesses.set(key, new Set([access]));
|
|
202
206
|
}
|
|
203
207
|
exports.addAccess = addAccess;
|
package/cjs/types.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export interface ICreateProviderArgs {
|
|
|
42
42
|
setVariable(name: string, value: any): IIPCResult | undefined;
|
|
43
43
|
waitPromise(channel: string): Promise<any>;
|
|
44
44
|
}
|
|
45
|
-
export type Scopes =
|
|
46
|
-
export type Accesses =
|
|
45
|
+
export type Scopes = Map<string, Set<Scope>>;
|
|
46
|
+
export type Accesses = Map<string, Set<Access>>;
|
|
47
47
|
export type RendererEvent<T = undefined> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
48
48
|
export type MainEvent<T = undefined> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
49
49
|
export type EventEmitter = (...args: any[]) => any;
|
package/esm/exp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty,
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/oldDecorators';
|
|
3
3
|
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
4
|
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/esm/exp.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty,
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMethod, publicStaticProperty } from './scripts/oldDecorators';
|
|
3
3
|
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
package/esm/scripts/Bridge.js
CHANGED
|
@@ -10,8 +10,7 @@ const info = provider.getInfo();
|
|
|
10
10
|
* _only for renderer process_
|
|
11
11
|
*/
|
|
12
12
|
const Bridge = createProvider({
|
|
13
|
-
info,
|
|
14
|
-
scope: Scope.renderer,
|
|
13
|
+
info, scope: Scope.renderer,
|
|
15
14
|
callFunction(name, ...args) {
|
|
16
15
|
return provider.provided.functions[name](...args);
|
|
17
16
|
},
|
package/esm/scripts/Main.js
CHANGED
|
@@ -10,8 +10,7 @@ if (!info)
|
|
|
10
10
|
* _only for preload process_
|
|
11
11
|
*/
|
|
12
12
|
const Main = createProvider({
|
|
13
|
-
info,
|
|
14
|
-
scope: Scope.preload,
|
|
13
|
+
info, scope: Scope.preload,
|
|
15
14
|
callFunction(name, ...args) {
|
|
16
15
|
return ipcRenderer.sendSync(IPCChannel.functionCall + name, ...args);
|
|
17
16
|
},
|
|
@@ -79,11 +79,11 @@ export function publicProperty(arg) {
|
|
|
79
79
|
context.addInitializer(function () {
|
|
80
80
|
publicVariable(name, {
|
|
81
81
|
get: () => {
|
|
82
|
-
// @ts-
|
|
82
|
+
// @ts-expect-error
|
|
83
83
|
return this[key];
|
|
84
84
|
},
|
|
85
85
|
set: (value) => {
|
|
86
|
-
// @ts-
|
|
86
|
+
// @ts-expect-error
|
|
87
87
|
this[key] = value;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
@@ -57,32 +57,6 @@ export declare function publicMethod(name: string): MethodDecorator;
|
|
|
57
57
|
* @param args - publish args
|
|
58
58
|
*/
|
|
59
59
|
export declare function publicMethod(args: IPublishMethodArgs): MethodDecorator;
|
|
60
|
-
/**
|
|
61
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
62
|
-
*
|
|
63
|
-
* _only for static_
|
|
64
|
-
*
|
|
65
|
-
* _experimental decorators_
|
|
66
|
-
*/
|
|
67
|
-
export declare function publicStaticMainEvent(): MethodDecorator;
|
|
68
|
-
/**
|
|
69
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
70
|
-
*
|
|
71
|
-
* _only for static_
|
|
72
|
-
*
|
|
73
|
-
* _experimental decorators_
|
|
74
|
-
* @param name - name by which the event will be accessed
|
|
75
|
-
*/
|
|
76
|
-
export declare function publicStaticMainEvent(name: string): MethodDecorator;
|
|
77
|
-
/**
|
|
78
|
-
* Makes the event available for **renderer** and **preload** processes.
|
|
79
|
-
*
|
|
80
|
-
* _only for static_
|
|
81
|
-
*
|
|
82
|
-
* _experimental decorators_
|
|
83
|
-
* @param args - publish args
|
|
84
|
-
*/
|
|
85
|
-
export declare function publicStaticMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
86
60
|
/**
|
|
87
61
|
* Makes the event available for **renderer** and **preload** processes.
|
|
88
62
|
*
|
|
@@ -115,60 +89,6 @@ export declare function publicClassMainEvent(name: string): MethodDecorator;
|
|
|
115
89
|
* @param args - publish args
|
|
116
90
|
*/
|
|
117
91
|
export declare function publicClassMainEvent(args: IPublishMainEventArgs): MethodDecorator;
|
|
118
|
-
/**
|
|
119
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
120
|
-
*
|
|
121
|
-
* _only for static_
|
|
122
|
-
*
|
|
123
|
-
* _experimental decorators_
|
|
124
|
-
*/
|
|
125
|
-
export declare function publicStaticRendererEvent(): PropertyDecorator;
|
|
126
|
-
/**
|
|
127
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
128
|
-
*
|
|
129
|
-
* _only for static_
|
|
130
|
-
*
|
|
131
|
-
* _experimental decorators_
|
|
132
|
-
* @param name - name by which the event will be accessed
|
|
133
|
-
*/
|
|
134
|
-
export declare function publicStaticRendererEvent(name: string): PropertyDecorator;
|
|
135
|
-
/**
|
|
136
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
137
|
-
*
|
|
138
|
-
* _only for static_
|
|
139
|
-
*
|
|
140
|
-
* _experimental decorators_
|
|
141
|
-
* @param receiver - linked receiver
|
|
142
|
-
*/
|
|
143
|
-
export declare function publicStaticRendererEvent(receiver: EventReceiver): PropertyDecorator;
|
|
144
|
-
/**
|
|
145
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
146
|
-
*
|
|
147
|
-
* _only for static_
|
|
148
|
-
*
|
|
149
|
-
* _experimental decorators_
|
|
150
|
-
* @param name - name by which the event will be accessed
|
|
151
|
-
* @param receiver - linked receiver
|
|
152
|
-
*/
|
|
153
|
-
export declare function publicStaticRendererEvent(name: string, receiver: EventReceiver): PropertyDecorator;
|
|
154
|
-
/**
|
|
155
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
156
|
-
*
|
|
157
|
-
* _only for static_
|
|
158
|
-
*
|
|
159
|
-
* _experimental decorators_
|
|
160
|
-
* @param args - publish args
|
|
161
|
-
*/
|
|
162
|
-
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
163
|
-
/**
|
|
164
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
165
|
-
*
|
|
166
|
-
* _only for static_
|
|
167
|
-
*
|
|
168
|
-
* _experimental decorators_
|
|
169
|
-
* @param args - publish args
|
|
170
|
-
*/
|
|
171
|
-
export declare function publicStaticRendererEvent(args: IPublishRendererEventArgs): PropertyDecorator;
|
|
172
92
|
/**
|
|
173
93
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
174
94
|
*
|
|
@@ -25,51 +25,25 @@ export function publicMethod(arg) {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
export function publicStaticMainEvent(arg) {
|
|
29
|
-
return (target, key) => {
|
|
30
|
-
let name = String(key);
|
|
31
|
-
if (arg) {
|
|
32
|
-
if (typeof arg === 'string') {
|
|
33
|
-
name = arg;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
name = arg.name ?? String(key);
|
|
37
|
-
if (arg.scope)
|
|
38
|
-
addScope(name, arg.scope);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
target[key] = publicMainEvent(name, target[key].bind(target));
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
28
|
export function publicClassMainEvent(arg) {
|
|
45
29
|
return (tgt, key, _) => {
|
|
46
30
|
const target = tgt;
|
|
47
31
|
const prevRegister = target.__register__ ?? (() => { });
|
|
48
32
|
target.__register__ = instance => {
|
|
49
33
|
prevRegister(instance);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
name = arg;
|
|
34
|
+
let name = String(key);
|
|
35
|
+
if (arg) {
|
|
36
|
+
if (typeof arg === 'string') {
|
|
37
|
+
name = arg;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
name = arg.name ?? String(key);
|
|
41
|
+
if (arg.scope)
|
|
42
|
+
addScope(name, arg.scope);
|
|
43
|
+
}
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
receiver = arg.receiver ?? receiver;
|
|
65
|
-
if (arg.scope)
|
|
66
|
-
addScope(name, arg.scope);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
receiver = arg;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
target[key] = publicRendererEvent(name, receiver);
|
|
45
|
+
instance[key] = publicMainEvent(name, instance[key].bind(instance));
|
|
46
|
+
};
|
|
73
47
|
};
|
|
74
48
|
}
|
|
75
49
|
export function publicClassRendererEvent(arg) {
|
|
@@ -78,7 +52,23 @@ export function publicClassRendererEvent(arg) {
|
|
|
78
52
|
const prevRegister = target.__register__ ?? (() => { });
|
|
79
53
|
target.__register__ = instance => {
|
|
80
54
|
prevRegister(instance);
|
|
81
|
-
|
|
55
|
+
let name = String(key);
|
|
56
|
+
let receiver = (v) => v;
|
|
57
|
+
if (arg) {
|
|
58
|
+
if (typeof arg === 'string') {
|
|
59
|
+
name = arg;
|
|
60
|
+
}
|
|
61
|
+
else if (typeof arg === 'object') {
|
|
62
|
+
name = arg.name ?? String(key);
|
|
63
|
+
receiver = arg.receiver ?? receiver;
|
|
64
|
+
if (arg.scope)
|
|
65
|
+
addScope(name, arg.scope);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
receiver = arg;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
instance[key] = publicRendererEvent(name, receiver);
|
|
82
72
|
};
|
|
83
73
|
};
|
|
84
74
|
}
|
package/esm/scripts/provider.js
CHANGED
|
@@ -1,157 +1,110 @@
|
|
|
1
|
-
import { Access
|
|
1
|
+
import { Access } from '../enums';
|
|
2
2
|
function errorHandler(error, channel) {
|
|
3
3
|
console.error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
|
|
4
4
|
}
|
|
5
5
|
function createProvider(args) {
|
|
6
6
|
const { info, scope, getVariable, setVariable, callFunction, handleMainEvent, waitPromise, emitRendererEvent } = args;
|
|
7
7
|
const target = {
|
|
8
|
-
as: () =>
|
|
8
|
+
as: () => target
|
|
9
9
|
};
|
|
10
|
+
function define(name, attrs) {
|
|
11
|
+
let descriptor;
|
|
12
|
+
if (!info.scopes.get(name).has(scope)) {
|
|
13
|
+
descriptor = {
|
|
14
|
+
get() { throw new Error(`'${name}' is not provided into ${scope} scope`); },
|
|
15
|
+
set() { throw new Error(`'${name}' is not provided into ${scope} scope`); }
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else if (attrs?.value) {
|
|
19
|
+
descriptor = {
|
|
20
|
+
get: () => attrs.value,
|
|
21
|
+
set: () => { throw new Error(`'${name}' is readonly`); },
|
|
22
|
+
enumerable: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
descriptor = {
|
|
27
|
+
get: attrs?.get || (() => { throw new Error(`No access to getting '${name}'`); }),
|
|
28
|
+
set: attrs?.set || (() => { throw new Error(`'${name}' is readonly`); }),
|
|
29
|
+
enumerable: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(target, name, descriptor);
|
|
33
|
+
}
|
|
10
34
|
info.functions.forEach(funcName => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return waitPromise(result.promiseChannel);
|
|
23
|
-
return result.value;
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
set() {
|
|
27
|
-
throw new Error(`Function '${funcName}' is readonly`);
|
|
28
|
-
},
|
|
29
|
-
enumerable: true
|
|
35
|
+
define(funcName, {
|
|
36
|
+
value(...args) {
|
|
37
|
+
const result = callFunction(funcName, ...args);
|
|
38
|
+
if (result.error) {
|
|
39
|
+
errorHandler(result.error, funcName);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (result.promiseChannel)
|
|
43
|
+
return waitPromise(result.promiseChannel);
|
|
44
|
+
return result.value;
|
|
45
|
+
}
|
|
30
46
|
});
|
|
31
47
|
});
|
|
32
|
-
info.rendererEvents.forEach(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return (arg) => emitRendererEvent(rendererEventName, arg);
|
|
38
|
-
},
|
|
39
|
-
set() {
|
|
40
|
-
throw new Error(`Function '${rendererEventName}' is readonly`);
|
|
41
|
-
},
|
|
42
|
-
enumerable: true
|
|
48
|
+
info.rendererEvents.forEach(eventName => {
|
|
49
|
+
define(eventName, {
|
|
50
|
+
value(arg) {
|
|
51
|
+
emitRendererEvent(eventName, arg);
|
|
52
|
+
}
|
|
43
53
|
});
|
|
44
54
|
});
|
|
45
55
|
info.mainEvents.forEach(mainEventName => {
|
|
46
|
-
if (!info.scopes[mainEventName].has(scope))
|
|
47
|
-
return;
|
|
48
56
|
const eventNameOn = `on${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
49
57
|
const eventNameOnce = `once${mainEventName[0].toUpperCase()}${mainEventName.slice(1)}`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
set() {
|
|
65
|
-
throw new Error(`Function '${eventNameOn}' is readonly`);
|
|
66
|
-
},
|
|
67
|
-
enumerable: true
|
|
58
|
+
define(eventNameOn, {
|
|
59
|
+
value(handler) {
|
|
60
|
+
return handleMainEvent(mainEventName, 'on', (result) => {
|
|
61
|
+
if (result.error) {
|
|
62
|
+
errorHandler(result.error, mainEventName);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (result.promiseChannel)
|
|
66
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
67
|
+
handler(result.value);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
68
70
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
set() {
|
|
84
|
-
throw new Error(`Function '${eventNameOnce}' is readonly`);
|
|
85
|
-
},
|
|
86
|
-
enumerable: true
|
|
71
|
+
define(eventNameOnce, {
|
|
72
|
+
value(handler) {
|
|
73
|
+
return handleMainEvent(mainEventName, 'once', (result) => {
|
|
74
|
+
if (result.error) {
|
|
75
|
+
errorHandler(result.error, mainEventName);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (result.promiseChannel)
|
|
79
|
+
waitPromise(result.promiseChannel).then(handler);
|
|
80
|
+
handler(result.value);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
87
83
|
});
|
|
88
84
|
});
|
|
89
85
|
info.properties.forEach(propName => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
setter = () => { throw new Error(`No access to setting the '${propName}' property`); };
|
|
111
|
-
Object.defineProperty(target, propName, {
|
|
112
|
-
get: getter,
|
|
113
|
-
set: setter,
|
|
114
|
-
enumerable: true
|
|
86
|
+
define(propName, {
|
|
87
|
+
get: info.accesses.get(propName).has(Access.get)
|
|
88
|
+
? () => {
|
|
89
|
+
const result = getVariable(propName);
|
|
90
|
+
if (result.error) {
|
|
91
|
+
errorHandler(result.error, propName);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return result.value;
|
|
95
|
+
}
|
|
96
|
+
: () => { throw new Error(`No access to getting the '${propName}' property`); },
|
|
97
|
+
set: info.accesses.get(propName).has(Access.set)
|
|
98
|
+
? (value) => {
|
|
99
|
+
const result = setVariable(propName, value);
|
|
100
|
+
if (result?.error) {
|
|
101
|
+
errorHandler(result.error, propName);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
: () => { throw new Error(`No access to setting the '${propName}' property`); }
|
|
115
106
|
});
|
|
116
107
|
});
|
|
117
|
-
|
|
118
|
-
get(target, key) {
|
|
119
|
-
if (key in target)
|
|
120
|
-
return target[key];
|
|
121
|
-
const isFunction = info.functions.has(key);
|
|
122
|
-
const isProperty = info.properties.has(key);
|
|
123
|
-
if (!isFunction && !isProperty)
|
|
124
|
-
throw new Error(`'${key}' is not provided from main`);
|
|
125
|
-
if (!info.scopes[key].has(Scope.renderer))
|
|
126
|
-
throw new Error(`'${key}' is not provided into renderer scope`);
|
|
127
|
-
if (isProperty && !info.accesses[key].has(Access.get))
|
|
128
|
-
throw new Error(`No access to getting the '${key}' property`);
|
|
129
|
-
throw new Error(`Unknown error on get '${key}'`);
|
|
130
|
-
},
|
|
131
|
-
set(target, key, newValue) {
|
|
132
|
-
if (key in target) {
|
|
133
|
-
target[key] = newValue;
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
const isFunction = info.functions.has(key);
|
|
137
|
-
const isProperty = info.properties.has(key);
|
|
138
|
-
if (isFunction)
|
|
139
|
-
throw new Error(`Function '${key}' is readonly`);
|
|
140
|
-
if (!isProperty)
|
|
141
|
-
throw new Error(`Property '${key}' is not provided from main`);
|
|
142
|
-
if (!info.scopes[key].has(Scope.renderer))
|
|
143
|
-
throw new Error(`'${key}' is not provided into renderer scope`);
|
|
144
|
-
if (!info.accesses[key].has(Access.set))
|
|
145
|
-
throw new Error(`No access to setting the '${key}' property`);
|
|
146
|
-
throw new Error(`Unknown error on set '${key}'`);
|
|
147
|
-
},
|
|
148
|
-
ownKeys(target) {
|
|
149
|
-
return Object.keys(target);
|
|
150
|
-
},
|
|
151
|
-
has(target, key) {
|
|
152
|
-
return key in target;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return proxy;
|
|
108
|
+
return target;
|
|
156
109
|
}
|
|
157
110
|
export default createProvider;
|
package/esm/scripts/publish.js
CHANGED
|
@@ -5,8 +5,8 @@ const publicInfo = {
|
|
|
5
5
|
functions: new Set(),
|
|
6
6
|
mainEvents: new Set(),
|
|
7
7
|
rendererEvents: new Set(),
|
|
8
|
-
accesses:
|
|
9
|
-
scopes:
|
|
8
|
+
accesses: new Map(),
|
|
9
|
+
scopes: new Map()
|
|
10
10
|
};
|
|
11
11
|
ipcMain.on(IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
12
12
|
/**
|
|
@@ -23,8 +23,12 @@ export function publicMainEvent(name, receiver = ((v = undefined) => v), scopes
|
|
|
23
23
|
let senders = [];
|
|
24
24
|
let sendersOnce = [];
|
|
25
25
|
mainEvents.add(name);
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const rendererNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
27
|
+
const rendererNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
|
|
28
|
+
if (!publicInfo.scopes.has(rendererNameOn)) {
|
|
29
|
+
publicInfo.scopes.set(rendererNameOn, new Set(scopes));
|
|
30
|
+
publicInfo.scopes.set(rendererNameOnce, new Set(scopes));
|
|
31
|
+
}
|
|
28
32
|
ipcMain.removeAllListeners(mainHandleChannel);
|
|
29
33
|
ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
30
34
|
ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
@@ -78,8 +82,8 @@ export function publicRendererEvent(name, receiver = ((v = undefined) => v), sco
|
|
|
78
82
|
const handlers = new Set();
|
|
79
83
|
const handlersOnce = new Set();
|
|
80
84
|
rendererEvents.add(name);
|
|
81
|
-
if (!publicInfo.scopes
|
|
82
|
-
publicInfo.scopes
|
|
85
|
+
if (!publicInfo.scopes.has(name))
|
|
86
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
83
87
|
ipcMain.removeAllListeners(rendererEmitChannel);
|
|
84
88
|
ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
85
89
|
if (result.error)
|
|
@@ -112,8 +116,8 @@ export function publicFunction(name, func, scopes = [Scope.preload, Scope.render
|
|
|
112
116
|
const { functions } = publicInfo;
|
|
113
117
|
const channel = IPCChannel.functionCall + name;
|
|
114
118
|
functions.add(name);
|
|
115
|
-
if (!publicInfo.scopes
|
|
116
|
-
publicInfo.scopes
|
|
119
|
+
if (!publicInfo.scopes.has(name))
|
|
120
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
117
121
|
ipcMain.removeAllListeners(channel);
|
|
118
122
|
ipcMain.on(channel, (e, ...args) => {
|
|
119
123
|
try {
|
|
@@ -148,16 +152,16 @@ export function publicVariable(name, value, scopes = [Scope.renderer, Scope.prel
|
|
|
148
152
|
const setChannel = IPCChannel.propertySet + name;
|
|
149
153
|
const { get: getter, set: setter } = value;
|
|
150
154
|
properties.add(name);
|
|
151
|
-
if (!publicInfo.scopes
|
|
152
|
-
publicInfo.scopes
|
|
153
|
-
if (!publicInfo.accesses
|
|
155
|
+
if (!publicInfo.scopes.has(name))
|
|
156
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
157
|
+
if (!publicInfo.accesses.has(name)) {
|
|
154
158
|
const accesses = [];
|
|
155
159
|
getter && accesses.push(Access.get);
|
|
156
160
|
setter && accesses.push(Access.set);
|
|
157
|
-
publicInfo.accesses
|
|
161
|
+
publicInfo.accesses.set(name, new Set(accesses));
|
|
158
162
|
}
|
|
159
163
|
else {
|
|
160
|
-
const accesses = publicInfo.accesses
|
|
164
|
+
const accesses = publicInfo.accesses.get(name);
|
|
161
165
|
getter && accesses.add(Access.get);
|
|
162
166
|
setter && accesses.add(Access.set);
|
|
163
167
|
}
|
|
@@ -187,8 +191,8 @@ export function publicVariable(name, value, scopes = [Scope.renderer, Scope.prel
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
export function addScope(key, scope) {
|
|
190
|
-
publicInfo.scopes
|
|
194
|
+
publicInfo.scopes.set(key, new Set([scope]));
|
|
191
195
|
}
|
|
192
196
|
export function addAccess(key, access) {
|
|
193
|
-
publicInfo.accesses
|
|
197
|
+
publicInfo.accesses.set(key, new Set([access]));
|
|
194
198
|
}
|
package/esm/types.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export interface ICreateProviderArgs {
|
|
|
42
42
|
setVariable(name: string, value: any): IIPCResult | undefined;
|
|
43
43
|
waitPromise(channel: string): Promise<any>;
|
|
44
44
|
}
|
|
45
|
-
export type Scopes =
|
|
46
|
-
export type Accesses =
|
|
45
|
+
export type Scopes = Map<string, Set<Scope>>;
|
|
46
|
+
export type Accesses = Map<string, Set<Access>>;
|
|
47
47
|
export type RendererEvent<T = undefined> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
48
48
|
export type MainEvent<T = undefined> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
49
49
|
export type EventEmitter = (...args: any[]) => any;
|