emr-bridge 1.3.0 → 1.4.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 +133 -110
- package/cjs/enums.d.ts +5 -4
- package/cjs/enums.js +4 -3
- package/cjs/exp.d.ts +3 -3
- package/cjs/exp.js +7 -4
- package/cjs/index.d.ts +3 -3
- package/cjs/index.js +5 -3
- package/cjs/scripts/Bridge.js +8 -5
- package/cjs/scripts/Main.js +17 -4
- package/cjs/scripts/newDecorators.d.ts +46 -4
- package/cjs/scripts/newDecorators.js +33 -8
- package/cjs/scripts/oldDecorators.d.ts +115 -7
- package/cjs/scripts/oldDecorators.js +40 -7
- package/cjs/scripts/preloadProvider.js +35 -28
- package/cjs/scripts/provider.js +22 -9
- package/cjs/scripts/publish.d.ts +10 -5
- package/cjs/scripts/publish.js +59 -23
- package/cjs/types.d.ts +18 -5
- package/esm/enums.d.ts +5 -4
- package/esm/enums.js +4 -3
- package/esm/exp.d.ts +3 -3
- package/esm/exp.js +2 -2
- package/esm/index.d.ts +3 -3
- package/esm/index.js +2 -2
- package/esm/scripts/Bridge.js +8 -5
- package/esm/scripts/Main.js +17 -4
- package/esm/scripts/newDecorators.d.ts +46 -4
- package/esm/scripts/newDecorators.js +31 -7
- package/esm/scripts/oldDecorators.d.ts +115 -7
- package/esm/scripts/oldDecorators.js +36 -5
- package/esm/scripts/preloadProvider.js +35 -28
- package/esm/scripts/provider.js +22 -9
- package/esm/scripts/publish.d.ts +10 -5
- package/esm/scripts/publish.js +56 -21
- package/esm/types.d.ts +18 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ JS library for easily providing access to the **main** from the **renderer** pro
|
|
|
14
14
|
- [access](#restricting-access-to-variables)
|
|
15
15
|
- [usage in renderer](#access-from-renderer-and-preload)
|
|
16
16
|
- [promises](#promises)
|
|
17
|
+
- [events](#events-system)
|
|
17
18
|
|
|
18
19
|
## Installation
|
|
19
20
|
|
|
@@ -23,11 +24,11 @@ npm i emr-bridge
|
|
|
23
24
|
|
|
24
25
|
## Usage
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
*If you need CommonJS modules, then use `emr-bridge/cjs`*
|
|
27
28
|
|
|
28
29
|
There are three ways to use
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
> In any of the cases, you need to insert this code into preload
|
|
31
32
|
|
|
32
33
|
```js
|
|
33
34
|
// Preload process
|
|
@@ -36,59 +37,26 @@ import { provideFromMain } from 'emr-bridge/preload'
|
|
|
36
37
|
provideFromMain(true /* context isolation */)
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
**Experimental decorators**
|
|
42
|
-
|
|
43
|
-
Use **publicStaticMethod**/**publicStaticProperty**.
|
|
40
|
+
> To use experimental non-static decorators, it is required to wrap the creation of a class instance in the `providePublic` function
|
|
44
41
|
|
|
45
|
-
```
|
|
42
|
+
```js
|
|
46
43
|
// Main process
|
|
44
|
+
import { providePublic } from 'emr-bridge/main/exp'
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
class MainPublic { /*...*/ }
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
private static name = 'Name'
|
|
52
|
-
private static age = 20
|
|
53
|
-
private static money = 1000
|
|
54
|
-
|
|
55
|
-
@publicStaticProperty('userBalance')
|
|
56
|
-
static get balance(): string {
|
|
57
|
-
return `${this.money}$`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static set balance(newBalance: string) {
|
|
61
|
-
this.money = Number(newBalance.split('$')[0])
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@publicStaticProperty({
|
|
65
|
-
name: 'userInfo',
|
|
66
|
-
access: Access.get
|
|
67
|
-
})
|
|
68
|
-
static get info(): string {
|
|
69
|
-
return `Name: '${this.name}'; Age: '${this.age}'; Money: '${this.money}';`
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@publicStaticMethod()
|
|
73
|
-
static setName(newName: string): void {
|
|
74
|
-
this.name = newName
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@publicStaticMethod('getUserAge')
|
|
78
|
-
static getAge(): number {
|
|
79
|
-
return this.age
|
|
80
|
-
}
|
|
81
|
-
}
|
|
48
|
+
const instance = providePublic(new MainPublic())
|
|
82
49
|
```
|
|
83
50
|
|
|
84
|
-
|
|
51
|
+
> All experimental decorators can be found in `emr-bridge/exp`
|
|
52
|
+
|
|
53
|
+
### Static methods and properties
|
|
85
54
|
|
|
86
55
|
Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
|
|
87
56
|
|
|
88
57
|
```ts
|
|
89
58
|
// Main process
|
|
90
|
-
|
|
91
|
-
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
|
|
59
|
+
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge/main'
|
|
92
60
|
|
|
93
61
|
class User {
|
|
94
62
|
private static name = 'Name'
|
|
@@ -130,59 +98,11 @@ class User {
|
|
|
130
98
|
|
|
131
99
|
### Methods and properties
|
|
132
100
|
|
|
133
|
-
**Experimental decorators**
|
|
134
|
-
|
|
135
|
-
Use **providePublic** and **publicMethod**/**publicProperty**.
|
|
136
|
-
|
|
137
|
-
Without calling **providePublic**, public methods will not be accessible from renderer.
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
// Main process
|
|
141
|
-
import { providePublic, publicMethod, publicProperty, Access } from 'emr-bridge/exp'
|
|
142
|
-
|
|
143
|
-
class User {
|
|
144
|
-
private name = 'Name'
|
|
145
|
-
private age = 20
|
|
146
|
-
private money = 1000
|
|
147
|
-
|
|
148
|
-
@publicProperty()
|
|
149
|
-
get balance(): string {
|
|
150
|
-
return `${this.money}$`
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
set balance(newBalance: string) {
|
|
154
|
-
this.money = Number(newBalance.split('$')[0])
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
@publicProperty({
|
|
158
|
-
name: 'userInfo',
|
|
159
|
-
access: Access.get
|
|
160
|
-
})
|
|
161
|
-
get info(): string {
|
|
162
|
-
return `Name: '${this.name}'; Age: '${this.age}'; Money: '${this.money}';`
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
@publicMethod()
|
|
166
|
-
setName(newName: string): void {
|
|
167
|
-
this.name = newName
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
@publicMethod('getUserAge')
|
|
171
|
-
getAge(): number {
|
|
172
|
-
return this.age
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const user = providePublic(new User())
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
**New decorators**
|
|
180
|
-
|
|
181
101
|
Use **publicMethod**/**publicProperty**/**publicGetter**/**publicSetter**.
|
|
182
102
|
|
|
183
103
|
```ts
|
|
184
104
|
// Main process
|
|
185
|
-
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge'
|
|
105
|
+
import { publicMethod, publicProperty, publicGetter, publicSetter, Access } from 'emr-bridge/main'
|
|
186
106
|
|
|
187
107
|
class User {
|
|
188
108
|
private name = 'Name'
|
|
@@ -230,7 +150,7 @@ Use **publicFunction** and **publicVariable**.
|
|
|
230
150
|
|
|
231
151
|
```ts
|
|
232
152
|
// Main process
|
|
233
|
-
import { publicFunction, publicVariable } from 'emr-bridge'
|
|
153
|
+
import { publicFunction, publicVariable } from 'emr-bridge/main'
|
|
234
154
|
|
|
235
155
|
publicFunction('sayHello', sayHello)
|
|
236
156
|
publicFunction('getUserName', getName)
|
|
@@ -269,13 +189,13 @@ Accessing an entity outside the specified scope will result in an error being th
|
|
|
269
189
|
// Main process
|
|
270
190
|
|
|
271
191
|
// static and non-static
|
|
272
|
-
import { Scope, Access,
|
|
192
|
+
import { Scope, Access, publicMethod, publicGetter } from 'emr-bridge/main'
|
|
273
193
|
|
|
274
194
|
class User {
|
|
275
195
|
private static age = 20
|
|
276
196
|
private name = 'Name'
|
|
277
197
|
|
|
278
|
-
@
|
|
198
|
+
@publicGetter({
|
|
279
199
|
scope: Scope.preload,
|
|
280
200
|
access: Access.get
|
|
281
201
|
})
|
|
@@ -283,7 +203,7 @@ class User {
|
|
|
283
203
|
return 30
|
|
284
204
|
}
|
|
285
205
|
|
|
286
|
-
@
|
|
206
|
+
@publicMethod({ scope: Scope.preload })
|
|
287
207
|
static getAge(): number {
|
|
288
208
|
return this.age
|
|
289
209
|
}
|
|
@@ -297,10 +217,13 @@ class User {
|
|
|
297
217
|
}
|
|
298
218
|
}
|
|
299
219
|
|
|
300
|
-
|
|
220
|
+
new User()
|
|
221
|
+
```
|
|
301
222
|
|
|
223
|
+
```ts
|
|
224
|
+
// Main process
|
|
302
225
|
// functions and variables
|
|
303
|
-
import { publicFunction, publicVariable, Scope } from 'emr-bridge'
|
|
226
|
+
import { publicFunction, publicVariable, Scope } from 'emr-bridge/main'
|
|
304
227
|
|
|
305
228
|
publicFunction('getName', getName, [Scope.preload])
|
|
306
229
|
publicVariable('count', {
|
|
@@ -326,15 +249,14 @@ Using an entity outside the specified scope _will cause an error_.
|
|
|
326
249
|
|
|
327
250
|
```ts
|
|
328
251
|
// Main process
|
|
329
|
-
|
|
330
252
|
// static and non-static
|
|
331
|
-
import {
|
|
253
|
+
import { publicGetter, Access } from 'emr-bridge/main'
|
|
332
254
|
|
|
333
255
|
class User {
|
|
334
256
|
private static name = 'Name'
|
|
335
257
|
private static surname = 'Surname'
|
|
336
258
|
|
|
337
|
-
@
|
|
259
|
+
@publicGetter({ access: Access.get })
|
|
338
260
|
static get fullName(): string {
|
|
339
261
|
return `${this.name} ${this.surname}`
|
|
340
262
|
}
|
|
@@ -348,10 +270,13 @@ class User {
|
|
|
348
270
|
}
|
|
349
271
|
}
|
|
350
272
|
|
|
351
|
-
|
|
273
|
+
new User()
|
|
274
|
+
```
|
|
352
275
|
|
|
276
|
+
```ts
|
|
277
|
+
// Main process
|
|
353
278
|
// for variables
|
|
354
|
-
import { publicVariable } from 'emr-bridge'
|
|
279
|
+
import { publicVariable } from 'emr-bridge/main'
|
|
355
280
|
|
|
356
281
|
publicVariable('count', {
|
|
357
282
|
// get access
|
|
@@ -369,7 +294,7 @@ let count = 0
|
|
|
369
294
|
|
|
370
295
|
### Access from renderer and preload
|
|
371
296
|
|
|
372
|
-
For _preload_, use **Main** from
|
|
297
|
+
For _preload_, use **Main** from `emr-bridge/preload`
|
|
373
298
|
|
|
374
299
|
```ts
|
|
375
300
|
// Preload process
|
|
@@ -377,13 +302,13 @@ import { Main, provideFromMain } from 'emr-bridge/preload'
|
|
|
377
302
|
|
|
378
303
|
provideFromMain()
|
|
379
304
|
|
|
380
|
-
|
|
305
|
+
interface IProvidedPublic {
|
|
381
306
|
getUserName(): string
|
|
382
307
|
setUserAge(newAge: number): void
|
|
383
308
|
count: number
|
|
384
309
|
}
|
|
385
310
|
|
|
386
|
-
const main = Main.as<
|
|
311
|
+
const main = Main.as<IProvidedPublic>()
|
|
387
312
|
|
|
388
313
|
main.getUserName()
|
|
389
314
|
main.count++
|
|
@@ -396,13 +321,13 @@ For _renderer_, use **Bridge** from 'emr-bridge/renderer'
|
|
|
396
321
|
// Renderer process
|
|
397
322
|
import { Bridge } from 'emr-bridge/renderer'
|
|
398
323
|
|
|
399
|
-
|
|
324
|
+
interface IProvidedPublic {
|
|
400
325
|
getUserName(): string
|
|
401
326
|
setUserAge(newAge: number): void
|
|
402
327
|
count: number
|
|
403
328
|
}
|
|
404
329
|
|
|
405
|
-
const bridge = Bridge.as<
|
|
330
|
+
const bridge = Bridge.as<IProvidedPubic>()
|
|
406
331
|
|
|
407
332
|
bridge.getUserName()
|
|
408
333
|
bridge.count--
|
|
@@ -415,7 +340,7 @@ The library also allows you to pass Promises from main to renderer
|
|
|
415
340
|
|
|
416
341
|
```ts
|
|
417
342
|
// Main process
|
|
418
|
-
import { publicFunction } from 'emr-bridge'
|
|
343
|
+
import { publicFunction } from 'emr-bridge/main'
|
|
419
344
|
|
|
420
345
|
publicFunction('delay1s', () => {
|
|
421
346
|
return new Promise<void>(resolve => {
|
|
@@ -436,3 +361,101 @@ const bridge = Bridge.as<IPublic>()
|
|
|
436
361
|
|
|
437
362
|
bridge.delay1s().then(() => console.log('After 1 second'))
|
|
438
363
|
```
|
|
364
|
+
|
|
365
|
+
### Events system
|
|
366
|
+
|
|
367
|
+
If the event source is the **main** process
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
// Main process
|
|
371
|
+
import { publicMainEvent, publicClassMainEvent } from 'emr-bridge/main'
|
|
372
|
+
|
|
373
|
+
const tickWithReceiver = publicMainEvent('tickWithReceiver', () => (new Date().toTimeString()))
|
|
374
|
+
setInterval(tickWithReceiver, 1000)
|
|
375
|
+
|
|
376
|
+
// Or
|
|
377
|
+
const tick = publicMainEvent('tick')
|
|
378
|
+
setInterval(() => tick(new Date().toTimeString()), 1000)
|
|
379
|
+
|
|
380
|
+
// The passed function receives the argument passed to the event and returns the value passed to the renderer process
|
|
381
|
+
const pay = publicMainEvent('pay', (count: number) => `${count} $`)
|
|
382
|
+
pay(200) // Send the string '200 $' to the renderer process
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
// Or with classes
|
|
386
|
+
class MainPublicEvents {
|
|
387
|
+
@publicClassMainEvent()
|
|
388
|
+
tick() {}
|
|
389
|
+
|
|
390
|
+
@publicClassMainEvent()
|
|
391
|
+
tickWithReceiver() { return new Date().toTimeString() }
|
|
392
|
+
|
|
393
|
+
@publicClassMainEvent()
|
|
394
|
+
pay(count: number) { return `${count} $` }
|
|
395
|
+
}
|
|
396
|
+
const events = new MainPublicEvents()
|
|
397
|
+
setInterval(events.tickWithReceiver, 1000)
|
|
398
|
+
setInterval(() => events.tick(new Date().toTimeString()), 1000)
|
|
399
|
+
events.pay(200)
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
```ts
|
|
403
|
+
// Renderer process
|
|
404
|
+
import { Bridge, MainEvent } from 'emr-bridge/renderer'
|
|
405
|
+
|
|
406
|
+
interface IPublic {
|
|
407
|
+
onTick: MainEvent<string>
|
|
408
|
+
onTickWithReceiver: MainEvent<string>
|
|
409
|
+
onPay: MainEvent<string>
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const bridge = Bridge.as<IPublic>()
|
|
413
|
+
// on + Capitalize<EventName>
|
|
414
|
+
bridge.onTick(time => `Time from tick: ${console.log(time)}`)
|
|
415
|
+
bridge.onTickWithReceiver(time => `Time from receiver: ${console.log(time)}`)
|
|
416
|
+
bridge.onPay(count => `Dollars: ${count}`)
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
If the event source is the **renderer** process
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
// Main process
|
|
423
|
+
import { publicRendererEvent, publicClassRendererEvent, RendererEvent } from 'emr-bridge/main'
|
|
424
|
+
|
|
425
|
+
const onMessage = publicRendererEvent('onMessage'/* or 'message' */)
|
|
426
|
+
onMessage(message => console.log(message))
|
|
427
|
+
|
|
428
|
+
// With receiver
|
|
429
|
+
const onMessageWithReceiver = publicRendererEvent('onMessageWithReceiver', (message: string) => `Message: ${message}`)
|
|
430
|
+
onMessageWithReceiver(message => console.log(message))
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
// Classes
|
|
434
|
+
class RendererPublicEvents {
|
|
435
|
+
@publicClassRendererEvent()
|
|
436
|
+
onMessage!: RendererEvent<string>
|
|
437
|
+
|
|
438
|
+
@publicClassRendererEvent((message: string) => `Message: ${message}`)
|
|
439
|
+
onMessageWithReceiver!: RendererEvent<string>
|
|
440
|
+
}
|
|
441
|
+
const events = new RendererPublicEvents()
|
|
442
|
+
events.onMessage(message => console.log(message))
|
|
443
|
+
events.onMessageWithReceiver(message => console.log(message))
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
// Renderer process
|
|
448
|
+
import { Bridge } from 'emr-bridge/renderer'
|
|
449
|
+
|
|
450
|
+
interface IPublic {
|
|
451
|
+
message(message: string): void
|
|
452
|
+
messageWithReceiver(message: string): void
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const bridge = Bridge.as<IPublic>()
|
|
456
|
+
// Uncapitalize<EventNameWithoutON>
|
|
457
|
+
bridge.message('Message from renderer')
|
|
458
|
+
bridge.messageWithReceiver('Hello, main process')
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
**NOTE**: The transmitted value can be `Promise`. In this case, the receiving party will wait for it to resolve and only then will call the handler
|
package/cjs/enums.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ export declare enum Scope {
|
|
|
9
9
|
export declare enum IPCChannel {
|
|
10
10
|
getPublicInfo = "GET_PUBLIC_INFO",
|
|
11
11
|
functionCall = "FUNCTION_CALL_",
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
mainEventOn = "MAIN_EVENT_ON_",
|
|
13
|
+
mainEventOnce = "MAIN_EVENT_ONCE_",
|
|
14
|
+
mainEventEmit = "MAIN_EVENT_EMIT_",
|
|
15
15
|
propertyGet = "PROPERTY_GET_",
|
|
16
16
|
propertySet = "PROPERTY_SET_",
|
|
17
|
-
promisePostfix = "_PROMISE"
|
|
17
|
+
promisePostfix = "_PROMISE",
|
|
18
|
+
rendererEventEmit = "RENDERER_EMIT_"
|
|
18
19
|
}
|
package/cjs/enums.js
CHANGED
|
@@ -15,10 +15,11 @@ var IPCChannel;
|
|
|
15
15
|
(function (IPCChannel) {
|
|
16
16
|
IPCChannel["getPublicInfo"] = "GET_PUBLIC_INFO";
|
|
17
17
|
IPCChannel["functionCall"] = "FUNCTION_CALL_";
|
|
18
|
-
IPCChannel["
|
|
19
|
-
IPCChannel["
|
|
20
|
-
IPCChannel["
|
|
18
|
+
IPCChannel["mainEventOn"] = "MAIN_EVENT_ON_";
|
|
19
|
+
IPCChannel["mainEventOnce"] = "MAIN_EVENT_ONCE_";
|
|
20
|
+
IPCChannel["mainEventEmit"] = "MAIN_EVENT_EMIT_";
|
|
21
21
|
IPCChannel["propertyGet"] = "PROPERTY_GET_";
|
|
22
22
|
IPCChannel["propertySet"] = "PROPERTY_SET_";
|
|
23
23
|
IPCChannel["promisePostfix"] = "_PROMISE";
|
|
24
|
+
IPCChannel["rendererEventEmit"] = "RENDERER_EMIT_";
|
|
24
25
|
})(IPCChannel = exports.IPCChannel || (exports.IPCChannel = {}));
|
package/cjs/exp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
-
export { providePublic,
|
|
3
|
-
export {
|
|
4
|
-
export type { EventEmitter, EventHandler, EventUnsubscriber,
|
|
2
|
+
export { providePublic, publicClassMainEvent, publicClassRendererEvent, publicMethod, publicProperty, publicStaticMainEvent, publicStaticMethod, publicStaticProperty, publicStaticRendererEvent } from './scripts/oldDecorators';
|
|
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/exp.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicVariable = exports.publicFunction = exports.
|
|
3
|
+
exports.publicVariable = exports.publicRendererEvent = exports.publicMainEvent = exports.publicFunction = exports.publicStaticRendererEvent = exports.publicStaticProperty = exports.publicStaticMethod = exports.publicStaticMainEvent = 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; } });
|
|
7
7
|
var oldDecorators_1 = require("./scripts/oldDecorators");
|
|
8
8
|
Object.defineProperty(exports, "providePublic", { enumerable: true, get: function () { return oldDecorators_1.providePublic; } });
|
|
9
|
-
Object.defineProperty(exports, "
|
|
9
|
+
Object.defineProperty(exports, "publicClassMainEvent", { enumerable: true, get: function () { return oldDecorators_1.publicClassMainEvent; } });
|
|
10
|
+
Object.defineProperty(exports, "publicClassRendererEvent", { enumerable: true, get: function () { return oldDecorators_1.publicClassRendererEvent; } });
|
|
10
11
|
Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return oldDecorators_1.publicMethod; } });
|
|
11
12
|
Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return oldDecorators_1.publicProperty; } });
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
+
Object.defineProperty(exports, "publicStaticMainEvent", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMainEvent; } });
|
|
13
14
|
Object.defineProperty(exports, "publicStaticMethod", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMethod; } });
|
|
14
15
|
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; } });
|
|
15
17
|
var publish_1 = require("./scripts/publish");
|
|
16
|
-
Object.defineProperty(exports, "publicEvent", { enumerable: true, get: function () { return publish_1.publicEvent; } });
|
|
17
18
|
Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_1.publicFunction; } });
|
|
19
|
+
Object.defineProperty(exports, "publicMainEvent", { enumerable: true, get: function () { return publish_1.publicMainEvent; } });
|
|
20
|
+
Object.defineProperty(exports, "publicRendererEvent", { enumerable: true, get: function () { return publish_1.publicRendererEvent; } });
|
|
18
21
|
Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_1.publicVariable; } });
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Access, Scope } from './enums';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { EventEmitter, EventHandler, EventUnsubscriber,
|
|
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/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicVariable = exports.
|
|
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
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; } });
|
|
7
7
|
var newDecorators_1 = require("./scripts/newDecorators");
|
|
8
|
-
Object.defineProperty(exports, "
|
|
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; } });
|
|
9
10
|
Object.defineProperty(exports, "publicGetter", { enumerable: true, get: function () { return newDecorators_1.publicGetter; } });
|
|
10
11
|
Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return newDecorators_1.publicMethod; } });
|
|
11
12
|
Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return newDecorators_1.publicProperty; } });
|
|
12
13
|
Object.defineProperty(exports, "publicSetter", { enumerable: true, get: function () { return newDecorators_1.publicSetter; } });
|
|
13
14
|
var publish_1 = require("./scripts/publish");
|
|
14
|
-
Object.defineProperty(exports, "publicEvent", { enumerable: true, get: function () { return publish_1.publicEvent; } });
|
|
15
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; } });
|
|
16
18
|
Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_1.publicVariable; } });
|
package/cjs/scripts/Bridge.js
CHANGED
|
@@ -20,15 +20,18 @@ const Bridge = (0, provider_1.default)({
|
|
|
20
20
|
callFunction(name, ...args) {
|
|
21
21
|
return provider.provided.functions[name](...args);
|
|
22
22
|
},
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
emitRendererEvent(name, arg) {
|
|
24
|
+
provider.provided.rendererEvents[name](arg);
|
|
25
|
+
},
|
|
26
|
+
handleMainEvent(name, type, handler) {
|
|
27
|
+
return provider.provided.mainEvents[name](type, handler);
|
|
25
28
|
},
|
|
26
29
|
getVariable(name) {
|
|
27
|
-
return provider.provided.properties[name];
|
|
30
|
+
return provider.provided.properties[name].get();
|
|
28
31
|
},
|
|
29
32
|
setVariable(name, value) {
|
|
30
|
-
provider.provided.properties[name]
|
|
31
|
-
return;
|
|
33
|
+
provider.provided.properties[name].set(value);
|
|
34
|
+
return undefined;
|
|
32
35
|
},
|
|
33
36
|
waitPromise(channel) {
|
|
34
37
|
return new Promise((resolve, reject) => {
|
package/cjs/scripts/Main.js
CHANGED
|
@@ -20,19 +20,32 @@ const Main = (0, provider_1.default)({
|
|
|
20
20
|
callFunction(name, ...args) {
|
|
21
21
|
return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.functionCall + name, ...args);
|
|
22
22
|
},
|
|
23
|
-
|
|
23
|
+
handleMainEvent(name, type, handler) {
|
|
24
24
|
const listener = (_, result) => handler(result);
|
|
25
|
-
const emitChannel = enums_1.IPCChannel.
|
|
25
|
+
const emitChannel = enums_1.IPCChannel.mainEventEmit + name;
|
|
26
26
|
if (type === 'on') {
|
|
27
|
-
electron_1.ipcRenderer.send(enums_1.IPCChannel.
|
|
27
|
+
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + name);
|
|
28
28
|
electron_1.ipcRenderer.on(emitChannel, listener);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
electron_1.ipcRenderer.send(enums_1.IPCChannel.
|
|
31
|
+
electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + name);
|
|
32
32
|
electron_1.ipcRenderer.once(emitChannel, listener);
|
|
33
33
|
}
|
|
34
34
|
return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
|
|
35
35
|
},
|
|
36
|
+
emitRendererEvent(name, arg) {
|
|
37
|
+
const emitChannel = enums_1.IPCChannel.rendererEventEmit + name;
|
|
38
|
+
if (arg instanceof Promise) {
|
|
39
|
+
const promiseChannel = emitChannel + enums_1.IPCChannel.promisePostfix;
|
|
40
|
+
electron_1.ipcRenderer.sendSync(emitChannel, { promiseChannel });
|
|
41
|
+
arg
|
|
42
|
+
.then(value => electron_1.ipcRenderer.send(promiseChannel, { value }))
|
|
43
|
+
.catch(reason => electron_1.ipcRenderer.send(promiseChannel, { error: String(reason) }));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
electron_1.ipcRenderer.send(emitChannel, { value: arg });
|
|
47
|
+
}
|
|
48
|
+
},
|
|
36
49
|
getVariable(name) {
|
|
37
50
|
return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + name);
|
|
38
51
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator,
|
|
1
|
+
import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, EventReceiver, IPublishMainEventArgs, IPublishMethodArgs, IPublishPropertyArgs, IPublishRendererEventArgs, PublishGetterArgs, PublishSetterArgs } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Makes the method available for **renderer** and **preload** processes.
|
|
4
4
|
*
|
|
@@ -24,21 +24,63 @@ export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecor
|
|
|
24
24
|
*
|
|
25
25
|
* _only new decorators_
|
|
26
26
|
*/
|
|
27
|
-
export declare function
|
|
27
|
+
export declare function publicClassMainEvent(): ClassMethodDecorator;
|
|
28
28
|
/**
|
|
29
29
|
* Makes the event available for **renderer** and **preload** processes.
|
|
30
30
|
*
|
|
31
31
|
* _only new decorators_
|
|
32
32
|
* @param name - name by which the event will be accessed
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function publicClassMainEvent(name: string): ClassMethodDecorator;
|
|
35
35
|
/**
|
|
36
36
|
* Makes the event available for **renderer** and **preload** processes.
|
|
37
37
|
*
|
|
38
38
|
* _only new decorators_
|
|
39
39
|
* @param args - publish args
|
|
40
40
|
*/
|
|
41
|
-
export declare function
|
|
41
|
+
export declare function publicClassMainEvent(args: IPublishMainEventArgs): ClassMethodDecorator;
|
|
42
|
+
/**
|
|
43
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
44
|
+
*
|
|
45
|
+
* _only new decorators_
|
|
46
|
+
*/
|
|
47
|
+
export declare function publicClassRendererEvent(): ClassPropertyDecorator;
|
|
48
|
+
/**
|
|
49
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
50
|
+
*
|
|
51
|
+
* _only new decorators_
|
|
52
|
+
* @param name - name by which the event will be accessed
|
|
53
|
+
*/
|
|
54
|
+
export declare function publicClassRendererEvent(name: string): ClassPropertyDecorator;
|
|
55
|
+
/**
|
|
56
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
57
|
+
*
|
|
58
|
+
* _only new decorators_
|
|
59
|
+
* @param receiver - linked receiver
|
|
60
|
+
*/
|
|
61
|
+
export declare function publicClassRendererEvent(receiver: EventReceiver): ClassPropertyDecorator;
|
|
62
|
+
/**
|
|
63
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
* @param name - name by which the event will be accessed
|
|
67
|
+
* @param receiver - linked receiver
|
|
68
|
+
*/
|
|
69
|
+
export declare function publicClassRendererEvent(name: string, receiver: EventReceiver): ClassPropertyDecorator;
|
|
70
|
+
/**
|
|
71
|
+
* Makes the event from **renderer** and **preload** available for **main** process.
|
|
72
|
+
*
|
|
73
|
+
* _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
|
+
*
|
|
80
|
+
* _only new decorators_
|
|
81
|
+
* @param args - publish args
|
|
82
|
+
*/
|
|
83
|
+
export declare function publicClassRendererEvent(args: IPublishRendererEventArgs): ClassPropertyDecorator;
|
|
42
84
|
/**
|
|
43
85
|
* Makes the property available for **renderer** and **preload** processes.
|
|
44
86
|
*
|