@domicile-desktop/system-network 0.0.0-alpha-2edc3c14d846 → 0.0.0-alpha-b85d9bb6d4af

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 CHANGED
@@ -106,6 +106,17 @@ import { checkPortal } from "@domicile-desktop/system-network/portal";
106
106
 
107
107
  See [SHELL-SYSTEM-ACCESS.md](/docs/SHELL-SYSTEM-ACCESS.md).
108
108
 
109
+ ## React
110
+
111
+ `@domicile-desktop/system-network/react`, for a shell on
112
+ [`@domicile-desktop/react`](../react/README.md):
113
+
114
+ - `useNetwork()`, `useNetworkInterfaces()`, `useAddresses()`, `useWifi()`:
115
+ each `undefined` until first read.
116
+ - `deskNetwork(domicile)`: the shared watches behind them, one per desktop.
117
+ The network service refuses calls while the desktop is locked, so those
118
+ watches start again on unlock (`watchAcrossLocks`).
119
+
109
120
  ## Test
110
121
 
111
122
  ```sh
@@ -0,0 +1,9 @@
1
+ import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
2
+ /**
3
+ * `start`, begun again each time the desktop unlocks.
4
+ *
5
+ * The compositor refuses the network service's calls while the desktop is
6
+ * locked (docs/LOCK.md), and a refused read is not retried until the service
7
+ * signals a change, which may be long after the unlock.
8
+ */
9
+ export declare const watchAcrossLocks: <T>(domicile: Pick<Domicile, "session">, start: (onValue: (value: T) => void) => () => void) => (onValue: (value: T) => void) => (() => void);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `start`, begun again each time the desktop unlocks.
3
+ *
4
+ * The compositor refuses the network service's calls while the desktop is
5
+ * locked (docs/LOCK.md), and a refused read is not retried until the service
6
+ * signals a change, which may be long after the unlock.
7
+ */
8
+ export const watchAcrossLocks = (domicile, start) => (onValue) => {
9
+ const watch = { locked: false, stop: start(onValue) };
10
+ const { session } = domicile;
11
+ const changed = () => {
12
+ // `undefined` until the compositor says.
13
+ const { locked } = session;
14
+ if (locked !== undefined) {
15
+ if (watch.locked && !locked) {
16
+ watch.stop();
17
+ watch.stop = start(onValue);
18
+ }
19
+ watch.locked = locked;
20
+ }
21
+ };
22
+ changed();
23
+ const stopHearing = session.on("lockchange", changed);
24
+ return () => {
25
+ stopHearing();
26
+ watch.stop();
27
+ };
28
+ };
@@ -0,0 +1,30 @@
1
+ import type { Option, Result } from "@cprussin/option-result";
2
+ import type { SharedWatch } from "@domicile-desktop/react/shared-watch";
3
+ import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
4
+ import type { SystemError } from "@domicile-desktop/sdk/system";
5
+ import type { Addressing, NetworkInterface } from "./interfaces";
6
+ import type { Network } from "./network-state";
7
+ import type { Wifi } from "./wifi-state";
8
+ export type DeskNetwork = {
9
+ network: SharedWatch<Result<Network, SystemError>>;
10
+ /** The network hardware. */
11
+ interfaces: SharedWatch<Result<NetworkInterface[], SystemError>>;
12
+ /** Each interface's addresses, by name. */
13
+ addresses: SharedWatch<Result<Map<string, Addressing>, SystemError>>;
14
+ /** The Wi-Fi device; `None` without one. */
15
+ wifi: SharedWatch<Result<Option<Wifi>, SystemError>>;
16
+ };
17
+ /**
18
+ * The network service and hardware, watched once per desktop. The calls that
19
+ * reach past `/sys` are refused while the desktop is locked, so those watches
20
+ * start again on unlock.
21
+ */
22
+ export declare const deskNetwork: (domicile: Domicile) => DeskNetwork;
23
+ /** NetworkManager's state, or `undefined` before it says. */
24
+ export declare const useNetwork: () => Result<Network, SystemError> | undefined;
25
+ /** The network hardware, or `undefined` before it was read. */
26
+ export declare const useNetworkInterfaces: () => Result<NetworkInterface[], SystemError> | undefined;
27
+ /** Each interface's addresses by name, or `undefined` before they were read. */
28
+ export declare const useAddresses: () => Result<Map<string, Addressing>, SystemError> | undefined;
29
+ /** The Wi-Fi device (`None` without one), or `undefined` before it was read. */
30
+ export declare const useWifi: () => Result<Option<Wifi>, SystemError> | undefined;
package/dist/react.js ADDED
@@ -0,0 +1,29 @@
1
+ // The network for a React shell: one watch per desktop, however many parts
2
+ // read it.
3
+ import { perDesktop } from "@domicile-desktop/react/per-desktop";
4
+ import { sharedWatch } from "@domicile-desktop/react/shared-watch";
5
+ import { useDeskWatch } from "@domicile-desktop/react/use-shared-watch";
6
+ import { watchAcrossLocks } from "./across-locks";
7
+ import { watchAddresses, watchInterfaces } from "./interfaces";
8
+ import { watchNetwork } from "./network";
9
+ import { watchWifi } from "./wifi";
10
+ /**
11
+ * The network service and hardware, watched once per desktop. The calls that
12
+ * reach past `/sys` are refused while the desktop is locked, so those watches
13
+ * start again on unlock.
14
+ */
15
+ export const deskNetwork = perDesktop((domicile) => ({
16
+ addresses: sharedWatch(watchAcrossLocks(domicile, (onAddresses) => watchAddresses(domicile, onAddresses))),
17
+ interfaces: sharedWatch((onInterfaces) => watchInterfaces(domicile, onInterfaces)),
18
+ network: sharedWatch(watchAcrossLocks(domicile, (onNetwork) => watchNetwork(domicile, onNetwork))),
19
+ wifi: sharedWatch(watchAcrossLocks(domicile, (onWifi) => watchWifi(domicile, onWifi))),
20
+ }));
21
+ const part = (key) => (domicile) => deskNetwork(domicile)[key];
22
+ /** NetworkManager's state, or `undefined` before it says. */
23
+ export const useNetwork = () => useDeskWatch(part("network"));
24
+ /** The network hardware, or `undefined` before it was read. */
25
+ export const useNetworkInterfaces = () => useDeskWatch(part("interfaces"));
26
+ /** Each interface's addresses by name, or `undefined` before they were read. */
27
+ export const useAddresses = () => useDeskWatch(part("addresses"));
28
+ /** The Wi-Fi device (`None` without one), or `undefined` before it was read. */
29
+ export const useWifi = () => useDeskWatch(part("wifi"));
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "dependencies": {
3
3
  "@cprussin/option-result": "^2.0.1",
4
- "@domicile-desktop/sdk": "0.0.0-alpha-2edc3c14d846",
4
+ "@domicile-desktop/react": "0.0.0-alpha-b85d9bb6d4af",
5
+ "@domicile-desktop/sdk": "0.0.0-alpha-b85d9bb6d4af",
5
6
  "zod": "^4.5.4"
6
7
  },
7
8
  "description": "The network for a Domicile shell, from NetworkManager, iwd or wpa_supplicant: connectivity and the primary connection, with its Wi-Fi network and signal, kept current.",
8
9
  "devDependencies": {
9
10
  "@cprussin/tsconfig": "^5.0.0",
10
11
  "@types/bun": "^1.4.2",
12
+ "@types/react": "^19.2.18",
13
+ "react": "^19.2.8",
11
14
  "typescript": "^7.0.2"
12
15
  },
13
16
  "engines": {
@@ -42,6 +45,10 @@
42
45
  "./wpa-supplicant": {
43
46
  "types": "./dist/wpa-supplicant.d.ts",
44
47
  "default": "./dist/wpa-supplicant.js"
48
+ },
49
+ "./react": {
50
+ "types": "./dist/react.d.ts",
51
+ "default": "./dist/react.js"
45
52
  }
46
53
  },
47
54
  "files": [
@@ -49,6 +56,9 @@
49
56
  ],
50
57
  "license": "MIT",
51
58
  "name": "@domicile-desktop/system-network",
59
+ "peerDependencies": {
60
+ "react": "^19.2.8"
61
+ },
52
62
  "private": false,
53
63
  "publishConfig": {
54
64
  "access": "public"
@@ -64,5 +74,5 @@
64
74
  "test:unit": "bun test"
65
75
  },
66
76
  "type": "module",
67
- "version": "0.0.0-alpha-2edc3c14d846"
77
+ "version": "0.0.0-alpha-b85d9bb6d4af"
68
78
  }