Network module: Wi-Fi and wired status, connect to Wi-Fi networks, Wi-Fi and airplane switches
CI / test (push) Failing after 18s
CI / test (push) Failing after 18s
- New `network` panel module (in the default panel, before the battery and the clock): signal bars and the
Wi-Fi network's name, a plug when wired, crossed-out bars offline or in airplane mode. Its
popup shows the status and the last action's outcome ("Couldn't connect to X: wrong
password?"), switches for Wi-Fi and airplane mode, and the networks in range (strongest
access point per name, the one in use first). Click a saved or open network to connect, a new
secured one to type its password in a field under it (Enter or Connect), the one in use to
disconnect, or "Forget" on a saved one. Opening the popup asks for a scan.
- compositor/network: NetworkManager over D-Bus through a small D-Bus client of our own
(wire format, EXTERNAL auth, async calls) on the existing @sys socket calls, so neither host
needed new imports. One ObjectManager.GetManagedObjects + GetAll every 2 s; GetSettings once
per saved connection; RequestScan, Device.Disconnect, WirelessEnabled / WwanEnabled,
ActivateConnection (saved), AddAndActivateConnection (new: open, WPA/WPA2 PSK, WPA3 SAE) and
Settings.Connection.Delete. Without NetworkManager it falls back to read-only status from
/proc/net/dev, /proc/net/wireless and /sys/class/net (no network names there), and looks for
NetworkManager again every 30 s.
- New `network` capability (wit/capabilities.wit): status, wifi-networks, scan, connect,
disconnect, forget, set-wifi-enabled, set-airplane-mode. Served from host tables 8/9 and a
`network(network-request)` request by the wasmer/wasmtime stub (compositor/wasm), host-wasm
and the MoonBit wasmhost. The stub's build_list learned bool fields; request strings are
wiped after use (Wi-Fi passwords).
- Running out of module instances now says "too many modules loaded".
- Deferred: VPN, hotspot, hidden networks, WEP and 802.1X (enterprise) networks, IP settings,
mobile broadband beyond the airplane switch, D-Bus signals (state is polled).
- Tests: D-Bus wire format (incl. the well-known Hello bytes), NetworkManager objects -> status
and list, security settings, /proc parsing; the module through the shell against a fake
backend (list, connect/forget/disconnect, password entry, switches, read-only); a host-wasm
test; and scripts/test-network-dbus.sh, which runs the backend against python-dbusmock's
NetworkManager on a private bus.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hizqNXcNDuef3gxa7D
This commit is contained in:
43 files changed
+4101
-32
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
"chandra/desktop/compositor/renderer" @renderer,
|
||||
"chandra/desktop/compositor/raster" @raster,
|
||||
"chandra/desktop/compositor/wasm" @wasm,
|
||||
"chandra/desktop/compositor/network" @network,
|
||||
}
|
||||
|
||||
supported_targets = "+native+wasm"
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
///| The `network` capability: the shell keeps a network service (compositor/network: NetworkManager
|
||||
/// over D-Bus, else read-only /sys status) while a module imports it, publishes its status and the
|
||||
/// Wi-Fi networks in range as host tables every frame, and hands the module's actions to it.
|
||||
|
||||
///| Start the network service if a module needs it (tests can set their own first).
|
||||
fn DesktopShell::network(self : DesktopShell) -> @network.NetService {
|
||||
match self.net {
|
||||
Some(n) => n
|
||||
None => {
|
||||
let n = @network.NetService::new()
|
||||
self.net = Some(n)
|
||||
n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Use `b` for network status and actions (tests: a fake backend).
|
||||
pub fn DesktopShell::set_network_backend(self : DesktopShell, b : &@network.NetBackend) -> Unit {
|
||||
match self.net {
|
||||
Some(n) => n.close()
|
||||
None => ()
|
||||
}
|
||||
self.net = Some(@network.NetService::with_backend(b))
|
||||
}
|
||||
|
||||
///| Refresh and publish network state while a module imports `network`; drop the service (and
|
||||
/// its bus connection) when none does any more.
|
||||
fn DesktopShell::publish_network(self : DesktopShell) -> Unit {
|
||||
if !self.widgets.iter().any(w => w.has_cap("network")) {
|
||||
match self.net {
|
||||
Some(n) if n.probe() => {
|
||||
n.close()
|
||||
self.net = None
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
return
|
||||
}
|
||||
let net = self.network()
|
||||
net.tick(@sys.monotonic_ms())
|
||||
let s = net.status()
|
||||
let st = @wasm.Table::new()
|
||||
st.int(s.state.code())
|
||||
st.int(s.signal)
|
||||
st.str(s.name)
|
||||
st.str(s.message)
|
||||
st.int(if s.wifi_enabled { 1 } else { 0 })
|
||||
st.int(if s.airplane { 1 } else { 0 })
|
||||
st.int(if s.managed { 1 } else { 0 })
|
||||
st.int(if s.has_wifi { 1 } else { 0 })
|
||||
st.end_row()
|
||||
@wasm.publish(NetStatus, st)
|
||||
let nt = @wasm.Table::new()
|
||||
for w in net.networks() {
|
||||
nt.str(w.ssid)
|
||||
nt.int(w.signal)
|
||||
nt.int(if w.secured { 1 } else { 0 })
|
||||
nt.int(if w.active { 1 } else { 0 })
|
||||
nt.int(if w.saved { 1 } else { 0 })
|
||||
nt.end_row()
|
||||
}
|
||||
@wasm.publish(NetNetworks, nt)
|
||||
}
|
||||
|
||||
///| A network module's request.
|
||||
fn DesktopShell::network_request(self : DesktopShell, code : Int, ssid : String, password : String) -> Unit {
|
||||
match @network.NetAction::from_code(code, ssid, password) {
|
||||
Some(a) => self.network().act(a)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
@@ -235,6 +235,8 @@ pub(all) struct DesktopShell {
|
||||
/// What the screenshot module is told (the compositor sets it every frame): bit 0 a
|
||||
/// recording is running, bit 1 recordings show the pointer.
|
||||
mut screenshot_state : Int
|
||||
/// The network service (network.mbt), while a module imports `network`.
|
||||
mut net : @network.NetService?
|
||||
mut remember_windows : Bool
|
||||
/// Dark mode (the configured theme) or light (Moon Day); saved as `:theme :light` when off.
|
||||
mut dark_mode : Bool
|
||||
@@ -342,6 +344,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
bg_key: None,
|
||||
restore_session: true,
|
||||
screenshot_state: 2,
|
||||
net: None,
|
||||
remember_windows: true,
|
||||
dark_mode: true,
|
||||
screen_off_min: default_screen_off_min,
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "screenshot", "session-settings",
|
||||
"logout",
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital12", "screenshot",
|
||||
"session-settings", "logout",
|
||||
]
|
||||
|
||||
///| A fresh panel's modules: the defaults, plus the battery before the clock on a machine that
|
||||
@@ -463,6 +463,7 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
|
||||
let b = self.battery.refresh()
|
||||
@wasm.publish_battery(b.percent, b.state, b.secs_left)
|
||||
}
|
||||
self.publish_network()
|
||||
let it = @wasm.Table::new()
|
||||
for w in self.widgets {
|
||||
it.str(w.slot)
|
||||
@@ -577,6 +578,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
|
||||
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
|
||||
Some(SetSuspendAfter(m)) => self.set_power_timeouts(self.screen_off_min, m)
|
||||
Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
|
||||
Some(Network(code, ssid, password)) => self.network_request(code, ssid, password)
|
||||
Some(SetInspector(on)) => self.set_inspecting(on)
|
||||
Some(LoadModule(path)) => {
|
||||
match self.load_path(path) {
|
||||
|
||||
Reference in new issue
Block a user