emr-bridge 2.0.0 → 2.0.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.
Files changed (72) hide show
  1. package/README.md +2 -2
  2. package/cjs/scripts/helpers/web-contents-events-container.d.ts +2 -7
  3. package/cjs/scripts/helpers/web-contents-events-container.js +14 -20
  4. package/cjs/scripts/main/publish.d.ts +2 -2
  5. package/cjs/scripts/main/publish.js +3 -5
  6. package/esm/scripts/helpers/web-contents-events-container.d.ts +2 -7
  7. package/esm/scripts/helpers/web-contents-events-container.js +14 -20
  8. package/esm/scripts/main/publish.d.ts +2 -2
  9. package/esm/scripts/main/publish.js +3 -5
  10. package/package.json +2 -2
  11. package/cjs/enums.d.ts +0 -10
  12. package/cjs/enums.js +0 -14
  13. package/cjs/index.d.ts +0 -4
  14. package/cjs/index.js +0 -16
  15. package/cjs/main.d.ts +0 -2
  16. package/cjs/main.js +0 -9
  17. package/cjs/preload.d.ts +0 -3
  18. package/cjs/preload.js +0 -10
  19. package/cjs/renderer.d.ts +0 -2
  20. package/cjs/renderer.js +0 -8
  21. package/cjs/scripts/bridge.d.ts +0 -8
  22. package/cjs/scripts/bridge.js +0 -69
  23. package/cjs/scripts/helpers/error-thrower.d.ts +0 -3
  24. package/cjs/scripts/helpers/error-thrower.js +0 -8
  25. package/cjs/scripts/helpers/main-event.d.ts +0 -8
  26. package/cjs/scripts/helpers/main-event.js +0 -15
  27. package/cjs/scripts/helpers/web-contents-container.d.ts +0 -12
  28. package/cjs/scripts/helpers/web-contents-container.js +0 -34
  29. package/cjs/scripts/preload-bridge.d.ts +0 -20
  30. package/cjs/scripts/preload-bridge.js +0 -76
  31. package/cjs/scripts/preload-provider.d.ts +0 -7
  32. package/cjs/scripts/preload-provider.js +0 -80
  33. package/cjs/scripts/provider.d.ts +0 -27
  34. package/cjs/scripts/provider.js +0 -95
  35. package/cjs/scripts/publish.d.ts +0 -41
  36. package/cjs/scripts/publish.js +0 -154
  37. package/cjs/scripts/renderer-tunnels.d.ts +0 -45
  38. package/cjs/scripts/renderer-tunnels.js +0 -110
  39. package/esm/enums.d.ts +0 -10
  40. package/esm/enums.js +0 -11
  41. package/esm/helpers.d.ts +0 -41
  42. package/esm/helpers.js +0 -96
  43. package/esm/index.d.ts +0 -4
  44. package/esm/index.js +0 -3
  45. package/esm/main.d.ts +0 -2
  46. package/esm/main.js +0 -1
  47. package/esm/preload.d.ts +0 -3
  48. package/esm/preload.js +0 -2
  49. package/esm/renderer.d.ts +0 -2
  50. package/esm/renderer.js +0 -1
  51. package/esm/scripts/bridge.d.ts +0 -8
  52. package/esm/scripts/bridge.js +0 -64
  53. package/esm/scripts/helpers/electron-importer.d.ts +0 -4
  54. package/esm/scripts/helpers/electron-importer.js +0 -16
  55. package/esm/scripts/helpers/error-thrower.d.ts +0 -3
  56. package/esm/scripts/helpers/error-thrower.js +0 -5
  57. package/esm/scripts/helpers/main-event.d.ts +0 -8
  58. package/esm/scripts/helpers/main-event.js +0 -12
  59. package/esm/scripts/helpers/web-contents-container.d.ts +0 -12
  60. package/esm/scripts/helpers/web-contents-container.js +0 -31
  61. package/esm/scripts/main.d.ts +0 -8
  62. package/esm/scripts/main.js +0 -69
  63. package/esm/scripts/preload-bridge.d.ts +0 -20
  64. package/esm/scripts/preload-bridge.js +0 -68
  65. package/esm/scripts/preload-provider.d.ts +0 -7
  66. package/esm/scripts/preload-provider.js +0 -75
  67. package/esm/scripts/provider.d.ts +0 -27
  68. package/esm/scripts/provider.js +0 -92
  69. package/esm/scripts/publish.d.ts +0 -41
  70. package/esm/scripts/publish.js +0 -147
  71. package/esm/scripts/renderer-tunnels.d.ts +0 -45
  72. package/esm/scripts/renderer-tunnels.js +0 -107
package/README.md CHANGED
@@ -218,8 +218,8 @@ publishFunction(
218
218
  )
219
219
 
220
220
  /* У событий также есть такой аргумент
221
- on('displayName', human => console.log(human.name), [Human])
222
- once('displayName', human => console.log(human.name), [Human])
221
+ on('displayName', human => console.log(human.name), Human)
222
+ once('displayName', human => console.log(human.name), Human)
223
223
  */
224
224
  ```
225
225
 
@@ -6,7 +6,7 @@ export default class WebContentsEventContainer {
6
6
  /**
7
7
  * Контейнер событий.
8
8
  */
9
- private container;
9
+ private containers;
10
10
  /**
11
11
  * Добавить многоразового отправителя для события.
12
12
  * @param event - Имя события.
@@ -45,12 +45,7 @@ export default class WebContentsEventContainer {
45
45
  /**
46
46
  * Добавить контейнер события.
47
47
  * @param name - Имя события.
48
+ * @returns Добавленный контейнер.
48
49
  */
49
50
  private addEvent;
50
- /**
51
- * Получить контейнер события.
52
- * @param name - Имя события.
53
- * @returns Контейнер события.
54
- */
55
- private getEvent;
56
51
  }
@@ -8,7 +8,7 @@ class WebContentsEventContainer {
8
8
  /**
9
9
  * Контейнер событий.
10
10
  */
11
- this.container = {};
11
+ this.containers = {};
12
12
  }
13
13
  /**
14
14
  * Добавить многоразового отправителя для события.
@@ -16,8 +16,7 @@ class WebContentsEventContainer {
16
16
  * @param sender - Отправитель.
17
17
  */
18
18
  addOn(event, sender) {
19
- this.addEvent(event);
20
- this.container[event].on.push(sender);
19
+ this.addEvent(event).on.push(sender);
21
20
  }
22
21
  /**
23
22
  * Добавить одноразового отправителя для события.
@@ -25,8 +24,7 @@ class WebContentsEventContainer {
25
24
  * @param sender - Отправитель.
26
25
  */
27
26
  addOnce(event, sender) {
28
- this.addEvent(event);
29
- this.container[event].once.push(sender);
27
+ this.addEvent(event).once.push(sender);
30
28
  }
31
29
  /**
32
30
  * Получить многоразовых отправителей для события.
@@ -34,7 +32,7 @@ class WebContentsEventContainer {
34
32
  * @returns многоразовые отправители для события.
35
33
  */
36
34
  getOn(event) {
37
- return this.getEvent(event).on.filter(sender => !sender.isDestroyed());
35
+ return this.addEvent(event).on;
38
36
  }
39
37
  /**
40
38
  * Получить одноразовых отправителей для события.
@@ -42,7 +40,7 @@ class WebContentsEventContainer {
42
40
  * @returns Одноразовые отправители для события.
43
41
  */
44
42
  getOnce(event) {
45
- return this.getEvent(event).once.filter(sender => !sender.isDestroyed());
43
+ return this.addEvent(event).once;
46
44
  }
47
45
  /**
48
46
  * Получить всех отправителей для события.
@@ -50,32 +48,28 @@ class WebContentsEventContainer {
50
48
  * @returns Отправители для события.
51
49
  */
52
50
  getAll(event) {
53
- const senders = this.getEvent(event);
54
- return [...senders.on, ...senders.once];
51
+ const container = this.addEvent(event);
52
+ return [...container.on, ...container.once];
55
53
  }
56
54
  /**
57
55
  * Удалить одноразовых отправителей для события.
58
56
  * @param event - Имя события.
59
57
  */
60
58
  clearOnce(event) {
61
- this.getEvent(event).once = [];
59
+ this.addEvent(event).once = [];
62
60
  }
63
61
  /**
64
62
  * Добавить контейнер события.
65
63
  * @param name - Имя события.
64
+ * @returns Добавленный контейнер.
66
65
  */
67
66
  addEvent(name) {
68
67
  var _a;
69
- (_a = this.container)[name] ?? (_a[name] = { on: [], once: [] });
70
- }
71
- /**
72
- * Получить контейнер события.
73
- * @param name - Имя события.
74
- * @returns Контейнер события.
75
- */
76
- getEvent(name) {
77
- this.addEvent(name);
78
- return this.container[name];
68
+ const container = (_a = this.containers)[name] ?? (_a[name] = { on: [], once: [] });
69
+ return this.containers[name] = {
70
+ on: container.on.filter(item => !item.isDestroyed()),
71
+ once: container.once.filter(item => !item.isDestroyed()),
72
+ };
79
73
  }
80
74
  }
81
75
  exports.default = WebContentsEventContainer;
@@ -12,7 +12,7 @@ export declare function emitEvent<T = unknown>(name: string, value?: T): void;
12
12
  * @param receives - Принимаемые классы, недоступные для транспортировки по умолчанию. _Порядок важен._
13
13
  * @returns Функция отписки от события.
14
14
  */
15
- export declare function on<TValue = any>(name: string, listener: EventListener<TValue>, receives: HasSnapshotClass<TValue>): EventUnsubscribe;
15
+ export declare function on<TValue = any>(name: string, listener: EventListener<TValue>, receives?: HasSnapshotClass<TValue>): EventUnsubscribe;
16
16
  /**
17
17
  * Добавить одноразовый обработчик renderer события.
18
18
  * @param name - Имя события.
@@ -20,7 +20,7 @@ export declare function on<TValue = any>(name: string, listener: EventListener<T
20
20
  * @param receives - Класс передаваемого значения, если оно не может быть передано стандартным способом.
21
21
  * @returns Функция отписки от события.
22
22
  */
23
- export declare function once<TValue = any>(name: string, listener: EventListener<TValue>, receives: HasSnapshotClass<TValue>): EventUnsubscribe;
23
+ export declare function once<TValue = any>(name: string, listener: EventListener<TValue>, receives?: HasSnapshotClass<TValue>): EventUnsubscribe;
24
24
  /**
25
25
  * Опубликовать (сделать доступной) функцию из main процесса.
26
26
  * @param name - Имя, по которому будет доступна функция в renderer процессе.
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
- /*
3
- Методы публикации в main процессе.
4
- */
2
+ // Методы публикации в main процессе.
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
4
  exports.emitEvent = emitEvent;
7
5
  exports.on = on;
@@ -77,7 +75,7 @@ function on(name, listener, receives) {
77
75
  canThrowError();
78
76
  const emitChannel = index_js_1.IpcChannel.event.emit(name);
79
77
  const handler = (_, { value }) => {
80
- if (index_js_1.Transfer.isSnapshotValue(value)) {
78
+ if (index_js_1.Transfer.isSnapshotValue(value) && receives) {
81
79
  listener(index_js_1.Transfer.getFromSnapshot(value, receives));
82
80
  }
83
81
  else {
@@ -98,7 +96,7 @@ function once(name, listener, receives) {
98
96
  canThrowError();
99
97
  const emitChannel = index_js_1.IpcChannel.event.emit(name);
100
98
  const handler = (_, { value }) => {
101
- if (index_js_1.Transfer.isSnapshotValue(value)) {
99
+ if (index_js_1.Transfer.isSnapshotValue(value) && receives) {
102
100
  listener(index_js_1.Transfer.getFromSnapshot(value, receives));
103
101
  }
104
102
  else {
@@ -6,7 +6,7 @@ export default class WebContentsEventContainer {
6
6
  /**
7
7
  * Контейнер событий.
8
8
  */
9
- private container;
9
+ private containers;
10
10
  /**
11
11
  * Добавить многоразового отправителя для события.
12
12
  * @param event - Имя события.
@@ -45,12 +45,7 @@ export default class WebContentsEventContainer {
45
45
  /**
46
46
  * Добавить контейнер события.
47
47
  * @param name - Имя события.
48
+ * @returns Добавленный контейнер.
48
49
  */
49
50
  private addEvent;
50
- /**
51
- * Получить контейнер события.
52
- * @param name - Имя события.
53
- * @returns Контейнер события.
54
- */
55
- private getEvent;
56
51
  }
@@ -6,7 +6,7 @@ export default class WebContentsEventContainer {
6
6
  /**
7
7
  * Контейнер событий.
8
8
  */
9
- this.container = {};
9
+ this.containers = {};
10
10
  }
11
11
  /**
12
12
  * Добавить многоразового отправителя для события.
@@ -14,8 +14,7 @@ export default class WebContentsEventContainer {
14
14
  * @param sender - Отправитель.
15
15
  */
16
16
  addOn(event, sender) {
17
- this.addEvent(event);
18
- this.container[event].on.push(sender);
17
+ this.addEvent(event).on.push(sender);
19
18
  }
20
19
  /**
21
20
  * Добавить одноразового отправителя для события.
@@ -23,8 +22,7 @@ export default class WebContentsEventContainer {
23
22
  * @param sender - Отправитель.
24
23
  */
25
24
  addOnce(event, sender) {
26
- this.addEvent(event);
27
- this.container[event].once.push(sender);
25
+ this.addEvent(event).once.push(sender);
28
26
  }
29
27
  /**
30
28
  * Получить многоразовых отправителей для события.
@@ -32,7 +30,7 @@ export default class WebContentsEventContainer {
32
30
  * @returns многоразовые отправители для события.
33
31
  */
34
32
  getOn(event) {
35
- return this.getEvent(event).on.filter(sender => !sender.isDestroyed());
33
+ return this.addEvent(event).on;
36
34
  }
37
35
  /**
38
36
  * Получить одноразовых отправителей для события.
@@ -40,7 +38,7 @@ export default class WebContentsEventContainer {
40
38
  * @returns Одноразовые отправители для события.
41
39
  */
42
40
  getOnce(event) {
43
- return this.getEvent(event).once.filter(sender => !sender.isDestroyed());
41
+ return this.addEvent(event).once;
44
42
  }
45
43
  /**
46
44
  * Получить всех отправителей для события.
@@ -48,31 +46,27 @@ export default class WebContentsEventContainer {
48
46
  * @returns Отправители для события.
49
47
  */
50
48
  getAll(event) {
51
- const senders = this.getEvent(event);
52
- return [...senders.on, ...senders.once];
49
+ const container = this.addEvent(event);
50
+ return [...container.on, ...container.once];
53
51
  }
54
52
  /**
55
53
  * Удалить одноразовых отправителей для события.
56
54
  * @param event - Имя события.
57
55
  */
58
56
  clearOnce(event) {
59
- this.getEvent(event).once = [];
57
+ this.addEvent(event).once = [];
60
58
  }
61
59
  /**
62
60
  * Добавить контейнер события.
63
61
  * @param name - Имя события.
62
+ * @returns Добавленный контейнер.
64
63
  */
65
64
  addEvent(name) {
66
65
  var _a;
67
- (_a = this.container)[name] ?? (_a[name] = { on: [], once: [] });
68
- }
69
- /**
70
- * Получить контейнер события.
71
- * @param name - Имя события.
72
- * @returns Контейнер события.
73
- */
74
- getEvent(name) {
75
- this.addEvent(name);
76
- return this.container[name];
66
+ const container = (_a = this.containers)[name] ?? (_a[name] = { on: [], once: [] });
67
+ return this.containers[name] = {
68
+ on: container.on.filter(item => !item.isDestroyed()),
69
+ once: container.once.filter(item => !item.isDestroyed()),
70
+ };
77
71
  }
78
72
  }
@@ -12,7 +12,7 @@ export declare function emitEvent<T = unknown>(name: string, value?: T): void;
12
12
  * @param receives - Принимаемые классы, недоступные для транспортировки по умолчанию. _Порядок важен._
13
13
  * @returns Функция отписки от события.
14
14
  */
15
- export declare function on<TValue = any>(name: string, listener: EventListener<TValue>, receives: HasSnapshotClass<TValue>): EventUnsubscribe;
15
+ export declare function on<TValue = any>(name: string, listener: EventListener<TValue>, receives?: HasSnapshotClass<TValue>): EventUnsubscribe;
16
16
  /**
17
17
  * Добавить одноразовый обработчик renderer события.
18
18
  * @param name - Имя события.
@@ -20,7 +20,7 @@ export declare function on<TValue = any>(name: string, listener: EventListener<T
20
20
  * @param receives - Класс передаваемого значения, если оно не может быть передано стандартным способом.
21
21
  * @returns Функция отписки от события.
22
22
  */
23
- export declare function once<TValue = any>(name: string, listener: EventListener<TValue>, receives: HasSnapshotClass<TValue>): EventUnsubscribe;
23
+ export declare function once<TValue = any>(name: string, listener: EventListener<TValue>, receives?: HasSnapshotClass<TValue>): EventUnsubscribe;
24
24
  /**
25
25
  * Опубликовать (сделать доступной) функцию из main процесса.
26
26
  * @param name - Имя, по которому будет доступна функция в renderer процессе.
@@ -1,6 +1,4 @@
1
- /*
2
- Методы публикации в main процессе.
3
- */
1
+ // Методы публикации в main процессе.
4
2
  import { ipcMain } from 'electron';
5
3
  import { PublishMethodsUnavailableError } from '../../errors.js';
6
4
  import { Env, Errors, IpcChannel, IpcEventInMain, IpcResult, Transfer, WebContentsEventsContainer } from '../helpers/index.js';
@@ -70,7 +68,7 @@ export function on(name, listener, receives) {
70
68
  canThrowError();
71
69
  const emitChannel = IpcChannel.event.emit(name);
72
70
  const handler = (_, { value }) => {
73
- if (Transfer.isSnapshotValue(value)) {
71
+ if (Transfer.isSnapshotValue(value) && receives) {
74
72
  listener(Transfer.getFromSnapshot(value, receives));
75
73
  }
76
74
  else {
@@ -91,7 +89,7 @@ export function once(name, listener, receives) {
91
89
  canThrowError();
92
90
  const emitChannel = IpcChannel.event.emit(name);
93
91
  const handler = (_, { value }) => {
94
- if (Transfer.isSnapshotValue(value)) {
92
+ if (Transfer.isSnapshotValue(value) && receives) {
95
93
  listener(Transfer.getFromSnapshot(value, receives));
96
94
  }
97
95
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emr-bridge",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Allows you to easily give access to main methods from the renderer process",
5
5
  "main": "esm/entries/index.js",
6
6
  "type": "module",
@@ -47,6 +47,6 @@
47
47
  "electron": ">=20.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "typescript": "^5.5.3"
50
+ "typescript": "^5.7.2"
51
51
  }
52
52
  }
package/cjs/enums.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare enum IpcChannel {
2
- getPublicInfo = "GET_PUBLIC_INFO",
3
- functionCall = "FUNCTION_CALL_",
4
- eventOn = "EVENT_ON",
5
- eventOnce = "EVENT_ONCE",
6
- eventEmit = "EVENT_EMIT_",
7
- propertyGet = "PROPERTY_GET_",
8
- propertySet = "PROPERTY_SET_",
9
- promisePostfix = "_PROMISE"
10
- }
package/cjs/enums.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IpcChannel = void 0;
4
- var IpcChannel;
5
- (function (IpcChannel) {
6
- IpcChannel["getPublicInfo"] = "GET_PUBLIC_INFO";
7
- IpcChannel["functionCall"] = "FUNCTION_CALL_";
8
- IpcChannel["eventOn"] = "EVENT_ON";
9
- IpcChannel["eventOnce"] = "EVENT_ONCE";
10
- IpcChannel["eventEmit"] = "EVENT_EMIT_";
11
- IpcChannel["propertyGet"] = "PROPERTY_GET_";
12
- IpcChannel["propertySet"] = "PROPERTY_SET_";
13
- IpcChannel["promisePostfix"] = "_PROMISE";
14
- })(IpcChannel || (exports.IpcChannel = IpcChannel = {}));
package/cjs/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { default as Bridge } from './scripts/bridge.js';
2
- export { default as provideFromMain } from './scripts/preload-provider.js';
3
- export { emitEvent, on, once, publicFunction, publicVariable } from './scripts/publish.js';
4
- export type { EventListener, EventUnsubscribe, IPublicProperty, PublicFunction } from './types.js';
package/cjs/index.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.publicVariable = exports.publicFunction = exports.once = exports.on = exports.emitEvent = exports.provideFromMain = exports.Bridge = void 0;
7
- var bridge_js_1 = require("./scripts/bridge.js");
8
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return __importDefault(bridge_js_1).default; } });
9
- var preload_provider_js_1 = require("./scripts/preload-provider.js");
10
- Object.defineProperty(exports, "provideFromMain", { enumerable: true, get: function () { return __importDefault(preload_provider_js_1).default; } });
11
- var publish_js_1 = require("./scripts/publish.js");
12
- Object.defineProperty(exports, "emitEvent", { enumerable: true, get: function () { return publish_js_1.emitEvent; } });
13
- Object.defineProperty(exports, "on", { enumerable: true, get: function () { return publish_js_1.on; } });
14
- Object.defineProperty(exports, "once", { enumerable: true, get: function () { return publish_js_1.once; } });
15
- Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_js_1.publicFunction; } });
16
- Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_js_1.publicVariable; } });
package/cjs/main.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { emitEvent, on, once, publicFunction, publicVariable } from './scripts/publish.js';
2
- export type { EventListener, EventUnsubscribe, IPublicProperty, PublicFunction } from './types.js';
package/cjs/main.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicVariable = exports.publicFunction = exports.once = exports.on = exports.emitEvent = void 0;
4
- var publish_js_1 = require("./scripts/publish.js");
5
- Object.defineProperty(exports, "emitEvent", { enumerable: true, get: function () { return publish_js_1.emitEvent; } });
6
- Object.defineProperty(exports, "on", { enumerable: true, get: function () { return publish_js_1.on; } });
7
- Object.defineProperty(exports, "once", { enumerable: true, get: function () { return publish_js_1.once; } });
8
- Object.defineProperty(exports, "publicFunction", { enumerable: true, get: function () { return publish_js_1.publicFunction; } });
9
- Object.defineProperty(exports, "publicVariable", { enumerable: true, get: function () { return publish_js_1.publicVariable; } });
package/cjs/preload.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as Bridge } from './scripts/preload-bridge.js';
2
- export { default as provideFromMain } from './scripts/preload-provider.js';
3
- export type { EventListener, EventUnsubscribe, IPublicProperty, PublicFunction } from './types.js';
package/cjs/preload.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.provideFromMain = exports.Bridge = void 0;
7
- var preload_bridge_js_1 = require("./scripts/preload-bridge.js");
8
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return __importDefault(preload_bridge_js_1).default; } });
9
- var preload_provider_js_1 = require("./scripts/preload-provider.js");
10
- Object.defineProperty(exports, "provideFromMain", { enumerable: true, get: function () { return __importDefault(preload_provider_js_1).default; } });
package/cjs/renderer.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default as Bridge } from './scripts/bridge.js';
2
- export type { EventListener, EventUnsubscribe, IPublicProperty, PublicFunction } from './types.js';
package/cjs/renderer.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Bridge = void 0;
7
- var bridge_js_1 = require("./scripts/bridge.js");
8
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return __importDefault(bridge_js_1).default; } });
@@ -1,8 +0,0 @@
1
- import type { IBridge } from '../types.js';
2
- /**
3
- * Bridge between `renderer` and `main` processes.
4
- *
5
- * _only for renderer process_
6
- */
7
- declare const _default: IBridge;
8
- export default _default;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const errors_js_1 = require("../errors.js");
7
- const index_js_1 = require("./helpers/index.js");
8
- const provider_js_1 = __importDefault(require("./provider.js"));
9
- class ProviderIntoRenderer extends provider_js_1.default {
10
- globalProvider;
11
- entitiesInfo;
12
- constructor() {
13
- super();
14
- if (!window.__provider__) {
15
- throw new errors_js_1.NotProvidedFromMain();
16
- }
17
- this.globalProvider = window.__provider__;
18
- this.entitiesInfo = this.globalProvider.getEntitiesInfo();
19
- this.init();
20
- }
21
- callFunction(name, id, args) {
22
- return this.globalProvider.entities.functions[name](id, args);
23
- }
24
- getVariable(name) {
25
- return this.globalProvider.entities.variables[name].get();
26
- }
27
- setVariable(name, value) {
28
- return this.globalProvider.entities.variables[name].set(value);
29
- }
30
- waitPromise(channel, id) {
31
- return new Promise((resolve, reject) => {
32
- this.globalProvider.waitPromise(channel, resolve, reject, id);
33
- });
34
- }
35
- handleEvent(name, type, listener) {
36
- return type === 'on'
37
- ? this.globalProvider.entities.events.on(name, listener)
38
- : this.globalProvider.entities.events.once(name, listener);
39
- }
40
- emitEvent(name, value) {
41
- this.globalProvider.entities.events.emit(name, value);
42
- }
43
- }
44
- function getErrorThrower() {
45
- if (!index_js_1.Env.global.hasWindow) {
46
- return index_js_1.ErrorThrower.throws(errors_js_1.TryUseBridgeInPreload);
47
- }
48
- if (!index_js_1.Env.global.hasProvider) {
49
- return index_js_1.ErrorThrower.throws(errors_js_1.GlobalProviderNotFoundError);
50
- }
51
- return null;
52
- }
53
- function getBridge() {
54
- const throwError = getErrorThrower();
55
- if (throwError) {
56
- return new Proxy({}, {
57
- get: throwError,
58
- set: throwError,
59
- apply: throwError
60
- });
61
- }
62
- return new ProviderIntoRenderer();
63
- }
64
- /**
65
- * Bridge between `renderer` and `main` processes.
66
- *
67
- * _only for renderer process_
68
- */
69
- exports.default = getBridge();
@@ -1,3 +0,0 @@
1
- export default class ErrorThrower {
2
- static throws<TClass extends new (...args: TArgs) => InstanceType<TClass>, TArgs extends any[]>(errorClass: TClass, ...args: TArgs): () => never;
3
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ErrorThrower {
4
- static throws(errorClass, ...args) {
5
- return () => { throw new errorClass(...args); };
6
- }
7
- }
8
- exports.default = ErrorThrower;
@@ -1,8 +0,0 @@
1
- import type { IpcMainEvent } from 'electron';
2
- import type { IResult } from '../../types.js';
3
- export default class MainEvent {
4
- private event;
5
- constructor(event: IpcMainEvent);
6
- send(channel: string, result: IResult): void;
7
- return(value: any): void;
8
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class MainEvent {
4
- event;
5
- constructor(event) {
6
- this.event = event;
7
- }
8
- send(channel, result) {
9
- this.event.sender.send(channel, result);
10
- }
11
- return(value) {
12
- this.event.returnValue = value;
13
- }
14
- }
15
- exports.default = MainEvent;
@@ -1,12 +0,0 @@
1
- import type { WebContents } from 'electron';
2
- export default class WebContentsContainer {
3
- private container;
4
- addOn(event: string, sender: WebContents): void;
5
- addOnce(event: string, sender: WebContents): void;
6
- getOn(event: string): WebContents[];
7
- getOnce(event: string): WebContents[];
8
- getAll(event: string): WebContents[];
9
- clearOnce(event: string): void;
10
- private addEvent;
11
- private getEvent;
12
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class WebContentsContainer {
4
- container = {};
5
- addOn(event, sender) {
6
- this.addEvent(event);
7
- this.container[event].on.push(sender);
8
- }
9
- addOnce(event, sender) {
10
- this.addEvent(event);
11
- this.container[event].once.push(sender);
12
- }
13
- getOn(event) {
14
- return this.getEvent(event).on.filter(sender => !sender.isDestroyed());
15
- }
16
- getOnce(event) {
17
- return this.getEvent(event).once.filter(sender => !sender.isDestroyed());
18
- }
19
- getAll(event) {
20
- const senders = this.getEvent(event);
21
- return [...senders.on, ...senders.once];
22
- }
23
- clearOnce(event) {
24
- this.getEvent(event).once = [];
25
- }
26
- addEvent(name) {
27
- this.container[name] ??= { on: [], once: [] };
28
- }
29
- getEvent(name) {
30
- this.addEvent(name);
31
- return this.container[name];
32
- }
33
- }
34
- exports.default = WebContentsContainer;
@@ -1,20 +0,0 @@
1
- import type { EventListener, EventUnsubscribe, IBridge, IResult } from '../types.js';
2
- import Provider from './provider.js';
3
- export declare class ProviderIntoPreload extends Provider {
4
- protected readonly entitiesInfo: any;
5
- constructor();
6
- protected callFunction(name: string, secret: string, args: any[]): IResult;
7
- protected getVariable(name: string): IResult;
8
- protected setVariable(name: string, value: any): IResult;
9
- protected waitPromise(channel: string, id?: string): Promise<any>;
10
- protected handleEvent(name: string, type: 'on' | 'once', listener: EventListener<IResult>): EventUnsubscribe;
11
- protected emitEvent(name: string, arg: any): void;
12
- }
13
- export declare function getBridge(): IBridge;
14
- /**
15
- * Bridge between `preload` and `main` processes.
16
- *
17
- * _only for preload process_
18
- */
19
- declare const _default: IBridge;
20
- export default _default;