CI / test (push) Failing after 30s
A module that exports chandra:desktop/desktop-module (wit/desktop.wit) owns the desktop behind the windows instead of a box in the panel: same sandbox, draw ops and capabilities, drawn at the output's full size and re-rendered on resize. It gets pointer and scroll events only on the empty desktop (windows, panel, popups and menus always win; a drag stays with the module until release), keys only while the desktop has focus, and can draw over the wallpaper or replace it. Its tick() asks for animation frames only while something moves; the main loop sleeps until the next one (wake_timeout), and frames pause while a window covers the desktop, so an idle desktop module costs nothing. Settings > Desktop gets "On the desktop": Wallpaper only, Clock card (default) or any installed desktop module, saved in state.edn as :desktop, loaded at login and reloaded by chandra-ctl reload. Right-click the empty desktop for Module settings and System settings. Hidden settings (empty label) are persisted by the shell, which is how Icon Desktop keeps icon positions. Samples: Icon Desktop (click to launch, drag to arrange, keyboard navigation, count and size settings) and Live Starfield (pointer steers, click or Space warps, wheel sets speed). Served by all hosts: compositor/wasm (native + MoonBit wasmhost) and Rust host-wasm. Docs in docs/desktop-modules.md; tests in compositor/host/desktop_test.mbt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgf1SwPMHVfLUbJKsB
72 lines
2.2 KiB
MoonBit
72 lines
2.2 KiB
MoonBit
///| 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.any_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 => ()
|
|
}
|
|
}
|