emr-bridge 1.7.0 → 2.0.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 (159) hide show
  1. package/LICENCE +1 -1
  2. package/README.md +173 -366
  3. package/cjs/entries/index.d.ts +1 -0
  4. package/cjs/entries/index.js +6 -0
  5. package/cjs/entries/main.d.ts +2 -0
  6. package/cjs/entries/main.js +27 -0
  7. package/cjs/entries/preload.d.ts +3 -0
  8. package/cjs/entries/preload.js +29 -0
  9. package/cjs/entries/renderer.d.ts +2 -0
  10. package/cjs/entries/renderer.js +27 -0
  11. package/cjs/enums.d.ts +5 -14
  12. package/cjs/enums.js +12 -23
  13. package/cjs/errors.d.ts +42 -10
  14. package/cjs/errors.js +77 -23
  15. package/cjs/index.d.ts +4 -4
  16. package/cjs/index.js +14 -16
  17. package/cjs/main.d.ts +2 -4
  18. package/cjs/main.js +7 -16
  19. package/cjs/preload.d.ts +3 -3
  20. package/cjs/preload.js +5 -5
  21. package/cjs/renderer.d.ts +2 -2
  22. package/cjs/renderer.js +2 -2
  23. package/cjs/scripts/base-bridge.d.ts +95 -0
  24. package/cjs/scripts/base-bridge.js +128 -0
  25. package/cjs/scripts/bridge.d.ts +3 -3
  26. package/cjs/scripts/bridge.js +51 -39
  27. package/cjs/scripts/helpers/env.d.ts +19 -0
  28. package/cjs/scripts/helpers/env.js +28 -0
  29. package/cjs/scripts/helpers/error-thrower.d.ts +3 -0
  30. package/cjs/scripts/helpers/error-thrower.js +8 -0
  31. package/cjs/scripts/helpers/errors.d.ts +12 -0
  32. package/cjs/scripts/helpers/errors.js +17 -0
  33. package/cjs/scripts/helpers/id.d.ts +9 -0
  34. package/cjs/scripts/helpers/id.js +14 -0
  35. package/cjs/scripts/helpers/index.d.ts +8 -0
  36. package/cjs/scripts/helpers/index.js +22 -0
  37. package/cjs/scripts/helpers/ipc-channel.d.ts +75 -0
  38. package/cjs/scripts/helpers/ipc-channel.js +78 -0
  39. package/cjs/scripts/helpers/ipc-event-in-main.d.ts +24 -0
  40. package/cjs/scripts/helpers/ipc-event-in-main.js +30 -0
  41. package/cjs/scripts/helpers/ipc-result.d.ts +26 -0
  42. package/cjs/scripts/helpers/ipc-result.js +48 -0
  43. package/cjs/scripts/helpers/main-event.d.ts +8 -0
  44. package/cjs/scripts/helpers/main-event.js +15 -0
  45. package/cjs/scripts/helpers/transfer.d.ts +33 -0
  46. package/cjs/scripts/helpers/transfer.js +57 -0
  47. package/cjs/scripts/helpers/web-contents-container.d.ts +12 -0
  48. package/cjs/scripts/helpers/web-contents-container.js +34 -0
  49. package/cjs/scripts/helpers/web-contents-events-container.d.ts +56 -0
  50. package/cjs/scripts/helpers/web-contents-events-container.js +81 -0
  51. package/cjs/scripts/main/publish.d.ts +36 -0
  52. package/cjs/scripts/main/publish.js +186 -0
  53. package/cjs/scripts/preload/bridge.d.ts +27 -0
  54. package/cjs/scripts/preload/bridge.js +85 -0
  55. package/cjs/scripts/preload/provider.d.ts +7 -0
  56. package/cjs/scripts/preload/provider.js +89 -0
  57. package/cjs/scripts/preload-bridge.d.ts +20 -0
  58. package/cjs/scripts/preload-bridge.js +76 -0
  59. package/cjs/scripts/preload-provider.js +37 -53
  60. package/cjs/scripts/provider.d.ts +17 -15
  61. package/cjs/scripts/provider.js +70 -91
  62. package/cjs/scripts/publish.d.ts +19 -18
  63. package/cjs/scripts/publish.js +97 -175
  64. package/cjs/scripts/renderer/bridge.d.ts +6 -0
  65. package/cjs/scripts/renderer/bridge.js +74 -0
  66. package/cjs/scripts/renderer/tunnels.d.ts +171 -0
  67. package/cjs/scripts/renderer/tunnels.js +205 -0
  68. package/cjs/scripts/renderer-tunnels.d.ts +19 -21
  69. package/cjs/scripts/renderer-tunnels.js +53 -58
  70. package/cjs/types.d.ts +189 -64
  71. package/esm/entries/index.d.ts +1 -0
  72. package/esm/entries/index.js +5 -0
  73. package/esm/entries/main.d.ts +2 -0
  74. package/esm/entries/main.js +5 -0
  75. package/esm/entries/preload.d.ts +3 -0
  76. package/esm/entries/preload.js +7 -0
  77. package/esm/entries/renderer.d.ts +2 -0
  78. package/esm/entries/renderer.js +6 -0
  79. package/esm/enums.d.ts +5 -14
  80. package/esm/enums.js +11 -22
  81. package/esm/errors.d.ts +42 -10
  82. package/esm/errors.js +69 -16
  83. package/esm/helpers.d.ts +41 -0
  84. package/esm/helpers.js +96 -0
  85. package/esm/index.d.ts +4 -4
  86. package/esm/index.js +3 -3
  87. package/esm/main.d.ts +2 -4
  88. package/esm/main.js +1 -3
  89. package/esm/preload.d.ts +3 -3
  90. package/esm/preload.js +2 -2
  91. package/esm/renderer.d.ts +2 -2
  92. package/esm/renderer.js +1 -1
  93. package/esm/scripts/base-bridge.d.ts +95 -0
  94. package/esm/scripts/base-bridge.js +125 -0
  95. package/esm/scripts/bridge.d.ts +3 -3
  96. package/esm/scripts/bridge.js +50 -38
  97. package/esm/scripts/helpers/electron-importer.d.ts +4 -0
  98. package/esm/scripts/helpers/electron-importer.js +16 -0
  99. package/esm/scripts/helpers/env.d.ts +19 -0
  100. package/esm/scripts/helpers/env.js +25 -0
  101. package/esm/scripts/helpers/error-thrower.d.ts +3 -0
  102. package/esm/scripts/helpers/error-thrower.js +5 -0
  103. package/esm/scripts/helpers/errors.d.ts +12 -0
  104. package/esm/scripts/helpers/errors.js +14 -0
  105. package/esm/scripts/helpers/id.d.ts +9 -0
  106. package/esm/scripts/helpers/id.js +11 -0
  107. package/esm/scripts/helpers/index.d.ts +8 -0
  108. package/esm/scripts/helpers/index.js +8 -0
  109. package/esm/scripts/helpers/ipc-channel.d.ts +75 -0
  110. package/esm/scripts/helpers/ipc-channel.js +76 -0
  111. package/esm/scripts/helpers/ipc-event-in-main.d.ts +24 -0
  112. package/esm/scripts/helpers/ipc-event-in-main.js +27 -0
  113. package/esm/scripts/helpers/ipc-result.d.ts +26 -0
  114. package/esm/scripts/helpers/ipc-result.js +42 -0
  115. package/esm/scripts/helpers/main-event.d.ts +8 -0
  116. package/esm/scripts/helpers/main-event.js +12 -0
  117. package/esm/scripts/helpers/transfer.d.ts +33 -0
  118. package/esm/scripts/helpers/transfer.js +54 -0
  119. package/esm/scripts/helpers/web-contents-container.d.ts +12 -0
  120. package/esm/scripts/helpers/web-contents-container.js +31 -0
  121. package/esm/scripts/helpers/web-contents-events-container.d.ts +56 -0
  122. package/esm/scripts/helpers/web-contents-events-container.js +78 -0
  123. package/esm/scripts/main/publish.d.ts +36 -0
  124. package/esm/scripts/main/publish.js +179 -0
  125. package/esm/scripts/main.d.ts +3 -3
  126. package/esm/scripts/main.js +43 -41
  127. package/esm/scripts/preload/bridge.d.ts +27 -0
  128. package/esm/scripts/preload/bridge.js +77 -0
  129. package/esm/scripts/preload/provider.d.ts +7 -0
  130. package/esm/scripts/preload/provider.js +84 -0
  131. package/esm/scripts/preload-bridge.d.ts +20 -0
  132. package/esm/scripts/preload-bridge.js +68 -0
  133. package/esm/scripts/preload-provider.js +35 -51
  134. package/esm/scripts/provider.d.ts +17 -15
  135. package/esm/scripts/provider.js +70 -91
  136. package/esm/scripts/publish.d.ts +19 -18
  137. package/esm/scripts/publish.js +89 -162
  138. package/esm/scripts/renderer/bridge.d.ts +6 -0
  139. package/esm/scripts/renderer/bridge.js +69 -0
  140. package/esm/scripts/renderer/tunnels.d.ts +171 -0
  141. package/esm/scripts/renderer/tunnels.js +203 -0
  142. package/esm/scripts/renderer-tunnels.d.ts +19 -21
  143. package/esm/scripts/renderer-tunnels.js +53 -55
  144. package/esm/types.d.ts +189 -64
  145. package/package.json +24 -41
  146. package/cjs/exp.d.ts +0 -4
  147. package/cjs/exp.js +0 -19
  148. package/cjs/scripts/main.d.ts +0 -8
  149. package/cjs/scripts/main.js +0 -72
  150. package/cjs/scripts/new-decorators.d.ts +0 -150
  151. package/cjs/scripts/new-decorators.js +0 -141
  152. package/cjs/scripts/old-decorators.d.ts +0 -185
  153. package/cjs/scripts/old-decorators.js +0 -132
  154. package/esm/exp.d.ts +0 -4
  155. package/esm/exp.js +0 -3
  156. package/esm/scripts/new-decorators.d.ts +0 -150
  157. package/esm/scripts/new-decorators.js +0 -132
  158. package/esm/scripts/old-decorators.d.ts +0 -185
  159. package/esm/scripts/old-decorators.js +0 -122
@@ -1,13 +1,15 @@
1
- import electron from 'electron';
2
- import { IPCChannel } from '../enums';
3
- import IPCTunnel from './renderer-tunnels';
1
+ import { contextBridge, ipcRenderer } from 'electron';
2
+ import { IpcChannel } from '../enums.js';
3
+ import { NotProvidedFromMain, TryProvideFromMainInMain, TryProvideFromMainInRenderer } from '../errors.js';
4
+ import { ErrorThrower } from './helpers/index.js';
5
+ import IPCTunnel from './renderer-tunnels.js';
4
6
  /** Выбрасывает ошибку если используется не в том процессе */
5
- let mayThrowError = () => { };
6
- if (typeof window === 'undefined') {
7
- mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in main process.'); };
7
+ let canThrowError = () => { };
8
+ if (!ipcRenderer) {
9
+ canThrowError = ErrorThrower.throws(TryProvideFromMainInMain);
8
10
  }
9
- else if (!('contextBridge' in electron)) {
10
- mayThrowError = () => { throw new Error('"provideFromMain" is unavailable in renderer process.'); };
11
+ else if (!contextBridge) {
12
+ canThrowError = ErrorThrower.throws(TryProvideFromMainInRenderer);
11
13
  }
12
14
  /**
13
15
  * Sets access to main from renderer
@@ -15,21 +17,32 @@ else if (!('contextBridge' in electron)) {
15
17
  * @param contextIsolation - _default_: `true`
16
18
  */
17
19
  function provideFromMain(contextIsolation = true) {
18
- mayThrowError();
19
- const { contextBridge, ipcRenderer } = electron;
20
- const info = ipcRenderer.sendSync(IPCChannel.getPublicInfo);
20
+ canThrowError();
21
+ const entitiesInfo = ipcRenderer.sendSync(IpcChannel.getPublicInfo);
22
+ if (!entitiesInfo) {
23
+ throw new NotProvidedFromMain();
24
+ }
21
25
  const provider = {
22
- getInfo: () => info,
23
- waitPromise(channel, resolve, reject, secret) {
24
- new IPCTunnel.Promise(channel).wait(secret)
26
+ getEntitiesInfo: () => entitiesInfo,
27
+ waitPromise(channel, resolve, reject, id) {
28
+ new IPCTunnel.Promise(channel).wait(id)
25
29
  .then(resolve)
26
30
  .catch(reject);
27
31
  },
28
- provided: {
32
+ entities: {
29
33
  functions: getFunctions(),
30
- properties: getProperties(),
31
- mainEvents: getMainEvents(),
32
- rendererEvents: getRendererEvents(),
34
+ variables: getProperties(),
35
+ events: {
36
+ emit(name, value) {
37
+ new IPCTunnel.Event(name).emit(value);
38
+ },
39
+ on(name, listener) {
40
+ return new IPCTunnel.Event(name).on(listener);
41
+ },
42
+ once(name, listener) {
43
+ return new IPCTunnel.Event(name).once(listener);
44
+ }
45
+ }
33
46
  }
34
47
  };
35
48
  if (contextIsolation) {
@@ -40,16 +53,16 @@ function provideFromMain(contextIsolation = true) {
40
53
  }
41
54
  function getFunctions() {
42
55
  const result = {};
43
- for (const name of info.functions) {
44
- result[name] = (secret, args) => {
45
- return new IPCTunnel.Function(name).call({ args, secret });
56
+ for (const name of entitiesInfo.functions) {
57
+ result[name] = (id, args) => {
58
+ return new IPCTunnel.Function(name).call({ args, id: id });
46
59
  };
47
60
  }
48
61
  return result;
49
62
  }
50
63
  function getProperties() {
51
64
  const result = {};
52
- for (const name of info.properties) {
65
+ for (const name of entitiesInfo.variables) {
53
66
  const tunnel = new IPCTunnel.Property(name);
54
67
  result[name] = {
55
68
  get: () => tunnel.get(),
@@ -58,34 +71,5 @@ function provideFromMain(contextIsolation = true) {
58
71
  }
59
72
  return result;
60
73
  }
61
- function getMainEvents() {
62
- const result = {};
63
- for (const name of info.mainEvents) {
64
- result[name] = (type, handler) => {
65
- const tunnel = new IPCTunnel.MainEvent(name);
66
- if (type === 'on')
67
- return tunnel.on(handler);
68
- else
69
- return tunnel.once(handler);
70
- };
71
- }
72
- return result;
73
- }
74
- function getRendererEvents() {
75
- const result = {};
76
- for (const name of info.rendererEvents) {
77
- result[name] = (arg) => {
78
- const tunnel = new IPCTunnel.RendererEvent(name);
79
- if (arg instanceof Promise) {
80
- arg.then(value => tunnel.emit(value))
81
- .catch(reason => tunnel.error(String(reason)));
82
- }
83
- else {
84
- tunnel.emit(arg);
85
- }
86
- };
87
- }
88
- return result;
89
- }
90
74
  }
91
75
  export default provideFromMain;
@@ -1,21 +1,23 @@
1
- import { Scope } from '../enums';
2
- import type { EventHandler, EventUnsubscriber, IPCResult, Info, Target } from '../types';
3
- export default abstract class Provider implements Target {
4
- protected abstract info: Info;
5
- protected abstract scope: Scope;
6
- protected abstract getVariable(name: string): IPCResult;
7
- protected abstract setVariable(name: string, value: any): IPCResult;
8
- protected abstract callFunction(name: string, secret: number, args: any[]): IPCResult;
9
- protected abstract waitPromise(channel: string, secret?: number): Promise<any>;
10
- protected abstract emitRendererEvent(name: string, arg: any): void;
11
- protected abstract handleMainEvent(name: string, type: 'on' | 'once', handler: EventHandler<IPCResult>): EventUnsubscriber;
12
- as<T>(): T;
1
+ import type { EventListener, EventUnsubscribe, IBridge, IEntitiesInfo, IHasSnapshot, IResult } from '../types.js';
2
+ export default abstract class Provider implements IBridge {
3
+ protected abstract entitiesInfo: IEntitiesInfo;
13
4
  protected readonly target: any;
5
+ as<TTarget>(): IBridge & TTarget;
6
+ emit(name: string, arg: any): void;
7
+ on<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
8
+ once<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
9
+ call<TFunc extends (...args: any[]) => InstanceType<TClass>, TClass extends {
10
+ new (): IHasSnapshot;
11
+ }>(func: TFunc, Class: TClass, args: Parameters<TFunc>): InstanceType<TClass>;
12
+ protected abstract getVariable<T = any>(name: string): IResult<T>;
13
+ protected abstract setVariable<T>(name: string, value: T): IResult<T>;
14
+ protected abstract callFunction<T = any>(name: string, id: string, args: any[]): IResult<T>;
15
+ protected abstract waitPromise<T = any>(channel: string, id?: string): Promise<T>;
16
+ protected abstract emitEvent(name: string, arg: any): void;
17
+ protected abstract handleEvent(name: string, type: 'on' | 'once', handler: EventListener<IResult>): EventUnsubscribe;
14
18
  protected init(): void;
15
- protected errorHandler(error: string, channel: string): never;
19
+ protected handleError(channel: string, error?: string): void | never;
16
20
  protected initFunctions(): void;
17
- protected initRendererEvents(): void;
18
- protected initMainEvents(): void;
19
21
  protected initProperties(): void;
20
22
  protected define(name: string, attrs?: {
21
23
  get?: () => any;
@@ -1,113 +1,92 @@
1
- import { Access } from '../enums';
2
- import { NoGetAccessError, NoSetAccessError, NotProvidedIntoScopeError, TrySetReadonlyError } from '../errors';
1
+ import { NoSetAccessError, TrySetReadonlyError } from '../errors.js';
2
+ import { ErrorThrower, Id, Transfer } from './helpers/index.js';
3
3
  export default class Provider {
4
- as() { return this.target; }
5
- target = {};
4
+ target = {
5
+ as: () => this.as(),
6
+ emit: (...args) => this.emit(...args),
7
+ on: (...args) => this.on(...args),
8
+ once: (...args) => this.once(...args),
9
+ call: (...args) => this.call(...args)
10
+ };
11
+ as() {
12
+ return this.target;
13
+ }
14
+ emit(name, arg) {
15
+ this.emitEvent(name, arg);
16
+ }
17
+ on(name, listener) {
18
+ return this.handleEvent(name, 'on', ({ value, error }) => {
19
+ this.handleError(`event: ${name}`, error);
20
+ listener(value);
21
+ });
22
+ }
23
+ once(name, listener) {
24
+ return this.handleEvent(name, 'once', ({ value, error }) => {
25
+ this.handleError(`event: ${name}`, error);
26
+ listener(value);
27
+ });
28
+ }
29
+ call(func, Class, args) {
30
+ const value = func(...args);
31
+ if (Transfer.isSnapshotValue(value)) {
32
+ return Transfer.getFromSnapshot(value, Class);
33
+ }
34
+ return value;
35
+ }
6
36
  init() {
7
37
  this.initFunctions();
8
38
  this.initProperties();
9
- this.initMainEvents();
10
- this.initRendererEvents();
11
39
  }
12
- errorHandler(error, channel) {
40
+ handleError(channel, error) {
41
+ if (!error) {
42
+ return;
43
+ }
13
44
  throw new Error(`Error on ${channel}.\n${error}`.replace('Error: ', ''));
14
45
  }
15
46
  initFunctions() {
16
- for (const name of this.info.functions) {
47
+ for (const name of this.entitiesInfo.functions) {
17
48
  this.define(name, {
18
49
  value: (...args) => {
19
- const secret = Math.random();
20
- const { error, promiseChannel, value } = this.callFunction(name, secret, args);
21
- if (error) {
22
- this.errorHandler(error, name);
23
- }
24
- if (promiseChannel)
25
- return this.waitPromise(promiseChannel, secret);
26
- return value;
27
- }
28
- });
29
- }
30
- }
31
- initRendererEvents() {
32
- for (const name of this.info.rendererEvents) {
33
- this.define(name, {
34
- value: (arg) => {
35
- this.emitRendererEvent(name, arg);
36
- }
37
- });
38
- }
39
- }
40
- initMainEvents() {
41
- for (const name of this.info.mainEvents) {
42
- const eventNameOn = `on${name[0].toUpperCase()}${name.slice(1)}`;
43
- const eventNameOnce = `once${name[0].toUpperCase()}${name.slice(1)}`;
44
- this.define(eventNameOn, {
45
- value: (handler) => {
46
- return this.handleMainEvent(name, 'on', ({ error, value }) => {
47
- if (error) {
48
- this.errorHandler(error, name);
49
- }
50
- handler(value);
51
- });
52
- }
53
- });
54
- this.define(eventNameOnce, {
55
- value: (handler) => {
56
- return this.handleMainEvent(name, 'once', ({ error, value }) => {
57
- if (error) {
58
- this.errorHandler(error, name);
59
- }
60
- handler(value);
61
- });
50
+ const id = Id.generate();
51
+ const preparedArgs = args.map(arg => Transfer.toTransferable(arg));
52
+ const { error, promiseChannel, value } = this.callFunction(name, id, preparedArgs);
53
+ this.handleError(name, error);
54
+ return promiseChannel
55
+ ? this.waitPromise(promiseChannel, id)
56
+ : value;
62
57
  }
63
58
  });
64
59
  }
65
60
  }
66
61
  initProperties() {
67
- for (const name of this.info.properties) {
62
+ for (const name of this.entitiesInfo.variables) {
68
63
  this.define(name, {
69
- get: this.info.accesses.get(name).has(Access.get)
70
- ? () => {
71
- const { error, value } = this.getVariable(name);
72
- if (error) {
73
- this.errorHandler(error, name);
74
- }
75
- return value;
76
- }
77
- : () => { throw new NoGetAccessError(name); },
78
- set: this.info.accesses.get(name).has(Access.set)
79
- ? (value) => {
80
- const { error } = this.setVariable(name, value);
81
- if (error) {
82
- this.errorHandler(error, name);
83
- }
84
- }
85
- : () => { throw new NoSetAccessError(name); }
64
+ get: () => {
65
+ const { error, value } = this.getVariable(name);
66
+ this.handleError(name, error);
67
+ return value;
68
+ },
69
+ set: (value) => {
70
+ const { error } = this.setVariable(name, value);
71
+ this.handleError(name, error);
72
+ }
86
73
  });
87
74
  }
88
75
  }
89
76
  define(name, attrs) {
90
- let descriptor;
91
- if (!this.info.scopes.get(name).has(this.scope)) {
92
- descriptor = {
93
- get: () => { throw new NotProvidedIntoScopeError(name, this.scope); },
94
- set: () => { throw new NotProvidedIntoScopeError(name, this.scope); }
95
- };
96
- }
97
- else if (attrs?.value) {
98
- descriptor = {
99
- get: () => attrs.value,
100
- set: () => { throw new TrySetReadonlyError(name); },
101
- enumerable: true
102
- };
103
- }
104
- else {
105
- descriptor = {
106
- get: attrs?.get || (() => { throw new NoSetAccessError(name); }),
107
- set: attrs?.set || (() => { throw new TrySetReadonlyError(name); }),
108
- enumerable: true
109
- };
110
- }
111
- Object.defineProperty(this.target, name, descriptor);
77
+ const hasValue = Boolean(attrs?.value);
78
+ const defaultDescriptor = {
79
+ get: () => attrs.value,
80
+ set: ErrorThrower.throws(TrySetReadonlyError, name),
81
+ enumerable: true
82
+ };
83
+ const noValueDescriptor = {
84
+ get: attrs?.get || ErrorThrower.throws(NoSetAccessError, name),
85
+ set: attrs?.set || ErrorThrower.throws(TrySetReadonlyError, name),
86
+ enumerable: true
87
+ };
88
+ Object.defineProperty(this.target, name, hasValue
89
+ ? defaultDescriptor
90
+ : noValueDescriptor);
112
91
  }
113
92
  }
@@ -1,21 +1,24 @@
1
- import { Access, Scope } from '../enums';
2
- import type { PublicFunction, PublicProperty, RendererEvent } from '../types';
1
+ import type { EventListener, EventUnsubscribe, IHasSnapshot, IPublicProperty, PublicFunction } from '../types.js';
3
2
  /**
4
- * Makes the event from **main** available for **renderer** and **preload** processes.
3
+ * Call the event from **main** process.
5
4
  *
6
- * @param name - name by which the event will be accessed
7
- * @param procFn - function of processing before sending the event
8
- * @param scopes - event scopes
5
+ * @param name - event name
9
6
  */
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;
7
+ export declare function emitEvent(name: string, value?: any): void;
11
8
  /**
12
- * Makes the event from **renderer** and **preload** available for **main** process.
9
+ * Handle event from **main** process.
13
10
  *
14
- * @param name - name by which the event will be accessed
15
- * @param procFn - processing function before calling handlers
16
- * @param scopes - event scopes
11
+ * @param name - event name
12
+ * @param listener - event handler
17
13
  */
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>;
14
+ export declare function on<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
15
+ /**
16
+ * Handle event from **main** process.
17
+ *
18
+ * @param name - event name
19
+ * @param listener - event handler
20
+ */
21
+ export declare function once<TValue = any>(name: string, listener: EventListener<TValue>): EventUnsubscribe;
19
22
  /**
20
23
  * Makes the function available for **renderer** and **preload** processes.
21
24
  *
@@ -23,9 +26,10 @@ export declare function publicRendererEvent<In = void, Out = In, ProcFn extends
23
26
  *
24
27
  * @param name - name by which the function will be accessed
25
28
  * @param func - linked function
26
- * @param scopes - function scopes
27
29
  */
28
- export declare function publicFunction<F extends PublicFunction>(name: string, func: F, scopes?: Scope[]): void;
30
+ export declare function publicFunction<TFunc extends PublicFunction>(name: string, func: TFunc, receives?: {
31
+ new (): IHasSnapshot;
32
+ }[]): void;
29
33
  /**
30
34
  * Makes the function available for **renderer** and **preload** processes.
31
35
  *
@@ -33,8 +37,5 @@ export declare function publicFunction<F extends PublicFunction>(name: string, f
33
37
  *
34
38
  * @param name - name by which the variable will be accessed
35
39
  * @param value - variable getter/setter
36
- * @param scopes - variable scopes
37
40
  */
38
- export declare function publicVariable<T>(name: string, value: PublicProperty<T>, scopes?: Scope[]): void;
39
- export declare function addScope(key: string, scope: Scope): void;
40
- export declare function addAccess(key: string, access: Access): void;
41
+ export declare function publicVariable<T>(name: string, value: IPublicProperty<T>): void;