emr-bridge 1.5.0 → 1.6.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/README.md +15 -15
- package/cjs/enums.js +3 -3
- package/cjs/main.d.ts +4 -0
- package/cjs/main.js +18 -0
- package/cjs/preload.d.ts +1 -0
- package/cjs/renderer.d.ts +1 -0
- package/cjs/scripts/Bridge.d.ts +2 -1
- package/cjs/scripts/Bridge.js +44 -27
- package/cjs/scripts/Main.d.ts +2 -1
- package/cjs/scripts/Main.js +71 -51
- package/cjs/scripts/newDecorators.d.ts +13 -6
- package/cjs/scripts/newDecorators.js +1 -1
- package/cjs/scripts/oldDecorators.d.ts +13 -37
- package/cjs/scripts/oldDecorators.js +1 -1
- package/cjs/scripts/preloadProvider.js +28 -15
- package/cjs/scripts/publish.d.ts +9 -5
- package/cjs/scripts/publish.js +40 -18
- package/cjs/types.d.ts +8 -8
- package/esm/main.d.ts +4 -0
- package/esm/main.js +3 -0
- package/esm/preload.d.ts +1 -0
- package/esm/renderer.d.ts +1 -0
- package/esm/scripts/Bridge.d.ts +2 -1
- package/esm/scripts/Bridge.js +44 -27
- package/esm/scripts/Main.d.ts +2 -1
- package/esm/scripts/Main.js +71 -51
- package/esm/scripts/newDecorators.d.ts +13 -6
- package/esm/scripts/newDecorators.js +1 -1
- package/esm/scripts/oldDecorators.d.ts +13 -37
- package/esm/scripts/oldDecorators.js +1 -1
- package/esm/scripts/preloadProvider.js +12 -2
- package/esm/scripts/publish.d.ts +9 -5
- package/esm/scripts/publish.js +25 -6
- package/esm/types.d.ts +8 -8
- package/package.json +3 -19
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ There are three ways to use
|
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
// Preload process
|
|
35
|
-
import { provideFromMain } from 'emr-bridge
|
|
35
|
+
import { provideFromMain } from 'emr-bridge'
|
|
36
36
|
|
|
37
37
|
provideFromMain(true /* context isolation */)
|
|
38
38
|
```
|
|
@@ -41,7 +41,7 @@ provideFromMain(true /* context isolation */)
|
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
43
|
// Main process
|
|
44
|
-
import { providePublic } from 'emr-bridge/
|
|
44
|
+
import { providePublic } from 'emr-bridge/exp'
|
|
45
45
|
|
|
46
46
|
class MainPublic { /*...*/ }
|
|
47
47
|
|
|
@@ -56,7 +56,7 @@ Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
|
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
// Main process
|
|
59
|
-
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge
|
|
59
|
+
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
|
|
60
60
|
|
|
61
61
|
class User {
|
|
62
62
|
private static name = 'Name'
|
|
@@ -102,7 +102,7 @@ Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
|
|
|
102
102
|
|
|
103
103
|
```ts
|
|
104
104
|
// Main process
|
|
105
|
-
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge
|
|
105
|
+
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
|
|
106
106
|
|
|
107
107
|
class User {
|
|
108
108
|
private name = 'Name'
|
|
@@ -150,7 +150,7 @@ Use **publicFunction** and **publicVariable**.
|
|
|
150
150
|
|
|
151
151
|
```ts
|
|
152
152
|
// Main process
|
|
153
|
-
import { publicFunction, publicVariable } from 'emr-bridge
|
|
153
|
+
import { publicFunction, publicVariable } from 'emr-bridge'
|
|
154
154
|
|
|
155
155
|
publicFunction('sayHello', sayHello)
|
|
156
156
|
publicFunction('getUserName', getName)
|
|
@@ -189,7 +189,7 @@ Accessing an entity outside the specified scope will result in an error being th
|
|
|
189
189
|
// Main process
|
|
190
190
|
|
|
191
191
|
// static and non-static
|
|
192
|
-
import { Scope, Access, publicMethod, publicGetter } from 'emr-bridge
|
|
192
|
+
import { Scope, Access, publicMethod, publicGetter } from 'emr-bridge'
|
|
193
193
|
|
|
194
194
|
class User {
|
|
195
195
|
private static age = 20
|
|
@@ -223,7 +223,7 @@ new User()
|
|
|
223
223
|
```ts
|
|
224
224
|
// Main process
|
|
225
225
|
// functions and variables
|
|
226
|
-
import { publicFunction, publicVariable, Scope } from 'emr-bridge
|
|
226
|
+
import { publicFunction, publicVariable, Scope } from 'emr-bridge'
|
|
227
227
|
|
|
228
228
|
publicFunction('getName', getName, [Scope.preload])
|
|
229
229
|
publicVariable('count', {
|
|
@@ -250,7 +250,7 @@ Using an entity outside the specified scope _will cause an error_.
|
|
|
250
250
|
```ts
|
|
251
251
|
// Main process
|
|
252
252
|
// static and non-static
|
|
253
|
-
import { publicGetter, Access } from 'emr-bridge
|
|
253
|
+
import { publicGetter, Access } from 'emr-bridge'
|
|
254
254
|
|
|
255
255
|
class User {
|
|
256
256
|
private static name = 'Name'
|
|
@@ -276,7 +276,7 @@ new User()
|
|
|
276
276
|
```ts
|
|
277
277
|
// Main process
|
|
278
278
|
// for variables
|
|
279
|
-
import { publicVariable } from 'emr-bridge
|
|
279
|
+
import { publicVariable } from 'emr-bridge'
|
|
280
280
|
|
|
281
281
|
publicVariable('count', {
|
|
282
282
|
// get access
|
|
@@ -294,7 +294,7 @@ let count = 0
|
|
|
294
294
|
|
|
295
295
|
### Access from renderer and preload
|
|
296
296
|
|
|
297
|
-
For _preload_, use **Main**
|
|
297
|
+
For _preload_, use **Main**
|
|
298
298
|
|
|
299
299
|
```ts
|
|
300
300
|
// Preload process
|
|
@@ -315,7 +315,7 @@ main.count++
|
|
|
315
315
|
main.setUserAge(20)
|
|
316
316
|
```
|
|
317
317
|
|
|
318
|
-
For _renderer_, use **Bridge**
|
|
318
|
+
For _renderer_, use **Bridge**
|
|
319
319
|
|
|
320
320
|
```ts
|
|
321
321
|
// Renderer process
|
|
@@ -340,7 +340,7 @@ The library also allows you to pass Promises from main to renderer
|
|
|
340
340
|
|
|
341
341
|
```ts
|
|
342
342
|
// Main process
|
|
343
|
-
import { publicFunction } from 'emr-bridge
|
|
343
|
+
import { publicFunction } from 'emr-bridge'
|
|
344
344
|
|
|
345
345
|
publicFunction('delay1s', () => {
|
|
346
346
|
return new Promise<void>(resolve => {
|
|
@@ -368,7 +368,7 @@ If the event source is the **main** process
|
|
|
368
368
|
|
|
369
369
|
```ts
|
|
370
370
|
// Main process
|
|
371
|
-
import { publicMainEvent, publicClassMainEvent } from 'emr-bridge
|
|
371
|
+
import { publicMainEvent, publicClassMainEvent } from 'emr-bridge'
|
|
372
372
|
|
|
373
373
|
const tickWithReceiver = publicMainEvent('tickWithReceiver', () => (new Date().toTimeString()))
|
|
374
374
|
setInterval(tickWithReceiver, 1000)
|
|
@@ -420,9 +420,9 @@ If the event source is the **renderer** process
|
|
|
420
420
|
|
|
421
421
|
```ts
|
|
422
422
|
// Main process
|
|
423
|
-
import { publicRendererEvent, publicClassRendererEvent, RendererEvent } from 'emr-bridge
|
|
423
|
+
import { publicRendererEvent, publicClassRendererEvent, RendererEvent } from 'emr-bridge'
|
|
424
424
|
|
|
425
|
-
const onMessage = publicRendererEvent('onMessage'/* or 'message' */)
|
|
425
|
+
const onMessage = publicRendererEvent<string>('onMessage'/* or 'message' */)
|
|
426
426
|
onMessage(message => console.log(message))
|
|
427
427
|
|
|
428
428
|
// With receiver
|
package/cjs/enums.js
CHANGED
|
@@ -5,12 +5,12 @@ var Access;
|
|
|
5
5
|
(function (Access) {
|
|
6
6
|
Access["get"] = "get";
|
|
7
7
|
Access["set"] = "set";
|
|
8
|
-
})(Access
|
|
8
|
+
})(Access || (exports.Access = Access = {}));
|
|
9
9
|
var Scope;
|
|
10
10
|
(function (Scope) {
|
|
11
11
|
Scope["renderer"] = "renderer";
|
|
12
12
|
Scope["preload"] = "preload";
|
|
13
|
-
})(Scope
|
|
13
|
+
})(Scope || (exports.Scope = Scope = {}));
|
|
14
14
|
var IPCChannel;
|
|
15
15
|
(function (IPCChannel) {
|
|
16
16
|
IPCChannel["getPublicInfo"] = "GET_PUBLIC_INFO";
|
|
@@ -22,4 +22,4 @@ var IPCChannel;
|
|
|
22
22
|
IPCChannel["propertySet"] = "PROPERTY_SET_";
|
|
23
23
|
IPCChannel["promisePostfix"] = "_PROMISE";
|
|
24
24
|
IPCChannel["rendererEventEmit"] = "RENDERER_EMIT_";
|
|
25
|
-
})(IPCChannel
|
|
25
|
+
})(IPCChannel || (exports.IPCChannel = IPCChannel = {}));
|
package/cjs/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/cjs/main.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.publicSetter = exports.publicProperty = exports.publicMethod = exports.publicGetter = exports.publicClassRendererEvent = exports.publicClassMainEvent = exports.Scope = exports.Access = void 0;
|
|
4
|
+
var enums_1 = require("./enums");
|
|
5
|
+
Object.defineProperty(exports, "Access", { enumerable: true, get: function () { return enums_1.Access; } });
|
|
6
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return enums_1.Scope; } });
|
|
7
|
+
var newDecorators_1 = require("./scripts/newDecorators");
|
|
8
|
+
Object.defineProperty(exports, "publicClassMainEvent", { enumerable: true, get: function () { return newDecorators_1.publicClassMainEvent; } });
|
|
9
|
+
Object.defineProperty(exports, "publicClassRendererEvent", { enumerable: true, get: function () { return newDecorators_1.publicClassRendererEvent; } });
|
|
10
|
+
Object.defineProperty(exports, "publicGetter", { enumerable: true, get: function () { return newDecorators_1.publicGetter; } });
|
|
11
|
+
Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return newDecorators_1.publicMethod; } });
|
|
12
|
+
Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return newDecorators_1.publicProperty; } });
|
|
13
|
+
Object.defineProperty(exports, "publicSetter", { enumerable: true, get: function () { return newDecorators_1.publicSetter; } });
|
|
14
|
+
var publish_1 = require("./scripts/publish");
|
|
15
|
+
Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_1.publicFunction; } });
|
|
16
|
+
Object.defineProperty(exports, "publicMainEvent", { enumerable: true, get: function () { return publish_1.publicMainEvent; } });
|
|
17
|
+
Object.defineProperty(exports, "publicRendererEvent", { enumerable: true, get: function () { return publish_1.publicRendererEvent; } });
|
|
18
|
+
Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_1.publicVariable; } });
|
package/cjs/preload.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { default as Main } from './scripts/Main';
|
|
2
2
|
export { default as provideFromMain } from './scripts/preloadProvider';
|
|
3
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/cjs/renderer.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export { default as Bridge } from './scripts/Bridge';
|
|
2
|
+
export type { EventEmitter, EventHandler, EventReceiver, EventUnsubscriber, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, MainEvent, PublicFunction, PublicProperty, RendererEvent } from './types';
|
package/cjs/scripts/Bridge.d.ts
CHANGED
package/cjs/scripts/Bridge.js
CHANGED
|
@@ -5,37 +5,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const enums_1 = require("../enums");
|
|
7
7
|
const provider_1 = __importDefault(require("./provider"));
|
|
8
|
-
if (!window.__provider__)
|
|
9
|
-
throw new Error('Required methods not provided. Did you forget to call "provide" in preload?');
|
|
10
|
-
const provider = window.__provider__;
|
|
11
|
-
const info = provider.getInfo();
|
|
12
8
|
/**
|
|
13
9
|
* Bridge between `renderer` and `main` processes.
|
|
14
10
|
*
|
|
15
11
|
* _only for renderer process_
|
|
16
12
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
emitRendererEvent(name, arg) {
|
|
23
|
-
provider.provided.rendererEvents[name](arg);
|
|
24
|
-
},
|
|
25
|
-
handleMainEvent(name, type, handler) {
|
|
26
|
-
return provider.provided.mainEvents[name](type, handler);
|
|
27
|
-
},
|
|
28
|
-
getVariable(name) {
|
|
29
|
-
return provider.provided.properties[name].get();
|
|
30
|
-
},
|
|
31
|
-
setVariable(name, value) {
|
|
32
|
-
provider.provided.properties[name].set(value);
|
|
33
|
-
return undefined;
|
|
34
|
-
},
|
|
35
|
-
waitPromise(channel) {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
provider.waitPromise(channel, resolve, reject);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
13
|
+
let Bridge = new Proxy({ as() { throwError(); } }, {
|
|
14
|
+
get() { throwError(); },
|
|
15
|
+
set() { throwError(); },
|
|
16
|
+
apply() { throwError(); }
|
|
40
17
|
});
|
|
18
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
19
|
+
let throwError;
|
|
20
|
+
if (typeof window === 'undefined') {
|
|
21
|
+
throwError = () => { throw new Error('"Bridge" is unavailable in main process. In preload use "Main" instead.'); };
|
|
22
|
+
}
|
|
23
|
+
else if (!window.__provider__) {
|
|
24
|
+
throwError = () => { throw new Error('Required methods not provided. Call "provideFromMain" in preload process.'); };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
initInWeb();
|
|
28
|
+
}
|
|
29
|
+
/** Выполняется только в web */
|
|
30
|
+
function initInWeb() {
|
|
31
|
+
const provider = window.__provider__;
|
|
32
|
+
const info = provider.getInfo();
|
|
33
|
+
Bridge = (0, provider_1.default)({
|
|
34
|
+
info, scope: enums_1.Scope.renderer,
|
|
35
|
+
callFunction(name, ...args) {
|
|
36
|
+
return provider.provided.functions[name](...args);
|
|
37
|
+
},
|
|
38
|
+
emitRendererEvent(name, arg) {
|
|
39
|
+
provider.provided.rendererEvents[name](arg);
|
|
40
|
+
},
|
|
41
|
+
handleMainEvent(name, type, handler) {
|
|
42
|
+
return provider.provided.mainEvents[name](type, handler);
|
|
43
|
+
},
|
|
44
|
+
getVariable(name) {
|
|
45
|
+
return provider.provided.properties[name].get();
|
|
46
|
+
},
|
|
47
|
+
setVariable(name, value) {
|
|
48
|
+
provider.provided.properties[name].set(value);
|
|
49
|
+
return undefined;
|
|
50
|
+
},
|
|
51
|
+
waitPromise(channel) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
provider.waitPromise(channel, resolve, reject);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
41
58
|
exports.default = Bridge;
|
package/cjs/scripts/Main.d.ts
CHANGED
package/cjs/scripts/Main.js
CHANGED
|
@@ -3,63 +3,83 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const electron_1 = require("electron");
|
|
6
|
+
const electron_1 = __importDefault(require("electron"));
|
|
7
7
|
const enums_1 = require("../enums");
|
|
8
8
|
const provider_1 = __importDefault(require("./provider"));
|
|
9
|
-
const info = electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.getPublicInfo);
|
|
10
|
-
if (!info)
|
|
11
|
-
throw new Error('Public methods from main is not provided');
|
|
12
9
|
/**
|
|
13
10
|
* Bridge between `preload` and `main` processes.
|
|
14
11
|
*
|
|
15
12
|
* _only for preload process_
|
|
16
13
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
handleMainEvent(name, type, handler) {
|
|
23
|
-
const listener = (_, result) => handler(result);
|
|
24
|
-
const emitChannel = enums_1.IPCChannel.mainEventEmit + name;
|
|
25
|
-
if (type === 'on') {
|
|
26
|
-
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + name);
|
|
27
|
-
electron_1.ipcRenderer.on(emitChannel, listener);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + name);
|
|
31
|
-
electron_1.ipcRenderer.once(emitChannel, listener);
|
|
32
|
-
}
|
|
33
|
-
return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
|
|
34
|
-
},
|
|
35
|
-
emitRendererEvent(name, arg) {
|
|
36
|
-
const emitChannel = enums_1.IPCChannel.rendererEventEmit + name;
|
|
37
|
-
if (arg instanceof Promise) {
|
|
38
|
-
const promiseChannel = emitChannel + enums_1.IPCChannel.promisePostfix;
|
|
39
|
-
electron_1.ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
40
|
-
arg
|
|
41
|
-
.then(value => electron_1.ipcRenderer.send(promiseChannel, { value }))
|
|
42
|
-
.catch(reason => electron_1.ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
electron_1.ipcRenderer.send(emitChannel, { value: arg });
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
getVariable(name) {
|
|
49
|
-
return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + name);
|
|
50
|
-
},
|
|
51
|
-
setVariable(name, value) {
|
|
52
|
-
return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertySet + name, value);
|
|
53
|
-
},
|
|
54
|
-
waitPromise(channel) {
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
electron_1.ipcRenderer.once(channel, (_, result) => {
|
|
57
|
-
if (result.error)
|
|
58
|
-
reject(result.error);
|
|
59
|
-
else
|
|
60
|
-
resolve(result.value);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
14
|
+
let Main = new Proxy({ as() { throwError(); } }, {
|
|
15
|
+
get() { throwError(); },
|
|
16
|
+
set() { throwError(); },
|
|
17
|
+
apply() { throwError(); }
|
|
64
18
|
});
|
|
19
|
+
/** Выбрасывает ошибку если используется не в том процессе */
|
|
20
|
+
let throwError;
|
|
21
|
+
if (typeof window !== 'undefined') {
|
|
22
|
+
throwError = () => { throw new Error('"Main" is unavailable in renderer process. Use "Bridge" instead'); };
|
|
23
|
+
}
|
|
24
|
+
else if (!('ipcRenderer' in electron_1.default)) {
|
|
25
|
+
throwError = () => { throw new Error('"Main" is unavailable in main process.'); };
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
initInNode();
|
|
29
|
+
}
|
|
30
|
+
/** Выполняется только в NodeJS */
|
|
31
|
+
function initInNode() {
|
|
32
|
+
const { ipcRenderer } = electron_1.default;
|
|
33
|
+
const info = ipcRenderer.sendSync(enums_1.IPCChannel.getPublicInfo);
|
|
34
|
+
if (!info)
|
|
35
|
+
throw new Error('Public methods from main is not provided. Call any publish methods to provide it from main process.');
|
|
36
|
+
Main = (0, provider_1.default)({
|
|
37
|
+
info, scope: enums_1.Scope.preload,
|
|
38
|
+
callFunction(name, ...args) {
|
|
39
|
+
return ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + name, ...args);
|
|
40
|
+
},
|
|
41
|
+
handleMainEvent(name, type, handler) {
|
|
42
|
+
const listener = (_, result) => handler(result);
|
|
43
|
+
const emitChannel = enums_1.IPCChannel.mainEventEmit + name;
|
|
44
|
+
if (type === 'on') {
|
|
45
|
+
ipcRenderer.send(enums_1.IPCChannel.mainEventOn + name);
|
|
46
|
+
ipcRenderer.on(emitChannel, listener);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + name);
|
|
50
|
+
ipcRenderer.once(emitChannel, listener);
|
|
51
|
+
}
|
|
52
|
+
return () => ipcRenderer.removeListener(emitChannel, listener);
|
|
53
|
+
},
|
|
54
|
+
emitRendererEvent(name, arg) {
|
|
55
|
+
const emitChannel = enums_1.IPCChannel.rendererEventEmit + name;
|
|
56
|
+
if (arg instanceof Promise) {
|
|
57
|
+
const promiseChannel = emitChannel + enums_1.IPCChannel.promisePostfix;
|
|
58
|
+
ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
59
|
+
arg
|
|
60
|
+
.then(value => ipcRenderer.send(promiseChannel, { value }))
|
|
61
|
+
.catch(reason => ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
ipcRenderer.send(emitChannel, { value: arg });
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
getVariable(name) {
|
|
68
|
+
return ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + name);
|
|
69
|
+
},
|
|
70
|
+
setVariable(name, value) {
|
|
71
|
+
return ipcRenderer.sendSync(enums_1.IPCChannel.propertySet + name, value);
|
|
72
|
+
},
|
|
73
|
+
waitPromise(channel) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
ipcRenderer.once(channel, (_, result) => {
|
|
76
|
+
if (result.error)
|
|
77
|
+
reject(result.error);
|
|
78
|
+
else
|
|
79
|
+
resolve(result.value);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
65
85
|
exports.default = Main;
|
|
@@ -9,6 +9,7 @@ export declare function publicMethod(): ClassMethodDecorator;
|
|
|
9
9
|
* Makes the method available for **renderer** and **preload** processes.
|
|
10
10
|
*
|
|
11
11
|
* _only new decorators_
|
|
12
|
+
*
|
|
12
13
|
* @param name - name by which the method will be accessed
|
|
13
14
|
*/
|
|
14
15
|
export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
@@ -16,6 +17,7 @@ export declare function publicMethod(name: string): ClassMethodDecorator;
|
|
|
16
17
|
* Makes the method available for **renderer** and **preload** processes.
|
|
17
18
|
*
|
|
18
19
|
* _only new decorators_
|
|
20
|
+
*
|
|
19
21
|
* @param args - publish args
|
|
20
22
|
*/
|
|
21
23
|
export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecorator;
|
|
@@ -29,6 +31,7 @@ export declare function publicClassMainEvent(): ClassMethodDecorator;
|
|
|
29
31
|
* Makes the event available for **renderer** and **preload** processes.
|
|
30
32
|
*
|
|
31
33
|
* _only new decorators_
|
|
34
|
+
*
|
|
32
35
|
* @param name - name by which the event will be accessed
|
|
33
36
|
*/
|
|
34
37
|
export declare function publicClassMainEvent(name: string): ClassMethodDecorator;
|
|
@@ -36,6 +39,7 @@ export declare function publicClassMainEvent(name: string): ClassMethodDecorator
|
|
|
36
39
|
* Makes the event available for **renderer** and **preload** processes.
|
|
37
40
|
*
|
|
38
41
|
* _only new decorators_
|
|
42
|
+
*
|
|
39
43
|
* @param args - publish args
|
|
40
44
|
*/
|
|
41
45
|
export declare function publicClassMainEvent(args: IPublishMainEventArgs): ClassMethodDecorator;
|
|
@@ -49,6 +53,7 @@ export declare function publicClassRendererEvent(): ClassPropertyDecorator;
|
|
|
49
53
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
50
54
|
*
|
|
51
55
|
* _only new decorators_
|
|
56
|
+
*
|
|
52
57
|
* @param name - name by which the event will be accessed
|
|
53
58
|
*/
|
|
54
59
|
export declare function publicClassRendererEvent(name: string): ClassPropertyDecorator;
|
|
@@ -56,12 +61,14 @@ export declare function publicClassRendererEvent(name: string): ClassPropertyDec
|
|
|
56
61
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
57
62
|
*
|
|
58
63
|
* _only new decorators_
|
|
64
|
+
*
|
|
59
65
|
* @param receiver - linked receiver
|
|
60
66
|
*/
|
|
61
67
|
export declare function publicClassRendererEvent(receiver: EventReceiver): ClassPropertyDecorator;
|
|
62
68
|
/**
|
|
63
69
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
64
70
|
*
|
|
71
|
+
* * _only new decorators_
|
|
65
72
|
*
|
|
66
73
|
* @param name - name by which the event will be accessed
|
|
67
74
|
* @param receiver - linked receiver
|
|
@@ -71,13 +78,7 @@ export declare function publicClassRendererEvent(name: string, receiver: EventRe
|
|
|
71
78
|
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
72
79
|
*
|
|
73
80
|
* _only new decorators_
|
|
74
|
-
* @param args - publish args
|
|
75
|
-
*/
|
|
76
|
-
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
77
|
-
/**
|
|
78
|
-
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
79
81
|
*
|
|
80
|
-
* _only new decorators_
|
|
81
82
|
* @param args - publish args
|
|
82
83
|
*/
|
|
83
84
|
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
@@ -91,6 +92,7 @@ export declare function publicProperty(): ClassPropertyDecorator;
|
|
|
91
92
|
* Makes the property available for **renderer** and **preload** processes.
|
|
92
93
|
*
|
|
93
94
|
* _only new decorators_
|
|
95
|
+
*
|
|
94
96
|
* @param name - name by which the property will be accessed
|
|
95
97
|
*/
|
|
96
98
|
export declare function publicProperty(name: string): ClassPropertyDecorator;
|
|
@@ -98,6 +100,7 @@ export declare function publicProperty(name: string): ClassPropertyDecorator;
|
|
|
98
100
|
* Makes the property available for **renderer** and **preload** processes.
|
|
99
101
|
*
|
|
100
102
|
* _only new decorators_
|
|
103
|
+
*
|
|
101
104
|
* @param args - publish args
|
|
102
105
|
*/
|
|
103
106
|
export declare function publicProperty(args: IPublishPropertyArgs): ClassPropertyDecorator;
|
|
@@ -111,6 +114,7 @@ export declare function publicGetter(): ClassGetterDecorator;
|
|
|
111
114
|
* Makes the property getter available for **renderer** and **preload** processes.
|
|
112
115
|
*
|
|
113
116
|
* _only new decorators_
|
|
117
|
+
*
|
|
114
118
|
* @param name - name by which the property will be accessed
|
|
115
119
|
*/
|
|
116
120
|
export declare function publicGetter(name: string): ClassGetterDecorator;
|
|
@@ -118,6 +122,7 @@ export declare function publicGetter(name: string): ClassGetterDecorator;
|
|
|
118
122
|
* Makes the property getter available for **renderer** and **preload** processes.
|
|
119
123
|
*
|
|
120
124
|
* _only new decorators_
|
|
125
|
+
*
|
|
121
126
|
* @param args - publish args
|
|
122
127
|
*/
|
|
123
128
|
export declare function publicGetter(args: PublishGetterArgs): ClassGetterDecorator;
|
|
@@ -131,6 +136,7 @@ export declare function publicSetter(): ClassSetterDecorator;
|
|
|
131
136
|
* Makes the property setter available for **renderer** and **preload** processes.
|
|
132
137
|
*
|
|
133
138
|
* _only new decorators_
|
|
139
|
+
*
|
|
134
140
|
* @param name - name by which the property will be accessed
|
|
135
141
|
*/
|
|
136
142
|
export declare function publicSetter(name: string): ClassSetterDecorator;
|
|
@@ -138,6 +144,7 @@ export declare function publicSetter(name: string): ClassSetterDecorator;
|
|
|
138
144
|
* Makes the property setter available for **renderer** and **preload** processes.
|
|
139
145
|
*
|
|
140
146
|
* _only new decorators_
|
|
147
|
+
*
|
|
141
148
|
* @param args - publish args
|
|
142
149
|
*/
|
|
143
150
|
export declare function publicSetter(args: PublishSetterArgs): ClassSetterDecorator;
|
|
@@ -51,7 +51,7 @@ function publicClassRendererEvent(arg) {
|
|
|
51
51
|
}
|
|
52
52
|
else if (typeof arg === 'object') {
|
|
53
53
|
name = arg.name ?? String(context.name);
|
|
54
|
-
receiver = arg.
|
|
54
|
+
receiver = arg.procFn ?? receiver;
|
|
55
55
|
if (arg.scope)
|
|
56
56
|
(0, publish_1.addScope)(name, arg.scope);
|
|
57
57
|
}
|