@rg-dev/electron-helpers 1.0.2 → 1.0.4

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.
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -40,7 +40,7 @@ interface TypedIpcMain<IpcEvents extends InputMap, IpcCommands extends InputMap
40
40
 
41
41
 
42
42
 
43
-
43
+ //@ts-ignore
44
44
  interface TypedIpcRenderer<IpcEvents extends InputMap, IpcCommands extends InputMap
45
45
  > extends IpcRenderer {
46
46
  on<K extends keyof IpcEvents>(
@@ -64,6 +64,13 @@ interface TypedIpcRenderer<IpcEvents extends InputMap, IpcCommands extends Input
64
64
  ...args: Parameters<IpcEvents[K]>
65
65
  ) => void
66
66
  ): this;
67
+ off<K extends keyof IpcEvents>(
68
+ channel: K,
69
+ listener: (
70
+ event: IpcRendererEvent,
71
+ ...args: Parameters<IpcEvents[K]>
72
+ ) => void
73
+ ): this;
67
74
  removeAllListeners<K extends keyof IpcEvents>(channel: K): this;
68
75
  off<K extends keyof IpcEvents>(channel: K): this;
69
76
  send<K extends keyof IpcEvents>(
@@ -40,7 +40,7 @@ interface TypedIpcMain<IpcEvents extends InputMap, IpcCommands extends InputMap
40
40
 
41
41
 
42
42
 
43
-
43
+ //@ts-ignore
44
44
  interface TypedIpcRenderer<IpcEvents extends InputMap, IpcCommands extends InputMap
45
45
  > extends IpcRenderer {
46
46
  on<K extends keyof IpcEvents>(
@@ -64,6 +64,13 @@ interface TypedIpcRenderer<IpcEvents extends InputMap, IpcCommands extends Input
64
64
  ...args: Parameters<IpcEvents[K]>
65
65
  ) => void
66
66
  ): this;
67
+ off<K extends keyof IpcEvents>(
68
+ channel: K,
69
+ listener: (
70
+ event: IpcRendererEvent,
71
+ ...args: Parameters<IpcEvents[K]>
72
+ ) => void
73
+ ): this;
67
74
  removeAllListeners<K extends keyof IpcEvents>(channel: K): this;
68
75
  off<K extends keyof IpcEvents>(channel: K): this;
69
76
  send<K extends keyof IpcEvents>(
package/dist/backend.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
package/dist/client.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -36,6 +37,9 @@ var IpcClient = class _IpcClient {
36
37
  ipc;
37
38
  static create(electronIpc, _shape) {
38
39
  const client = new _IpcClient();
40
+ if (!electronIpc) {
41
+ console.warn("electron ipc object undefined");
42
+ }
39
43
  client.ipc = electronIpc;
40
44
  return client;
41
45
  }
@@ -43,6 +47,10 @@ var IpcClient = class _IpcClient {
43
47
  return new Promise(
44
48
  async (resolve, reject) => {
45
49
  try {
50
+ if (!this.ipc) {
51
+ resolve(void 0);
52
+ return;
53
+ }
46
54
  const res = await this.ipc.invoke(route, ...args);
47
55
  if (!res) {
48
56
  resolve(void 0);
@@ -61,11 +69,17 @@ var IpcClient = class _IpcClient {
61
69
  );
62
70
  }
63
71
  on(channel, listener) {
72
+ if (!this.ipc) {
73
+ return this;
74
+ }
64
75
  this.ipc.on(channel, (_event, ...args) => listener(...args));
65
76
  return this;
66
77
  }
67
78
  off(channel, listener) {
68
- this.ipc.removeListener(channel, (_event, ...args) => listener(...args));
79
+ if (!this.ipc) {
80
+ return this;
81
+ }
82
+ this.ipc.off(channel, (_event, ...args) => listener(...args));
69
83
  return this;
70
84
  }
71
85
  };
package/dist/client.js CHANGED
@@ -8,6 +8,9 @@ var IpcClient = class _IpcClient {
8
8
  ipc;
9
9
  static create(electronIpc, _shape) {
10
10
  const client = new _IpcClient();
11
+ if (!electronIpc) {
12
+ console.warn("electron ipc object undefined");
13
+ }
11
14
  client.ipc = electronIpc;
12
15
  return client;
13
16
  }
@@ -15,6 +18,10 @@ var IpcClient = class _IpcClient {
15
18
  return new Promise(
16
19
  async (resolve, reject) => {
17
20
  try {
21
+ if (!this.ipc) {
22
+ resolve(void 0);
23
+ return;
24
+ }
18
25
  const res = await this.ipc.invoke(route, ...args);
19
26
  if (!res) {
20
27
  resolve(void 0);
@@ -33,11 +40,17 @@ var IpcClient = class _IpcClient {
33
40
  );
34
41
  }
35
42
  on(channel, listener) {
43
+ if (!this.ipc) {
44
+ return this;
45
+ }
36
46
  this.ipc.on(channel, (_event, ...args) => listener(...args));
37
47
  return this;
38
48
  }
39
49
  off(channel, listener) {
40
- this.ipc.removeListener(channel, (_event, ...args) => listener(...args));
50
+ if (!this.ipc) {
51
+ return this;
52
+ }
53
+ this.ipc.off(channel, (_event, ...args) => listener(...args));
41
54
  return this;
42
55
  }
43
56
  };
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/electron-helpers",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "tsup && node dist/index.cjs",
@@ -12,24 +12,34 @@
12
12
  "files": [
13
13
  "dist"
14
14
  ],
15
- "publishConfig": {
16
- "access": "public"
15
+ "publishConfig": {
16
+ "access": "public"
17
17
  },
18
18
  "module": "./dist/index.js",
19
19
  "types": "./dist/index.d.ts",
20
20
  "type": "module",
21
+ "typesVersions": {
22
+ "*": {
23
+ "dist/backend": [
24
+ "dist/backend.d.ts"
25
+ ],
26
+ "dist/client": [
27
+ "dist/client.d.ts"
28
+ ]
29
+ }
30
+ },
21
31
  "exports": {
22
- ".": {
23
- "import": "./dist/index.js",
24
- "require": "./dist/index.cjs"
32
+ ".": {
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
25
35
  },
26
- "./dist/client": {
27
- "import": "./dist/client.js",
28
- "require": "./dist/client.cjs"
36
+ "./dist/client": {
37
+ "import": "./dist/client.js",
38
+ "require": "./dist/client.cjs"
29
39
  },
30
- "./dist/backend": {
31
- "import": "./dist/backend.js",
32
- "require": "./dist/backend.cjs"
40
+ "./dist/backend": {
41
+ "import": "./dist/backend.js",
42
+ "require": "./dist/backend.cjs"
33
43
  }
34
44
  },
35
45
  "devDependencies": {