emr-bridge 1.2.2 → 1.4.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.
Files changed (52) hide show
  1. package/LICENCE +1 -1
  2. package/README.md +136 -113
  3. package/cjs/enums.d.ts +5 -1
  4. package/cjs/enums.js +4 -0
  5. package/cjs/exp.d.ts +4 -0
  6. package/cjs/exp.js +21 -0
  7. package/cjs/index.d.ts +3 -4
  8. package/cjs/index.js +5 -7
  9. package/cjs/scripts/Bridge.js +6 -0
  10. package/cjs/scripts/Main.js +26 -0
  11. package/cjs/scripts/newDecorators.d.ts +63 -1
  12. package/cjs/scripts/newDecorators.js +50 -5
  13. package/cjs/scripts/oldDecorators.d.ts +167 -1
  14. package/cjs/scripts/oldDecorators.js +62 -1
  15. package/cjs/scripts/preloadProvider.js +37 -1
  16. package/cjs/scripts/provider.js +58 -1
  17. package/cjs/scripts/publish.d.ts +15 -1
  18. package/cjs/scripts/publish.js +96 -1
  19. package/cjs/types.d.ts +21 -0
  20. package/{lib → esm}/enums.d.ts +5 -1
  21. package/{lib → esm}/enums.js +4 -0
  22. package/esm/exp.d.ts +4 -0
  23. package/esm/exp.js +3 -0
  24. package/esm/index.d.ts +4 -0
  25. package/esm/index.js +3 -0
  26. package/{lib → esm}/scripts/Bridge.js +6 -0
  27. package/esm/scripts/Main.js +61 -0
  28. package/{lib → esm}/scripts/newDecorators.d.ts +63 -1
  29. package/{lib → esm}/scripts/newDecorators.js +48 -5
  30. package/esm/scripts/oldDecorators.d.ts +289 -0
  31. package/{lib → esm}/scripts/oldDecorators.js +58 -1
  32. package/esm/scripts/preloadProvider.js +87 -0
  33. package/{lib → esm}/scripts/provider.js +58 -1
  34. package/{lib → esm}/scripts/publish.d.ts +15 -1
  35. package/esm/scripts/publish.js +194 -0
  36. package/{lib → esm}/types.d.ts +21 -0
  37. package/package.json +29 -13
  38. package/lib/index.d.ts +0 -5
  39. package/lib/index.js +0 -4
  40. package/lib/scripts/Main.js +0 -35
  41. package/lib/scripts/oldDecorators.d.ts +0 -123
  42. package/lib/scripts/preloadProvider.js +0 -51
  43. package/lib/scripts/publish.js +0 -101
  44. /package/{lib → esm}/preload.d.ts +0 -0
  45. /package/{lib → esm}/preload.js +0 -0
  46. /package/{lib → esm}/renderer.d.ts +0 -0
  47. /package/{lib → esm}/renderer.js +0 -0
  48. /package/{lib → esm}/scripts/Bridge.d.ts +0 -0
  49. /package/{lib → esm}/scripts/Main.d.ts +0 -0
  50. /package/{lib → esm}/scripts/preloadProvider.d.ts +0 -0
  51. /package/{lib → esm}/scripts/provider.d.ts +0 -0
  52. /package/{lib → esm}/types.js +0 -0
package/LICENCE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 VerZsuT
3
+ Copyright (c) 2023 VerZsuT
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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,6 +24,8 @@ npm i emr-bridge
23
24
 
24
25
  ## Usage
25
26
 
27
+ _If you need CommonJS modules, then use `emr-bridge/cjs`_
28
+
26
29
  There are three ways to use
27
30
 
28
31
  **IMPORTANT**: In any of the cases, you need to insert this code into preload
@@ -31,64 +34,29 @@ There are three ways to use
31
34
  // Preload process
32
35
  import { provideFromMain } from 'emr-bridge/preload'
33
36
 
34
- const contextIsolation = true
35
-
36
- provideFromMain(contextIsolation)
37
+ provideFromMain(true /* context isolation */)
37
38
  ```
38
39
 
39
- ### Static methods and properties
40
-
41
- **Experimental decorators**
42
-
43
- Use **publicStaticMethodExp**/**publicStaticPropertyExp**.
40
+ **IMPORTANT**: To use experimental non-static decorators, it is required to wrap the creation of a class instance in the `providePublic` function
44
41
 
45
- ```ts
42
+ ```js
46
43
  // Main process
44
+ import { providePublic } from 'emr-bridge/main/exp'
47
45
 
48
- import { publicStaticMethodExp, publicStaticPropertyExp, Access } from 'emr-bridge'
46
+ class MainPublic { /*...*/ }
49
47
 
50
- class User {
51
- private static name = 'Name'
52
- private static age = 20
53
- private static money = 1000
54
-
55
- @publicStaticPropertyExp('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
- @publicStaticPropertyExp({
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
- @publicStaticMethodExp()
73
- static setName(newName: string): void {
74
- this.name = newName
75
- }
76
-
77
- @publicStaticMethodExp('getUserAge')
78
- static getAge(): number {
79
- return this.age
80
- }
81
- }
48
+ const instance = providePublic(new MainPublic())
82
49
  ```
83
50
 
84
- **New decorators**
51
+ **NOTE**: 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 **publicMethodExp**/**publicPropertyExp**.
136
-
137
- Without calling **providePublic**, public methods will not be accessible from renderer.
138
-
139
- ```ts
140
- // Main process
141
- import { providePublic, publicMethodExp, publicPropertyExp, Access } from 'emr-bridge'
142
-
143
- class User {
144
- private name = 'Name'
145
- private age = 20
146
- private money = 1000
147
-
148
- @publicPropertyExp()
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
- @publicPropertyExp({
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
- @publicMethodExp()
166
- setName(newName: string): void {
167
- this.name = newName
168
- }
169
-
170
- @publicMethodExp('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, providePublic, publicStaticMethodExp, publicMethodExp, publicPropertyExp } from 'emr-bridge'
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
- @publicPropertyExp({
198
+ @publicGetter({
279
199
  scope: Scope.preload,
280
200
  access: Access.get
281
201
  })
@@ -283,12 +203,12 @@ class User {
283
203
  return 30
284
204
  }
285
205
 
286
- @publicStaticMethodExp({ scope: Scope.preload })
206
+ @publicMethod({ scope: Scope.preload })
287
207
  static getAge(): number {
288
208
  return this.age
289
209
  }
290
210
 
291
- @publicMethodExp({
211
+ @publicMethod({
292
212
  name: 'getUserName',
293
213
  scope: Scope.renderer
294
214
  })
@@ -297,10 +217,13 @@ class User {
297
217
  }
298
218
  }
299
219
 
300
- providePublic(new User())
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,20 +249,19 @@ 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 { publicStaticPropertyExp, publicPropertyExp, providePublic, Access } from 'emr-bridge'
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
- @publicStaticPropertyExp({ access: Access.get })
259
+ @publicGetter({ access: Access.get })
338
260
  static get fullName(): string {
339
261
  return `${this.name} ${this.surname}`
340
262
  }
341
263
 
342
- @publicPropertyExp({
264
+ @publicProperty({
343
265
  name: 'userAge',
344
266
  access: Access.get
345
267
  })
@@ -348,10 +270,13 @@ class User {
348
270
  }
349
271
  }
350
272
 
351
- providePublic(new User())
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 'emr-bridge/preload'
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
- type ProvidedPublic = {
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<ProvidedPublic>()
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
- type ProvidedPublic = {
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<ProvidedPubic>()
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,7 +9,11 @@ export declare enum Scope {
9
9
  export declare enum IPCChannel {
10
10
  getPublicInfo = "GET_PUBLIC_INFO",
11
11
  functionCall = "FUNCTION_CALL_",
12
+ mainEventOn = "MAIN_EVENT_ON_",
13
+ mainEventOnce = "MAIN_EVENT_ONCE_",
14
+ mainEventEmit = "MAIN_EVENT_EMIT_",
12
15
  propertyGet = "PROPERTY_GET_",
13
16
  propertySet = "PROPERTY_SET_",
14
- promisePostfix = "_PROMISE"
17
+ promisePostfix = "_PROMISE",
18
+ rendererEventEmit = "RENDERER_EMIT_"
15
19
  }
package/cjs/enums.js CHANGED
@@ -15,7 +15,11 @@ var IPCChannel;
15
15
  (function (IPCChannel) {
16
16
  IPCChannel["getPublicInfo"] = "GET_PUBLIC_INFO";
17
17
  IPCChannel["functionCall"] = "FUNCTION_CALL_";
18
+ IPCChannel["mainEventOn"] = "MAIN_EVENT_ON_";
19
+ IPCChannel["mainEventOnce"] = "MAIN_EVENT_ONCE_";
20
+ IPCChannel["mainEventEmit"] = "MAIN_EVENT_EMIT_";
18
21
  IPCChannel["propertyGet"] = "PROPERTY_GET_";
19
22
  IPCChannel["propertySet"] = "PROPERTY_SET_";
20
23
  IPCChannel["promisePostfix"] = "_PROMISE";
24
+ IPCChannel["rendererEventEmit"] = "RENDERER_EMIT_";
21
25
  })(IPCChannel = exports.IPCChannel || (exports.IPCChannel = {}));
package/cjs/exp.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { Access, Scope } from './enums';
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 ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ 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 oldDecorators_1 = require("./scripts/oldDecorators");
8
+ Object.defineProperty(exports, "providePublic", { enumerable: true, get: function () { return oldDecorators_1.providePublic; } });
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; } });
11
+ Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return oldDecorators_1.publicMethod; } });
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
+ Object.defineProperty(exports, "publicStaticMethod", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMethod; } });
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; } });
17
+ var publish_1 = require("./scripts/publish");
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; } });
21
+ Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_1.publicVariable; } });
package/cjs/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { Access, Scope } from './enums';
2
- export { publicGetter, publicMethod, publicProperty, publicSetter } from './scripts/newDecorators';
3
- export { providePublic, publicMethod as publicMethodExp, publicProperty as publicPropertyExp, publicStaticMethod as publicStaticMethodExp, publicStaticProperty as publicStaticPropertyExp } from './scripts/oldDecorators';
4
- export { publicFunction, publicVariable } from './scripts/publish';
5
- export type { IPublishMethodArgs, IPublishPropertyArgs, PublicFunction, PublicProperty } from './types';
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,20 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicVariable = exports.publicFunction = exports.publicStaticPropertyExp = exports.publicStaticMethodExp = exports.publicPropertyExp = exports.publicMethodExp = exports.providePublic = exports.publicSetter = exports.publicProperty = exports.publicMethod = exports.publicGetter = exports.Scope = exports.Access = void 0;
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, "publicClassMainEvent", { enumerable: true, get: function () { return newDecorators_1.publicClassMainEvent; } });
9
+ Object.defineProperty(exports, "publicClassRendererEvent", { enumerable: true, get: function () { return newDecorators_1.publicClassRendererEvent; } });
8
10
  Object.defineProperty(exports, "publicGetter", { enumerable: true, get: function () { return newDecorators_1.publicGetter; } });
9
11
  Object.defineProperty(exports, "publicMethod", { enumerable: true, get: function () { return newDecorators_1.publicMethod; } });
10
12
  Object.defineProperty(exports, "publicProperty", { enumerable: true, get: function () { return newDecorators_1.publicProperty; } });
11
13
  Object.defineProperty(exports, "publicSetter", { enumerable: true, get: function () { return newDecorators_1.publicSetter; } });
12
- var oldDecorators_1 = require("./scripts/oldDecorators");
13
- Object.defineProperty(exports, "providePublic", { enumerable: true, get: function () { return oldDecorators_1.providePublic; } });
14
- Object.defineProperty(exports, "publicMethodExp", { enumerable: true, get: function () { return oldDecorators_1.publicMethod; } });
15
- Object.defineProperty(exports, "publicPropertyExp", { enumerable: true, get: function () { return oldDecorators_1.publicProperty; } });
16
- Object.defineProperty(exports, "publicStaticMethodExp", { enumerable: true, get: function () { return oldDecorators_1.publicStaticMethod; } });
17
- Object.defineProperty(exports, "publicStaticPropertyExp", { enumerable: true, get: function () { return oldDecorators_1.publicStaticProperty; } });
18
14
  var publish_1 = require("./scripts/publish");
19
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; } });
20
18
  Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_1.publicVariable; } });
@@ -20,6 +20,12 @@ const Bridge = (0, provider_1.default)({
20
20
  callFunction(name, ...args) {
21
21
  return provider.provided.functions[name](...args);
22
22
  },
23
+ emitRendererEvent(name, arg) {
24
+ provider.provided.rendererEvents[name](arg);
25
+ },
26
+ handleMainEvent(name, type, handler) {
27
+ return provider.provided.mainEvents[name](type, handler);
28
+ },
23
29
  getVariable(name) {
24
30
  return provider.provided.properties[name];
25
31
  },
@@ -20,6 +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
+ handleMainEvent(name, type, handler) {
24
+ const listener = (_, result) => handler(result);
25
+ const emitChannel = enums_1.IPCChannel.mainEventEmit + name;
26
+ if (type === 'on') {
27
+ electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOn + name);
28
+ electron_1.ipcRenderer.on(emitChannel, listener);
29
+ }
30
+ else {
31
+ electron_1.ipcRenderer.send(enums_1.IPCChannel.mainEventOnce + name);
32
+ electron_1.ipcRenderer.once(emitChannel, listener);
33
+ }
34
+ return () => electron_1.ipcRenderer.removeListener(emitChannel, listener);
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
+ },
23
49
  getVariable(name) {
24
50
  return electron_1.ipcRenderer.sendSync(enums_1.IPCChannel.propertyGet + name);
25
51
  },
@@ -1,4 +1,4 @@
1
- import type { ClassGetterDecorator, ClassMethodDecorator, ClassPropertyDecorator, ClassSetterDecorator, IPublishMethodArgs, IPublishPropertyArgs, PublishGetterArgs, PublishSetterArgs } from '../types';
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
  *
@@ -19,6 +19,68 @@ export declare function publicMethod(name: string): ClassMethodDecorator;
19
19
  * @param args - publish args
20
20
  */
21
21
  export declare function publicMethod(args: IPublishMethodArgs): ClassMethodDecorator;
22
+ /**
23
+ * Makes the event available for **renderer** and **preload** processes.
24
+ *
25
+ * _only new decorators_
26
+ */
27
+ export declare function publicClassMainEvent(): ClassMethodDecorator;
28
+ /**
29
+ * Makes the event available for **renderer** and **preload** processes.
30
+ *
31
+ * _only new decorators_
32
+ * @param name - name by which the event will be accessed
33
+ */
34
+ export declare function publicClassMainEvent(name: string): ClassMethodDecorator;
35
+ /**
36
+ * Makes the event available for **renderer** and **preload** processes.
37
+ *
38
+ * _only new decorators_
39
+ * @param args - publish args
40
+ */
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;
22
84
  /**
23
85
  * Makes the property available for **renderer** and **preload** processes.
24
86
  *