///| 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 => () } }