refactor(network): update the icon name for disconnected state, and improve subscriptions
This commit is contained in:
parent
2c9470bdd7
commit
a9b82222c4
5 changed files with 56 additions and 27 deletions
|
|
@ -119,11 +119,13 @@ impl CosmicNetworkApplet {
|
|||
.nm_state
|
||||
.active_conns
|
||||
.iter()
|
||||
.fold("network-offline-symbolic", |icon_name, conn| {
|
||||
match (icon_name, conn) {
|
||||
("network-offline-symbolic", ActiveConnectionInfo::WiFi { strength, .. }) => {
|
||||
wifi_icon(*strength)
|
||||
}
|
||||
.fold(
|
||||
"network-wired-disconnected-symbolic",
|
||||
|icon_name, conn| match (icon_name, conn) {
|
||||
(
|
||||
"network-wired-disconnected-symbolic",
|
||||
ActiveConnectionInfo::WiFi { strength, .. },
|
||||
) => wifi_icon(*strength),
|
||||
(_, ActiveConnectionInfo::Wired { .. })
|
||||
if icon_name != "network-vpn-symbolic" =>
|
||||
{
|
||||
|
|
@ -131,8 +133,8 @@ impl CosmicNetworkApplet {
|
|||
}
|
||||
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
|
||||
_ => icon_name,
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
.to_string()
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +235,9 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.min_width(1.0)
|
||||
.max_height(800.0)
|
||||
.max_width(400.0);
|
||||
if let Some(tx) = self.nm_sender.as_mut() {
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::Reload);
|
||||
}
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
|
|
@ -799,12 +804,13 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.map(|(_, now)| Message::Frame(now));
|
||||
|
||||
if let Some(conn) = self.conn.as_ref() {
|
||||
let has_popup = self.popup.is_some();
|
||||
Subscription::batch(vec![
|
||||
timeline,
|
||||
network_sub,
|
||||
active_conns_subscription(self.toggle_wifi_ctr, conn.clone())
|
||||
.map(Message::NetworkManagerEvent),
|
||||
devices_subscription(self.toggle_wifi_ctr, conn.clone())
|
||||
devices_subscription(self.toggle_wifi_ctr, has_popup, conn.clone())
|
||||
.map(Message::NetworkManagerEvent),
|
||||
wireless_enabled_subscription(self.toggle_wifi_ctr, conn.clone())
|
||||
.map(Message::NetworkManagerEvent),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ pub fn active_conns_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>
|
|||
async move {
|
||||
loop {
|
||||
state = start_listening(state, &mut output).await;
|
||||
_ = tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -49,10 +48,15 @@ async fn start_listening(
|
|||
let mut active_conns_changed = network_manager.receive_active_connections_changed().await;
|
||||
active_conns_changed.next().await;
|
||||
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
while let (Some(_change), _) = tokio::join!(
|
||||
active_conns_changed.next(),
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1))
|
||||
) {
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::ActiveConns(new_state))
|
||||
.await;
|
||||
}
|
||||
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::ActiveConns(new_state))
|
||||
.await;
|
||||
State::Continue(conn)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,16 @@ use zbus::Connection;
|
|||
|
||||
pub fn devices_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||
id: I,
|
||||
has_popup: bool,
|
||||
conn: Connection,
|
||||
) -> iced::Subscription<NetworkManagerEvent> {
|
||||
let initial = State::Continue(conn.clone());
|
||||
subscription::channel(id, 50, move |mut output| {
|
||||
subscription::channel((id, has_popup), 50, move |mut output| {
|
||||
let mut state = initial.clone();
|
||||
|
||||
async move {
|
||||
loop {
|
||||
state = start_listening(state, &mut output).await;
|
||||
_ = tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
state = start_listening(state, has_popup, &mut output).await;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -32,6 +32,7 @@ pub enum State {
|
|||
|
||||
async fn start_listening(
|
||||
state: State,
|
||||
has_popup: bool,
|
||||
output: &mut futures::channel::mpsc::Sender<NetworkManagerEvent>,
|
||||
) -> State {
|
||||
let conn = match state {
|
||||
|
|
@ -47,11 +48,17 @@ async fn start_listening(
|
|||
};
|
||||
|
||||
let mut devices_changed = network_manager.receive_devices_changed().await;
|
||||
devices_changed.next().await;
|
||||
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::WirelessAccessPoints(new_state))
|
||||
.await;
|
||||
let secs = if has_popup { 4 } else { 60 };
|
||||
while let (Some(_change), _) = tokio::join!(
|
||||
devices_changed.next(),
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(secs))
|
||||
) {
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::WirelessAccessPoints(new_state))
|
||||
.await;
|
||||
}
|
||||
|
||||
State::Continue(conn)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -472,6 +472,16 @@ async fn start_listening(
|
|||
})
|
||||
.await;
|
||||
}
|
||||
Some(NetworkManagerRequest::Reload) => {
|
||||
let state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::RequestResponse {
|
||||
req: NetworkManagerRequest::Reload,
|
||||
success: true,
|
||||
state,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
_ => {
|
||||
return State::Finished;
|
||||
}
|
||||
|
|
@ -490,6 +500,7 @@ pub enum NetworkManagerRequest {
|
|||
SelectAccessPoint(String),
|
||||
Disconnect(String),
|
||||
Password(String, String),
|
||||
Reload,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ pub fn wireless_enabled_subscription<I: 'static + Hash + Copy + Send + Sync + De
|
|||
async move {
|
||||
loop {
|
||||
state = start_listening(state, &mut output).await;
|
||||
_ = tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -38,6 +37,7 @@ async fn start_listening(
|
|||
State::Continue(conn) => conn,
|
||||
State::Error => iced::futures::future::pending().await,
|
||||
};
|
||||
|
||||
let network_manager = match NetworkManager::new(&conn).await {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
|
|
@ -47,11 +47,12 @@ async fn start_listening(
|
|||
};
|
||||
|
||||
let mut wireless_enabled_changed = network_manager.receive_wireless_enabled_changed().await;
|
||||
wireless_enabled_changed.next().await;
|
||||
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::WiFiEnabled(new_state))
|
||||
.await;
|
||||
while let Some(_change) = wireless_enabled_changed.next().await {
|
||||
let new_state = NetworkManagerState::new(&conn).await.unwrap_or_default();
|
||||
_ = output
|
||||
.send(NetworkManagerEvent::WiFiEnabled(new_state))
|
||||
.await;
|
||||
}
|
||||
State::Continue(conn)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue