@domicile-desktop/system-network
v0.0.0-alpha-bfbc2e9a3043
Published
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.
Readme
@domicile-desktop/system-network
The network for a Domicile shell, from NetworkManager, iwd or wpa_supplicant:
connectivity and the primary connection, with the Wi-Fi network's name and
signal. The Wi-Fi device, from NetworkManager or iwd: its networks and
connection, and the requests that change them. Built on
@domicile-desktop/sdk/system.
Usage
import { system } from "@domicile-desktop/sdk/system";
import { watchNetwork } from "@domicile-desktop/system-network/network";
const stop = watchNetwork(system(domicile), (network) => {
network.match({
Err: () => hide(),
Ok: ({ connectivity, link }) => show(connectivity, link),
});
});watchNetworkwatches the first service on the system bus, byNameHasOwner: NetworkManager, then iwd, then wpa_supplicant. With none, it watches NetworkManager. It does not switch if another starts later.- To force one, call its watch, which takes the same arguments:
| Export | Service | Reads |
|---|---|---|
| networkmanager watchNetworkManager | org.freedesktop.NetworkManager | connectivity; link is None, Wired, Wifi or Other (VPNs and the rest) |
| iwd watchIwd | net.connman.iwd | the connected station's network; signal from GetOrderedNetworks |
| wpa-supplicant watchWpaSupplicant | fi.w1.wpa_supplicant1 (only with -u) | the current BSS of an interface that is completed or rekeying (group_handshake) |
- iwd and wpa_supplicant know only Wi-Fi:
connectivityis alwaysUnknown, andlinkisWifiorNone, even with a cable plugged in. strengthis 0 through 1. Both grade dBm as NetworkManager does: -100 dBm is 0, -40 dBm is 1. iwd's signal changes after each scan.- Reports once, then after each change the service signals.
- An
Erris a D-Bus failure, such as the service not running. - A bug or an unexpected reply shape throws, logged to the console.
Wi-Fi
import { connectWifi, watchWifi } from "@domicile-desktop/system-network/wifi";
const stop = watchWifi(host, (wifi) => {
wifi.match({
Err: () => hide(),
Ok: (found) => found.match({ None: () => hide(), Some: (device) => show(device) }),
});
});
await connectWifi(host, device, network, "passphrase");watchWifiwatches the first Wi-Fi device of NetworkManager, else iwd, byNameHasOwner.Noneis no device, or neither service. wpa_supplicant is not controlled.- Requests:
setWifiEnabled,scanWifi,connectWifi,disconnectWifi. Each resolvesOkonce the service accepts it; the watch reports the outcome. connectWifiuses a network's saved profile when it has one. A new secured network needs a passphrase:- NetworkManager: a new WPA-PSK profile, saved.
- iwd:
iwctl --passphrase … station <interface> connect <ssid>, since iwd asks an agent for it and a page cannot serve one.iwctlmust be on the compositor'sPATH.
- NetworkManager reads re-run on each property change of an object read, an
access point coming or going, or a device coming or going. It does not say
when a scan runs, so
scanningis alwaysfalse. - iwd does not report addresses, so
connection.ipisundefined.
Test
bun run turbo test --filter @domicile-desktop/system-networkTests replay D-Bus replies, in the compositor's JSON, through an injected
System.
