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