update applets using latest libcosmic auto-sizing popups
This commit is contained in:
parent
a1aa87f5bd
commit
88b4a7d20b
13 changed files with 319 additions and 251 deletions
|
|
@ -2,8 +2,12 @@ use cosmic::{
|
|||
applet::CosmicAppletHelper,
|
||||
iced::{
|
||||
executor,
|
||||
wayland::{
|
||||
popup::{destroy_popup, get_popup},
|
||||
SurfaceIdWrapper,
|
||||
},
|
||||
widget::{column, container, row, scrollable, text},
|
||||
Alignment, Application, Color, Command, Length, Subscription, wayland::{popup::{destroy_popup, get_popup}, SurfaceIdWrapper},
|
||||
Alignment, Application, Color, Command, Length, Subscription,
|
||||
},
|
||||
iced_native::window,
|
||||
iced_style::{application, svg},
|
||||
|
|
@ -44,26 +48,22 @@ struct CosmicNetworkApplet {
|
|||
impl CosmicNetworkApplet {
|
||||
fn update_icon_name(&mut self) {
|
||||
self.icon_name = self
|
||||
.active_conns
|
||||
.iter()
|
||||
.fold("network-offline-symbolic", |icon_name, conn| {
|
||||
match (icon_name, conn) {
|
||||
("network-offline-symbolic", ActiveConnectionInfo::WiFi { .. }) => {
|
||||
"network-wireless-symbolic"
|
||||
.active_conns
|
||||
.iter()
|
||||
.fold("network-offline-symbolic", |icon_name, conn| {
|
||||
match (icon_name, conn) {
|
||||
("network-offline-symbolic", ActiveConnectionInfo::WiFi { .. }) => {
|
||||
"network-wireless-symbolic"
|
||||
}
|
||||
("network-offline-symbolic", ActiveConnectionInfo::Wired { .. })
|
||||
| ("network-wireless-symbolic", ActiveConnectionInfo::Wired { .. }) => {
|
||||
"network-wired-symbolic"
|
||||
}
|
||||
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
|
||||
_ => icon_name,
|
||||
}
|
||||
(
|
||||
"network-offline-symbolic",
|
||||
ActiveConnectionInfo::Wired { .. },
|
||||
)
|
||||
| (
|
||||
"network-wireless-symbolic",
|
||||
ActiveConnectionInfo::Wired { .. },
|
||||
) => "network-wired-symbolic",
|
||||
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
|
||||
_ => icon_name,
|
||||
}
|
||||
})
|
||||
.to_string()
|
||||
})
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ impl Application for CosmicNetworkApplet {
|
|||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(420, 600),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
|
@ -156,14 +156,20 @@ impl Application for CosmicNetworkApplet {
|
|||
self.active_conns = conns;
|
||||
self.update_icon_name();
|
||||
}
|
||||
NetworkManagerEvent::RequestResponse { wireless_access_points, active_conns, wifi_enabled, success, ..} => {
|
||||
NetworkManagerEvent::RequestResponse {
|
||||
wireless_access_points,
|
||||
active_conns,
|
||||
wifi_enabled,
|
||||
success,
|
||||
..
|
||||
} => {
|
||||
if success {
|
||||
self.wireless_access_points = wireless_access_points;
|
||||
self.active_conns = active_conns;
|
||||
self.wifi = wifi_enabled;
|
||||
self.update_icon_name();
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
Message::SelectWirelessAccessPoint(ssid) => {
|
||||
if let Some(tx) = self.nm_sender.as_ref() {
|
||||
|
|
@ -312,7 +318,7 @@ impl Application for CosmicNetworkApplet {
|
|||
});
|
||||
list_col = list_col.add(button);
|
||||
}
|
||||
content = content.push(scrollable(list_col).height(Length::Fill));
|
||||
content = content.push(scrollable(list_col).height(Length::Units(300)));
|
||||
}
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,22 @@ pub async fn active_connections(
|
|||
for connection in active_connections {
|
||||
if connection.vpn().await.unwrap_or_default() {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in connection
|
||||
.ip4_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in connection
|
||||
.ip6_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Vpn {
|
||||
|
|
@ -27,13 +39,30 @@ pub async fn active_connections(
|
|||
continue;
|
||||
}
|
||||
for device in connection.devices().await.unwrap_or_default() {
|
||||
match device.downcast_to_device().await.ok().and_then(|inner| inner) {
|
||||
match device
|
||||
.downcast_to_device()
|
||||
.await
|
||||
.ok()
|
||||
.and_then(|inner| inner)
|
||||
{
|
||||
Some(SpecificDevice::Wired(wired_device)) => {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in device.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in device
|
||||
.ip4_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in device.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in device
|
||||
.ip6_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Wired {
|
||||
|
|
@ -56,10 +85,22 @@ pub async fn active_connections(
|
|||
}
|
||||
Some(SpecificDevice::WireGuard(_)) => {
|
||||
let mut ip_addresses = Vec::new();
|
||||
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in connection
|
||||
.ip4_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V4(address_data.address));
|
||||
}
|
||||
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
|
||||
for address_data in connection
|
||||
.ip6_config()
|
||||
.await?
|
||||
.address_data()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
{
|
||||
ip_addresses.push(IpAddr::V6(address_data.address));
|
||||
}
|
||||
info.push(ActiveConnectionInfo::Vpn {
|
||||
|
|
@ -71,14 +112,12 @@ pub async fn active_connections(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
info.sort_by(|a, b| {
|
||||
let helper = |conn: &ActiveConnectionInfo| {
|
||||
match conn {
|
||||
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
|
||||
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
|
||||
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
|
||||
}
|
||||
let helper = |conn: &ActiveConnectionInfo| match conn {
|
||||
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
|
||||
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
|
||||
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
|
||||
};
|
||||
helper(a).cmp(&helper(b))
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue