diff --git a/Cargo.lock b/Cargo.lock index f7efac66..77852eb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "cosmic-dbus-networkmanager" version = "0.1.0" -source = "git+https://github.com/pop-os/dbus-settings-bindings#c9cb2c256eb956e0c09cb5c4409b0bb59e455b7f" +source = "git+https://github.com/pop-os/dbus-settings-bindings#2ef53b2bfae2525f45ec27065397f9c2d7cf30fe" dependencies = [ "bitflags 2.4.1", "derive_builder", diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index 3dd47ee6..369164e3 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -21,7 +21,9 @@ use cosmic::{ widget::{button, divider, icon}, Element, Theme, }; -use cosmic_dbus_networkmanager::interface::enums::{ActiveConnectionState, DeviceState}; +use cosmic_dbus_networkmanager::interface::enums::{ + ActiveConnectionState, DeviceState, NmConnectivityState, +}; use cosmic_time::{anim, chain, id, once_cell::sync::Lazy, Instant, Timeline}; use futures::channel::mpsc::UnboundedSender; @@ -306,6 +308,20 @@ impl cosmic::Application for CosmicNetworkApplet { } } } + + if self.nm_state.connectivity != state.connectivity + && !matches!(req, NetworkManagerRequest::Reload) + && matches!(state.connectivity, NmConnectivityState::Portal) + { + // spawn browser + if let Err(err) = std::process::Command::new("xdg-open") + .arg("http://pop.system76.com") + .spawn() + { + log::error!("Failed to open browser: {}", err); + } + } + self.update_nm_state(state); } }, diff --git a/cosmic-applet-network/src/network_manager/mod.rs b/cosmic-applet-network/src/network_manager/mod.rs index 9153a0fb..ef0a3920 100644 --- a/cosmic-applet-network/src/network_manager/mod.rs +++ b/cosmic-applet-network/src/network_manager/mod.rs @@ -11,8 +11,8 @@ use cosmic_dbus_networkmanager::{ device::SpecificDevice, interface::{ active_connection::ActiveConnectionProxy, - enums::DeviceType, enums::{self, ActiveConnectionState}, + enums::{DeviceType, NmConnectivityState}, }, nm::NetworkManager, settings::{connection::Settings, NetworkManagerSettings}, @@ -512,19 +512,33 @@ pub enum NetworkManagerEvent { ActiveConns(NetworkManagerState), } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub struct NetworkManagerState { pub wireless_access_points: Vec, pub active_conns: Vec, pub known_access_points: Vec, pub wifi_enabled: bool, pub airplane_mode: bool, + pub connectivity: NmConnectivityState, +} + +impl Default for NetworkManagerState { + fn default() -> Self { + Self { + wireless_access_points: Vec::new(), + active_conns: Vec::new(), + known_access_points: Vec::new(), + wifi_enabled: false, + airplane_mode: false, + connectivity: NmConnectivityState::Unknown, + } + } } impl NetworkManagerState { pub async fn new(conn: &Connection) -> anyhow::Result { let network_manager = NetworkManager::new(conn).await?; - let mut _self = Self::default(); + let mut self_ = Self::default(); // airplane mode let airplaine_mode = Command::new("rfkill") .arg("list") @@ -532,8 +546,8 @@ impl NetworkManagerState { .output() .await?; let airplane_mode = std::str::from_utf8(&airplaine_mode.stdout).unwrap_or_default(); - _self.wifi_enabled = network_manager.wireless_enabled().await.unwrap_or_default(); - _self.airplane_mode = airplane_mode.contains("Soft blocked: yes") && !_self.wifi_enabled; + self_.wifi_enabled = network_manager.wireless_enabled().await.unwrap_or_default(); + self_.airplane_mode = airplane_mode.contains("Soft blocked: yes") && !self_.wifi_enabled; let s = NetworkManagerSettings::new(conn).await?; _ = s.load_connections(&[]).await; @@ -595,10 +609,12 @@ impl NetworkManagerState { .cloned() .collect(); wireless_access_points.sort_by(|a, b| b.strength.cmp(&a.strength)); - _self.wireless_access_points = wireless_access_points; - _self.active_conns = active_conns; - _self.known_access_points = known_access_points; - Ok(_self) + self_.wireless_access_points = wireless_access_points; + self_.active_conns = active_conns; + self_.known_access_points = known_access_points; + self_.connectivity = network_manager.connectivity().await?; + + Ok(self_) } #[allow(dead_code)]