@nativewindow/ipc 0.2.0 → 1.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.
- package/README.md +22 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@nativewindow/ipc)
|
|
4
4
|
|
|
5
|
-
> [!
|
|
6
|
-
> This project is in **
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> This project is in **beta**. APIs may change without notice.
|
|
7
7
|
|
|
8
8
|
Pure TypeScript typesafe IPC channel layer for [native-window](https://github.com/nativewindow/webview). Schema-based validation with compile-time checked event maps.
|
|
9
9
|
|
|
@@ -25,13 +25,18 @@ const ch = createWindow(
|
|
|
25
25
|
{ title: "Typed IPC" },
|
|
26
26
|
{
|
|
27
27
|
schemas: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
host: {
|
|
29
|
+
"update-title": z.string(),
|
|
30
|
+
},
|
|
31
|
+
client: {
|
|
32
|
+
"user-click": z.object({ x: z.number(), y: z.number() }),
|
|
33
|
+
counter: z.number(),
|
|
34
|
+
},
|
|
31
35
|
},
|
|
32
36
|
},
|
|
33
37
|
);
|
|
34
38
|
|
|
39
|
+
// Receive typed messages from the webview (client events)
|
|
35
40
|
ch.on("user-click", (pos) => {
|
|
36
41
|
// pos: { x: number; y: number }
|
|
37
42
|
console.log(`Click at ${pos.x}, ${pos.y}`);
|
|
@@ -42,8 +47,8 @@ ch.on("counter", (n) => {
|
|
|
42
47
|
ch.send("update-title", `Count: ${n}`);
|
|
43
48
|
});
|
|
44
49
|
|
|
45
|
-
// ch.send("counter", "wrong"); // Type error
|
|
46
|
-
// ch.send("typo", 123); // Type error
|
|
50
|
+
// ch.send("counter", "wrong"); // Type error: "counter" is a client event
|
|
51
|
+
// ch.send("typo", 123); // Type error: "typo" does not exist
|
|
47
52
|
|
|
48
53
|
ch.window.loadHtml(`<html>...</html>`);
|
|
49
54
|
```
|
|
@@ -71,12 +76,19 @@ import { createChannelClient } from "@nativewindow/ipc/client";
|
|
|
71
76
|
|
|
72
77
|
const ch = createChannelClient({
|
|
73
78
|
schemas: {
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
host: {
|
|
80
|
+
"update-title": z.string(),
|
|
81
|
+
},
|
|
82
|
+
client: {
|
|
83
|
+
counter: z.number(),
|
|
84
|
+
},
|
|
76
85
|
},
|
|
77
86
|
});
|
|
78
87
|
|
|
88
|
+
// Send client events to the host
|
|
79
89
|
ch.send("counter", 42); // Typed!
|
|
90
|
+
|
|
91
|
+
// Receive host events from the host
|
|
80
92
|
ch.on("update-title", (t) => {
|
|
81
93
|
// t: string
|
|
82
94
|
document.title = t;
|
|
@@ -105,7 +117,7 @@ Create a typed channel client inside the webview for use in bundled apps.
|
|
|
105
117
|
|
|
106
118
|
| Option | Type | Default | Description |
|
|
107
119
|
| ---------------------- | ----------- | ---------- | -------------------------------------- |
|
|
108
|
-
| `schemas` | `SchemaMap` | _required_ |
|
|
120
|
+
| `schemas` | `{ host: SchemaMap; client: SchemaMap }` | _required_ | Directional schemas — `host` for events the host sends, `client` for events the webview sends |
|
|
109
121
|
| `injectClient` | `boolean` | `true` | Auto-inject client script into webview |
|
|
110
122
|
| `onValidationError` | `function` | — | Called when a payload fails validation |
|
|
111
123
|
| `trustedOrigins` | `string[]` | — | Restrict IPC to specific origins |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativewindow/ipc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Typesafe IPC channels for native-window (
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Typesafe IPC channels for native-window (beta)",
|
|
5
5
|
"homepage": "https://nativewindow.fcannizzaro.com",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/nativewindow/webview/issues"
|