pub struct Network { /* private fields */ }Expand description
Networking from NetworkManager, from cx.network(). Cloning it is
cheap.
Implementations§
Source§impl Network
impl Network
Sourcepub fn wifi_enabled(&self) -> ReadSignal<bool>
pub fn wifi_enabled(&self) -> ReadSignal<bool>
Whether Wi-Fi is on. false while NetworkManager isn’t running.
Sourcepub fn connectivity(&self) -> ReadSignal<Connectivity>
pub fn connectivity(&self) -> ReadSignal<Connectivity>
How far the host reaches, from NetworkManager’s own checks.
Unknown while it isn’t running.
Sourcepub fn devices(&self) -> ReadSignal<Vec<NetworkDevice>>
pub fn devices(&self) -> ReadSignal<Vec<NetworkDevice>>
Every device but loopback and those NetworkManager doesn’t manage, in NetworkManager’s numbering. Empty while it isn’t running.
Sourcepub fn wifi_networks(&self) -> ReadSignal<Vec<WifiNetwork>>
pub fn wifi_networks(&self) -> ReadSignal<Vec<WifiNetwork>>
The Wi-Fi networks each device sees, one per name and device, strongest first. Hidden networks are left out. Empty while NetworkManager isn’t running.
Sourcepub fn scanner(&self) -> Scanner
pub fn scanner(&self) -> Scanner
Asks every Wi-Fi device that is on to look for networks now and
every 10 s after, while the context that called cx.network() lives,
so call it inside the popup that shows the networks. Scanners share
one timer. NetworkManager’s refusal of a scan too soon after another
is logged only at debug.
Sourcepub fn set_wifi_enabled(&self, enabled: bool)
pub fn set_wifi_enabled(&self, enabled: bool)
Turns Wi-Fi on or off.
Sourcepub fn scan(&self, device: &str)
pub fn scan(&self, device: &str)
Asks the Wi-Fi device at device, its path, to look for networks.
NetworkManager refuses a scan right after another, and that is
logged.
Sourcepub fn connect(&self, network: &WifiNetwork, password: Option<&str>)
pub fn connect(&self, network: &WifiNetwork, password: Option<&str>)
Connects network’s device to it. Without a password,
NetworkManager uses a connection saved for it, and refuses if it has
none. With one, it saves a new WPA connection and uses that. A
refusal is logged, never the password.
Sourcepub fn disconnect(&self, device: &str)
pub fn disconnect(&self, device: &str)
Disconnects the device at device, until it is connected again.
Sourcepub fn saved_connections(&self) -> ReadSignal<Vec<SavedConnection>>
pub fn saved_connections(&self) -> ReadSignal<Vec<SavedConnection>>
The connections NetworkManager saved, in its numbering, at most 256. NetworkManager is asked for them on the first call and followed from then on, so a config that never lists them reads none. Empty while it isn’t running.
Sourcepub fn forget(&self, uuid: &str)
pub fn forget(&self, uuid: &str)
Deletes the saved connection uuid names, so NetworkManager
forgets that network. A refusal is logged.
Sourcepub fn clear_secrets(&self, uuid: &str)
pub fn clear_secrets(&self, uuid: &str)
Takes the secrets, such as a Wi-Fi password, out of the saved
connection uuid names, so NetworkManager asks for them next time.
A refusal is logged.
Sourcepub fn add_connection(&self, settings: &Json)
pub fn add_connection(&self, settings: &Json)
Saves a new connection with settings, by group and name as
SavedConnection::settings holds them. Secrets such as a Wi-Fi
psk may come too. An SSID or a hardware address may come as text.
A value of a shape NetworkManager has no type for, or a refusal, is
logged, never the settings.
fn save_cafe(network: &Network, password: &str) {
network.add_connection(&serde_json::json!({
"connection": { "id": "cafe", "type": "802-11-wireless" },
"802-11-wireless": { "ssid": "cafe" },
"802-11-wireless-security": { "key-mgmt": "wpa-psk", "psk": password },
}));
}Sourcepub fn update_connection(&self, uuid: &str, settings: &Json)
pub fn update_connection(&self, uuid: &str, settings: &Json)
Replaces the settings of the saved connection uuid names with
settings, as add_connection takes them.
Those left out go back to NetworkManager’s defaults. NetworkManager
keeps the saved secrets when settings carries none, and drops them
all once it carries any, so a new psk alone on an 802.1X connection
drops its other passwords.