emr-bridge 1.4.1 → 1.6.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/README.md +20 -20
- package/cjs/enums.js +3 -3
- package/cjs/exp.d.ts +1 -1
- package/cjs/exp.js +1 -3
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +16 -0
- package/cjs/main.d.ts +4 -0
- package/cjs/main.js +18 -0
- package/cjs/scripts/Bridge.d.ts +2 -1
- package/cjs/scripts/Bridge.js +44 -28
- package/cjs/scripts/Main.d.ts +2 -1
- package/cjs/scripts/Main.js +71 -52
- package/cjs/scripts/newDecorators.d.ts +13 -6
- package/cjs/scripts/newDecorators.js +3 -3
- package/cjs/scripts/oldDecorators.d.ts +13 -117
- package/cjs/scripts/oldDecorators.js +30 -42
- package/cjs/scripts/preloadProvider.js +29 -16
- package/cjs/scripts/provider.js +86 -133
- package/cjs/scripts/publish.d.ts +9 -5
- package/cjs/scripts/publish.js +59 -33
- package/cjs/types.d.ts +10 -10
- package/esm/exp.d.ts +1 -1
- package/esm/exp.js +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/main.d.ts +4 -0
- package/esm/main.js +3 -0
- package/esm/scripts/Bridge.d.ts +2 -1
- package/esm/scripts/Bridge.js +44 -28
- package/esm/scripts/Main.d.ts +2 -1
- package/esm/scripts/Main.js +71 -52
- package/esm/scripts/newDecorators.d.ts +13 -6
- package/esm/scripts/newDecorators.js +3 -3
- package/esm/scripts/oldDecorators.d.ts +13 -117
- package/esm/scripts/oldDecorators.js +29 -39
- package/esm/scripts/preloadProvider.js +13 -3
- package/esm/scripts/provider.js +87 -134
- package/esm/scripts/publish.d.ts +9 -5
- package/esm/scripts/publish.js +44 -21
- package/esm/types.d.ts +10 -10
- package/package.json +3 -35
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.d.ts
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
import { Access, Scope } from '../enums';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PublicFunction, PublicProperty, RendererEvent } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
5
5
|
*
|
|
6
6
|
* @param name - name by which the event will be accessed
|
|
7
|
+
* @param procFn - function of processing before sending the event
|
|
7
8
|
* @param scopes - event scopes
|
|
8
9
|
*/
|
|
9
|
-
export declare function publicMainEvent<
|
|
10
|
+
export declare function publicMainEvent<In = void, Out = In extends Array<any> ? In[0] : In, ProcFn extends (...args: any[]) => any = In extends Array<any> ? (...args: In) => Out : (val: In) => Out>(name: string, procFn?: ProcFn, scopes?: Scope[]): (...args: Parameters<ProcFn>) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
12
13
|
*
|
|
13
14
|
* @param name - name by which the event will be accessed
|
|
15
|
+
* @param procFn - processing function before calling handlers
|
|
14
16
|
* @param scopes - event scopes
|
|
15
17
|
*/
|
|
16
|
-
export declare function publicRendererEvent<
|
|
18
|
+
export declare function publicRendererEvent<In = void, Out = In, ProcFn extends (...args: any[]) => any = (v?: In) => Out>(name: string, procFn?: ProcFn, scopes?: Scope[]): RendererEvent<Out>;
|
|
17
19
|
/**
|
|
18
20
|
* Makes the function available for **renderer** and **preload** processes.
|
|
19
21
|
*
|
|
20
22
|
* _only for function_
|
|
23
|
+
*
|
|
21
24
|
* @param name - name by which the function will be accessed
|
|
22
25
|
* @param func - linked function
|
|
23
26
|
* @param scopes - function scopes
|
|
24
27
|
*/
|
|
25
|
-
export declare function publicFunction(name: string, func:
|
|
28
|
+
export declare function publicFunction<F extends PublicFunction>(name: string, func: F, scopes?: Scope[]): void;
|
|
26
29
|
/**
|
|
27
30
|
* Makes the function available for **renderer** and **preload** processes.
|
|
28
31
|
*
|
|
29
32
|
* _only for variables_
|
|
33
|
+
*
|
|
30
34
|
* @param name - name by which the variable will be accessed
|
|
31
35
|
* @param value - variable getter/setter
|
|
32
36
|
* @param scopes - variable scopes
|
|
33
37
|
*/
|
|
34
|
-
export declare function publicVariable(name: string, value: PublicProperty
|
|
38
|
+
export declare function publicVariable<T>(name: string, value: PublicProperty<T>, scopes?: Scope[]): void;
|
|
35
39
|
export declare function addScope(key: string, scope: Scope): void;
|
|
36
40
|
export declare function addAccess(key: string, access: Access): void;
|
package/cjs/scripts/publish.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.addAccess = exports.addScope = exports.publicVariable = exports.publicFunction = exports.publicRendererEvent = exports.publicMainEvent = void 0;
|
|
4
|
-
const electron_1 = require("electron");
|
|
7
|
+
const electron_1 = __importDefault(require("electron"));
|
|
5
8
|
const enums_1 = require("../enums");
|
|
6
9
|
const publicInfo = {
|
|
7
10
|
properties: new Set(),
|
|
8
11
|
functions: new Set(),
|
|
9
12
|
mainEvents: new Set(),
|
|
10
13
|
rendererEvents: new Set(),
|
|
11
|
-
accesses:
|
|
12
|
-
scopes:
|
|
14
|
+
accesses: new Map(),
|
|
15
|
+
scopes: new Map()
|
|
13
16
|
};
|
|
14
|
-
|
|
17
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
18
|
+
let mayThrowError = () => { };
|
|
19
|
+
if (typeof window !== 'undefined' || !electron_1.default.ipcMain) {
|
|
20
|
+
mayThrowError = () => { throw new Error('Publish methods is available only in main process.'); };
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
electron_1.default.ipcMain.on(enums_1.IPCChannel.getPublicInfo, e => e.returnValue = publicInfo);
|
|
24
|
+
}
|
|
15
25
|
/**
|
|
16
26
|
* Makes the event from **main** available for **renderer** and **preload** processes.
|
|
17
27
|
*
|
|
18
28
|
* @param name - name by which the event will be accessed
|
|
29
|
+
* @param procFn - function of processing before sending the event
|
|
19
30
|
* @param scopes - event scopes
|
|
20
31
|
*/
|
|
21
|
-
function publicMainEvent(name,
|
|
32
|
+
function publicMainEvent(name, procFn = ((...args) => args[0]), scopes = [enums_1.Scope.preload, enums_1.Scope.renderer]) {
|
|
33
|
+
mayThrowError();
|
|
34
|
+
const { ipcMain } = electron_1.default;
|
|
22
35
|
const { mainEvents } = publicInfo;
|
|
23
36
|
const mainEmitChannel = enums_1.IPCChannel.mainEventEmit + name;
|
|
24
37
|
const mainHandleChannel = enums_1.IPCChannel.mainEventOn + name;
|
|
@@ -26,12 +39,16 @@ function publicMainEvent(name, receiver = ((v = undefined) => v), scopes = [enum
|
|
|
26
39
|
let senders = [];
|
|
27
40
|
let sendersOnce = [];
|
|
28
41
|
mainEvents.add(name);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const rendererNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
|
|
43
|
+
const rendererNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
|
|
44
|
+
if (!publicInfo.scopes.has(rendererNameOn)) {
|
|
45
|
+
publicInfo.scopes.set(rendererNameOn, new Set(scopes));
|
|
46
|
+
publicInfo.scopes.set(rendererNameOnce, new Set(scopes));
|
|
47
|
+
}
|
|
48
|
+
ipcMain.removeAllListeners(mainHandleChannel);
|
|
49
|
+
ipcMain.removeAllListeners(mainHandleChannelOnce);
|
|
50
|
+
ipcMain.on(mainHandleChannel, ({ sender }) => !senders.includes(sender) && senders.push(sender));
|
|
51
|
+
ipcMain.on(mainHandleChannelOnce, ({ sender }) => !sendersOnce.includes(sender) && sendersOnce.push(sender));
|
|
35
52
|
return (...args) => {
|
|
36
53
|
function filterSenders() {
|
|
37
54
|
senders = senders.filter(sender => !sender.isDestroyed());
|
|
@@ -40,7 +57,7 @@ function publicMainEvent(name, receiver = ((v = undefined) => v), scopes = [enum
|
|
|
40
57
|
filterSenders();
|
|
41
58
|
const allSenders = [...senders, ...sendersOnce];
|
|
42
59
|
try {
|
|
43
|
-
const result =
|
|
60
|
+
const result = procFn(...args);
|
|
44
61
|
if (result instanceof Promise) {
|
|
45
62
|
result
|
|
46
63
|
.then(value => {
|
|
@@ -70,9 +87,12 @@ exports.publicMainEvent = publicMainEvent;
|
|
|
70
87
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
71
88
|
*
|
|
72
89
|
* @param name - name by which the event will be accessed
|
|
90
|
+
* @param procFn - processing function before calling handlers
|
|
73
91
|
* @param scopes - event scopes
|
|
74
92
|
*/
|
|
75
|
-
function publicRendererEvent(name,
|
|
93
|
+
function publicRendererEvent(name, procFn = ((v) => v), scopes = [enums_1.Scope.preload, enums_1.Scope.renderer]) {
|
|
94
|
+
mayThrowError();
|
|
95
|
+
const { ipcMain } = electron_1.default;
|
|
76
96
|
if (name.startsWith('on')) {
|
|
77
97
|
name = name.replace('on', '');
|
|
78
98
|
name = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
@@ -82,13 +102,13 @@ function publicRendererEvent(name, receiver = ((v = undefined) => v), scopes = [
|
|
|
82
102
|
const handlers = new Set();
|
|
83
103
|
const handlersOnce = new Set();
|
|
84
104
|
rendererEvents.add(name);
|
|
85
|
-
if (!publicInfo.scopes
|
|
86
|
-
publicInfo.scopes
|
|
87
|
-
|
|
88
|
-
|
|
105
|
+
if (!publicInfo.scopes.has(name))
|
|
106
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
107
|
+
ipcMain.removeAllListeners(rendererEmitChannel);
|
|
108
|
+
ipcMain.on(rendererEmitChannel, (_, result) => {
|
|
89
109
|
if (result.error)
|
|
90
110
|
throw new Error(result.error);
|
|
91
|
-
const converted =
|
|
111
|
+
const converted = procFn(result.value);
|
|
92
112
|
handlers.forEach(handler => handler(converted));
|
|
93
113
|
handlersOnce.forEach(handler => handler(converted));
|
|
94
114
|
handlersOnce.clear();
|
|
@@ -109,18 +129,21 @@ exports.publicRendererEvent = publicRendererEvent;
|
|
|
109
129
|
* Makes the function available for **renderer** and **preload** processes.
|
|
110
130
|
*
|
|
111
131
|
* _only for function_
|
|
132
|
+
*
|
|
112
133
|
* @param name - name by which the function will be accessed
|
|
113
134
|
* @param func - linked function
|
|
114
135
|
* @param scopes - function scopes
|
|
115
136
|
*/
|
|
116
137
|
function publicFunction(name, func, scopes = [enums_1.Scope.preload, enums_1.Scope.renderer]) {
|
|
138
|
+
mayThrowError();
|
|
139
|
+
const { ipcMain } = electron_1.default;
|
|
117
140
|
const { functions } = publicInfo;
|
|
118
141
|
const channel = enums_1.IPCChannel.functionCall + name;
|
|
119
142
|
functions.add(name);
|
|
120
|
-
if (!publicInfo.scopes
|
|
121
|
-
publicInfo.scopes
|
|
122
|
-
|
|
123
|
-
|
|
143
|
+
if (!publicInfo.scopes.has(name))
|
|
144
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
145
|
+
ipcMain.removeAllListeners(channel);
|
|
146
|
+
ipcMain.on(channel, (e, ...args) => {
|
|
124
147
|
try {
|
|
125
148
|
const result = func(...args);
|
|
126
149
|
if (result instanceof Promise) {
|
|
@@ -144,32 +167,35 @@ exports.publicFunction = publicFunction;
|
|
|
144
167
|
* Makes the function available for **renderer** and **preload** processes.
|
|
145
168
|
*
|
|
146
169
|
* _only for variables_
|
|
170
|
+
*
|
|
147
171
|
* @param name - name by which the variable will be accessed
|
|
148
172
|
* @param value - variable getter/setter
|
|
149
173
|
* @param scopes - variable scopes
|
|
150
174
|
*/
|
|
151
175
|
function publicVariable(name, value, scopes = [enums_1.Scope.renderer, enums_1.Scope.preload]) {
|
|
176
|
+
mayThrowError();
|
|
177
|
+
const { ipcMain } = electron_1.default;
|
|
152
178
|
const { properties } = publicInfo;
|
|
153
179
|
const getChannel = enums_1.IPCChannel.propertyGet + name;
|
|
154
180
|
const setChannel = enums_1.IPCChannel.propertySet + name;
|
|
155
181
|
const { get: getter, set: setter } = value;
|
|
156
182
|
properties.add(name);
|
|
157
|
-
if (!publicInfo.scopes
|
|
158
|
-
publicInfo.scopes
|
|
159
|
-
if (!publicInfo.accesses
|
|
183
|
+
if (!publicInfo.scopes.has(name))
|
|
184
|
+
publicInfo.scopes.set(name, new Set(scopes));
|
|
185
|
+
if (!publicInfo.accesses.has(name)) {
|
|
160
186
|
const accesses = [];
|
|
161
187
|
getter && accesses.push(enums_1.Access.get);
|
|
162
188
|
setter && accesses.push(enums_1.Access.set);
|
|
163
|
-
publicInfo.accesses
|
|
189
|
+
publicInfo.accesses.set(name, new Set(accesses));
|
|
164
190
|
}
|
|
165
191
|
else {
|
|
166
|
-
const accesses = publicInfo.accesses
|
|
192
|
+
const accesses = publicInfo.accesses.get(name);
|
|
167
193
|
getter && accesses.add(enums_1.Access.get);
|
|
168
194
|
setter && accesses.add(enums_1.Access.set);
|
|
169
195
|
}
|
|
170
196
|
if (getter) {
|
|
171
|
-
|
|
172
|
-
|
|
197
|
+
ipcMain.removeAllListeners(getChannel);
|
|
198
|
+
ipcMain.on(getChannel, event => {
|
|
173
199
|
try {
|
|
174
200
|
const result = getter();
|
|
175
201
|
event.returnValue = { value: result };
|
|
@@ -180,8 +206,8 @@ function publicVariable(name, value, scopes = [enums_1.Scope.renderer, enums_1.S
|
|
|
180
206
|
});
|
|
181
207
|
}
|
|
182
208
|
if (setter) {
|
|
183
|
-
|
|
184
|
-
|
|
209
|
+
ipcMain.removeAllListeners(setChannel);
|
|
210
|
+
ipcMain.on(setChannel, (event, ...args) => {
|
|
185
211
|
try {
|
|
186
212
|
setter(args[0]);
|
|
187
213
|
event.returnValue = { value: null };
|
|
@@ -194,10 +220,10 @@ function publicVariable(name, value, scopes = [enums_1.Scope.renderer, enums_1.S
|
|
|
194
220
|
}
|
|
195
221
|
exports.publicVariable = publicVariable;
|
|
196
222
|
function addScope(key, scope) {
|
|
197
|
-
publicInfo.scopes
|
|
223
|
+
publicInfo.scopes.set(key, new Set([scope]));
|
|
198
224
|
}
|
|
199
225
|
exports.addScope = addScope;
|
|
200
226
|
function addAccess(key, access) {
|
|
201
|
-
publicInfo.accesses
|
|
227
|
+
publicInfo.accesses.set(key, new Set([access]));
|
|
202
228
|
}
|
|
203
229
|
exports.addAccess = addAccess;
|
package/cjs/types.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface IPublishMainEventArgs {
|
|
|
25
25
|
export interface IPublishRendererEventArgs {
|
|
26
26
|
name?: string;
|
|
27
27
|
scope?: Scope;
|
|
28
|
-
|
|
28
|
+
procFn?: EventReceiver;
|
|
29
29
|
}
|
|
30
30
|
export interface IPublishPropertyArgs {
|
|
31
31
|
name?: string;
|
|
@@ -42,14 +42,14 @@ 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 =
|
|
47
|
-
export type RendererEvent<T =
|
|
48
|
-
export type MainEvent<T =
|
|
45
|
+
export type Scopes = Map<string, Set<Scope>>;
|
|
46
|
+
export type Accesses = Map<string, Set<Access>>;
|
|
47
|
+
export type RendererEvent<T = void> = (handler: EventHandler<T>, isOnce?: boolean) => EventUnsubscriber;
|
|
48
|
+
export type MainEvent<T = void> = (handler: EventHandler<T>) => EventUnsubscriber;
|
|
49
49
|
export type EventEmitter = (...args: any[]) => any;
|
|
50
|
-
export type EventReceiver<I =
|
|
50
|
+
export type EventReceiver<I = void, O = I> = (input: I) => O;
|
|
51
51
|
export type EventUnsubscriber = () => void;
|
|
52
|
-
export type EventHandler<T> = (result: T) => void;
|
|
52
|
+
export type EventHandler<T = void> = (result: T) => void;
|
|
53
53
|
export interface IRendererPublic {
|
|
54
54
|
__register__?(instance: any): void;
|
|
55
55
|
}
|
|
@@ -67,9 +67,9 @@ export interface IProvider {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
export type PublicFunction = (...args: any[]) => any;
|
|
70
|
-
export type PublicProperty = {
|
|
71
|
-
get?():
|
|
72
|
-
set?(value:
|
|
70
|
+
export type PublicProperty<T> = {
|
|
71
|
+
get?(): T;
|
|
72
|
+
set?(value: T): void;
|
|
73
73
|
};
|
|
74
74
|
export interface IInfo {
|
|
75
75
|
properties: Set<string>;
|
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/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
+
export * from './preload';
|
|
3
|
+
export * from './renderer';
|
|
2
4
|
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
5
|
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
6
|
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
+
export * from './preload';
|
|
3
|
+
export * from './renderer';
|
|
2
4
|
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
5
|
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
package/esm/main.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
|
4
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/esm/main.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Access, Scope } from './enums';
|
|
2
|
+
export { publicClassMainEvent, publicClassRendererEvent, publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
|
|
3
|
+
export { publicFunction, publicMainEvent, publicRendererEvent, publicVariable } from './scripts/publish';
|
package/esm/scripts/Bridge.d.ts
CHANGED