wip: network applet more like mockup

This commit is contained in:
Ashley Wulber 2023-01-04 22:12:46 -05:00
parent b5371f58f7
commit 13ccc03676
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
5 changed files with 376 additions and 139 deletions

31
Cargo.lock generated
View file

@ -668,7 +668,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-panel-config" name = "cosmic-panel-config"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-panel#9502913468dc7bf1cc17da6c1fcf1e274f43a769" source = "git+https://github.com/pop-os/cosmic-panel#bab60b3883bd90b71b1be8bdf771fa11be0cf1dc"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"ron", "ron",
@ -1996,7 +1996,7 @@ dependencies = [
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
@ -2013,7 +2013,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_core" name = "iced_core"
version = "0.6.2" version = "0.6.2"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"palette", "palette",
@ -2023,7 +2023,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_futures" name = "iced_futures"
version = "0.5.1" version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"futures", "futures",
"log", "log",
@ -2035,7 +2035,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_glow" name = "iced_glow"
version = "0.5.1" version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"euclid", "euclid",
@ -2050,7 +2050,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytemuck", "bytemuck",
@ -2070,7 +2070,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_lazy" name = "iced_lazy"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"iced_native", "iced_native",
"ouroboros 0.13.0", "ouroboros 0.13.0",
@ -2079,7 +2079,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_native" name = "iced_native"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
@ -2093,7 +2093,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_sctk" name = "iced_sctk"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"enum-repr", "enum-repr",
"futures", "futures",
@ -2112,7 +2112,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_style" name = "iced_style"
version = "0.5.1" version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"once_cell", "once_cell",
@ -2122,7 +2122,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_swbuf" name = "iced_swbuf"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"cosmic-text", "cosmic-text",
"iced_graphics", "iced_graphics",
@ -2137,7 +2137,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_wgpu" name = "iced_wgpu"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytemuck", "bytemuck",
@ -2327,7 +2327,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]] [[package]]
name = "libcosmic" name = "libcosmic"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#444e389496bb92a928b7731175f00f51ec4f0caa" source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620"
dependencies = [ dependencies = [
"apply", "apply",
"cosmic-panel-config", "cosmic-panel-config",
@ -2336,7 +2336,6 @@ dependencies = [
"freedesktop-icons", "freedesktop-icons",
"iced", "iced",
"iced_core", "iced_core",
"iced_glow",
"iced_lazy", "iced_lazy",
"iced_native", "iced_native",
"iced_style", "iced_style",
@ -3953,9 +3952,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.23.0" version = "1.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes", "bytes",

View file

@ -8,7 +8,7 @@ license = "GPL-3.0-or-later"
once_cell = "1.16.0" once_cell = "1.16.0"
cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "deps" } cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "deps" }
futures-util = "0.3.21" futures-util = "0.3.21"
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] } libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet", "tokio"] }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "3776d4a" } sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "3776d4a" }
futures = "0.3" futures = "0.3"
zbus = { version = "3.6.2", no-default-features = true } zbus = { version = "3.6.2", no-default-features = true }

View file

@ -5,3 +5,12 @@ ipv4 = IPv4 Address
ipv6 = IPv6 Address ipv6 = IPv6 Address
mac = MAC mac = MAC
megabits-per-second = Mbps megabits-per-second = Mbps
connected = Connected
connecting = Connecting
connect = Connect
cancel = Cancel
visible-wireless-networks = Visible Wireless Networks
enter-password = Enter the password or encryption key
router-wps-button = You can also connect by pressing the "WIPS" button on the router
unable-to-connect = Unable to connect to network
check-wifi-connection = Make sure Wi-Fi is connected to the internet and the password is correct

View file

@ -6,15 +6,31 @@ use cosmic::{
popup::{destroy_popup, get_popup}, popup::{destroy_popup, get_popup},
SurfaceIdWrapper, SurfaceIdWrapper,
}, },
widget::{column, container, row, scrollable, text}, widget::{column, container, row, scrollable, text, text_input},
Alignment, Application, Color, Command, Length, Subscription, Alignment, Application, Color, Command, Length, Subscription,
}, },
iced_native::window, iced_native::{
iced_style::{application, svg}, alignment::{Horizontal, Vertical},
layout::Limits,
renderer::BorderRadius,
subscription, window,
},
iced_style::{application, button::StyleSheet, svg},
theme::{Button, Svg}, theme::{Button, Svg},
widget::{button, horizontal_rule, icon, list_column, toggler}, widget::{button, horizontal_rule, icon, list_column, toggler},
Element, Theme, Element, Theme,
}; };
use cosmic::{
iced_style,
widget::segmented_button::{
self,
cosmic::{
horizontal_segmented_selection, horizontal_view_switcher, vertical_segmented_selection,
vertical_view_switcher,
},
},
};
use cosmic_dbus_networkmanager::access_point;
use futures::channel::mpsc::UnboundedSender; use futures::channel::mpsc::UnboundedSender;
use crate::{ use crate::{
@ -30,7 +46,29 @@ pub fn run() -> cosmic::iced::Result {
CosmicNetworkApplet::run(helper.window_settings()) CosmicNetworkApplet::run(helper.window_settings())
} }
#[derive(Clone, Default)] enum NewConnectionState {
EnterPassword {
access_point: AccessPoint,
password: String,
},
Waiting(AccessPoint),
Failure(AccessPoint),
}
impl Into<AccessPoint> for NewConnectionState {
fn into(self) -> AccessPoint {
match self {
NewConnectionState::EnterPassword {
access_point,
password,
} => access_point,
NewConnectionState::Waiting(access_point) => access_point,
NewConnectionState::Failure(access_point) => access_point,
}
}
}
#[derive(Default)]
struct CosmicNetworkApplet { struct CosmicNetworkApplet {
icon_name: String, icon_name: String,
theme: Theme, theme: Theme,
@ -43,6 +81,8 @@ struct CosmicNetworkApplet {
wireless_access_points: Vec<AccessPoint>, wireless_access_points: Vec<AccessPoint>,
active_conns: Vec<ActiveConnectionInfo>, active_conns: Vec<ActiveConnectionInfo>,
nm_sender: Option<UnboundedSender<NetworkManagerRequest>>, nm_sender: Option<UnboundedSender<NetworkManagerRequest>>,
show_visible_networks: bool,
new_connection: Option<NewConnectionState>,
} }
impl CosmicNetworkApplet { impl CosmicNetworkApplet {
@ -72,10 +112,14 @@ enum Message {
TogglePopup, TogglePopup,
ToggleAirplaneMode(bool), ToggleAirplaneMode(bool),
ToggleWiFi(bool), ToggleWiFi(bool),
ToggleVisibleNetworks,
Errored(String), Errored(String),
Ignore, Ignore,
NetworkManagerEvent(NetworkManagerEvent), NetworkManagerEvent(NetworkManagerEvent),
SelectWirelessAccessPoint(String), SelectWirelessAccessPoint(AccessPoint),
CancelNewConnection,
Password(String),
SubmitPassword,
} }
impl Application for CosmicNetworkApplet { impl Application for CosmicNetworkApplet {
@ -109,13 +153,18 @@ impl Application for CosmicNetworkApplet {
let new_id = window::Id::new(self.id_ctr); let new_id = window::Id::new(self.id_ctr);
self.popup.replace(new_id); self.popup.replace(new_id);
let popup_settings = self.applet_helper.get_popup_settings( let mut popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0), window::Id::new(0),
new_id, new_id,
None, None,
None, None,
None, None,
); );
popup_settings.positioner.size_limits = Limits::NONE
.min_height(1)
.min_width(1)
.max_height(600)
.max_width(600);
return get_popup(popup_settings); return get_popup(popup_settings);
} }
} }
@ -166,20 +215,65 @@ impl Application for CosmicNetworkApplet {
if success { if success {
self.wireless_access_points = wireless_access_points; self.wireless_access_points = wireless_access_points;
self.active_conns = active_conns; self.active_conns = active_conns;
self.wifi = wifi_enabled; self.wifi = wifi_enabled;
self.update_icon_name(); self.update_icon_name();
} }
} }
}, },
Message::SelectWirelessAccessPoint(ssid) => { Message::SelectWirelessAccessPoint(access_point) => {
if let Some(tx) = self.nm_sender.as_ref() { // if let Some(tx) = self.nm_sender.as_ref() {
let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(ssid)); // let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(
// access_point.ssid.clone(),
// ));
// }
self.new_connection
.replace(NewConnectionState::EnterPassword {
access_point,
password: String::new(),
});
}
Message::ToggleVisibleNetworks => {
self.new_connection.take();
self.show_visible_networks = !self.show_visible_networks;
}
Message::Password(entered_pw) => {
dbg!(&entered_pw);
match &mut self.new_connection {
Some(NewConnectionState::EnterPassword { password, .. }) => {
*password = entered_pw;
}
_ => {}
} }
} }
Message::SubmitPassword => {
// TODO setup connection
match self.new_connection.take() {
Some(new_connection) => {
self.new_connection
.replace(NewConnectionState::Failure(new_connection.into()));
}
None => {}
}
}
Message::CancelNewConnection => {
self.new_connection.take();
}
} }
Command::none() Command::none()
} }
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> { fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
let button_style = Button::Custom {
active: |t| iced_style::button::Appearance {
border_radius: BorderRadius::from(0.0),
..t.active(&Button::Text)
},
hover: |t| iced_style::button::Appearance {
border_radius: BorderRadius::from(0.0),
..t.hovered(&Button::Text)
},
};
match id { match id {
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(), SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
SurfaceIdWrapper::Window(_) => self SurfaceIdWrapper::Window(_) => self
@ -188,39 +282,23 @@ impl Application for CosmicNetworkApplet {
.on_press(Message::TogglePopup) .on_press(Message::TogglePopup)
.into(), .into(),
SurfaceIdWrapper::Popup(_) => { SurfaceIdWrapper::Popup(_) => {
let name = text(fl!("network")).size(18); let mut list_col = column![];
let icon = icon(&*self.icon_name, 24)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(24))
.height(Length::Units(24));
let mut list_col = list_column();
for conn in &self.active_conns { for conn in &self.active_conns {
let el = match conn { let el = match conn {
ActiveConnectionInfo::Vpn { name, ip_addresses } => { ActiveConnectionInfo::Vpn { name, ip_addresses } => {
let mut ipv4 = column![]; let mut ipv4 = column![];
let mut ipv6 = column![];
for addr in ip_addresses { for addr in ip_addresses {
match addr { match addr {
std::net::IpAddr::V4(a) => { std::net::IpAddr::V4(a) => {
ipv4 = ipv4.push(text(format!( ipv4 = ipv4.push(
"{}: {}", text(format!("{}: {}", fl!("ipv4"), a.to_string()))
fl!("ipv4"), .size(12),
a.to_string() );
)));
}
std::net::IpAddr::V6(a) => {
ipv6 = ipv6.push(text(format!(
"{}: {}",
fl!("ipv6"),
a.to_string()
)));
} }
std::net::IpAddr::V6(a) => {}
} }
} }
column![text(name), ipv4, ipv6].spacing(4) column![text(name), ipv4].spacing(4)
} }
ActiveConnectionInfo::Wired { ActiveConnectionInfo::Wired {
name, name,
@ -229,23 +307,15 @@ impl Application for CosmicNetworkApplet {
ip_addresses, ip_addresses,
} => { } => {
let mut ipv4 = column![]; let mut ipv4 = column![];
let mut ipv6 = column![];
for addr in ip_addresses { for addr in ip_addresses {
match addr { match addr {
std::net::IpAddr::V4(a) => { std::net::IpAddr::V4(a) => {
ipv4 = ipv4.push(text(format!( ipv4 = ipv4.push(
"{}: {}", text(format!("{}: {}", fl!("ipv4"), a.to_string()))
fl!("ipv4"), .size(12),
a.to_string() );
)));
}
std::net::IpAddr::V6(a) => {
ipv6 = ipv6.push(text(format!(
"{}: {}",
fl!("ipv6"),
a.to_string()
)));
} }
std::net::IpAddr::V6(a) => {}
} }
} }
column![ column![
@ -255,27 +325,51 @@ impl Application for CosmicNetworkApplet {
] ]
.spacing(16), .spacing(16),
ipv4, ipv4,
ipv6,
text(format!("{}: {hw_address}", fl!("mac"))),
] ]
.spacing(4) .spacing(4)
} }
ActiveConnectionInfo::WiFi { ActiveConnectionInfo::WiFi {
name, hw_address, .. name, ip_addresses, ..
} => column![row![ } => {
text(name), let mut ipv4 = column![];
text(format!("{}: {hw_address}", fl!("mac"))) for addr in ip_addresses {
] match addr {
.spacing(12)] std::net::IpAddr::V4(a) => {
.spacing(4), ipv4 = ipv4.push(
text(format!("{}: {}", fl!("ipv4"), a.to_string()))
.size(12),
);
}
std::net::IpAddr::V6(a) => {}
}
}
column![button(Button::Secondary)
.custom(vec![
icon("network-wireless-symbolic", 24)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(24))
.height(Length::Units(24))
.into(),
column![text(name).size(14), ipv4,].into(),
text(format!("{}", fl!("connected")))
.size(14)
.width(Length::Fill)
.height(Length::Units(24))
.horizontal_alignment(Horizontal::Right)
.vertical_alignment(Vertical::Center)
.into()
])
.padding([8, 24])
.style(button_style.clone())
.on_press(Message::Ignore)]
}
}; };
list_col = list_col.add(el); list_col = list_col.push(el);
} }
let mut content = column![ let mut content = column![
row![icon, name].spacing(8).width(Length::Fill),
list_col,
horizontal_rule(1),
container( container(
toggler(fl!("airplane-mode"), self.airplane_mode, |m| { toggler(fl!("airplane-mode"), self.airplane_mode, |m| {
Message::ToggleAirplaneMode(m) Message::ToggleAirplaneMode(m)
@ -289,36 +383,178 @@ impl Application for CosmicNetworkApplet {
.width(Length::Fill) .width(Length::Fill)
) )
.padding([0, 12]), .padding([0, 12]),
horizontal_rule(1),
list_col,
] ]
.align_items(Alignment::Center) .align_items(Alignment::Center)
.spacing(8) .spacing(8)
.padding(8); .padding([8, 0]);
if self.wifi { let dropdown_icon = if self.show_visible_networks {
let mut list_col = list_column(); "go-down-symbolic"
for ap in &self.wireless_access_points { } else {
let button = self "go-next-symbolic"
.active_conns };
.iter() let available_connections_btn = button(Button::Secondary)
.find_map(|conn| match conn { .custom(
ActiveConnectionInfo::WiFi { name, .. } if name == &ap.ssid => { vec![
Some( text(fl!("visible-wireless-networks"))
button(Button::Primary) .size(14)
.text(&ap.ssid) .width(Length::Fill)
.on_press(Message::Ignore) .height(Length::Units(24))
.width(Length::Fill), .vertical_alignment(Vertical::Center)
) .into(),
} container(
_ => None, icon(dropdown_icon, 14)
}) .style(Svg::Custom(|theme| svg::Appearance {
.unwrap_or_else(|| { color: Some(theme.palette().text),
button(Button::Text) }))
.text(&ap.ssid) .width(Length::Units(14))
.on_press(Message::SelectWirelessAccessPoint(ap.ssid.clone())) .height(Length::Units(14)),
.width(Length::Fill) )
}); .align_x(Horizontal::Center)
list_col = list_col.add(button); .align_y(Vertical::Center)
.width(Length::Units(24))
.height(Length::Units(24))
.into(),
]
.into(),
)
.padding([8, 24])
.style(button_style.clone())
.on_press(Message::ToggleVisibleNetworks);
content = content.push(available_connections_btn);
if self.show_visible_networks {
if let Some(new_conn_state) = self.new_connection.as_ref() {
match new_conn_state {
NewConnectionState::EnterPassword {
access_point,
password,
} => {
let id = row![
icon("network-wireless-symbolic", 24)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(24))
.height(Length::Units(24)),
text(&access_point.ssid).size(14),
]
.align_items(Alignment::Center)
.width(Length::Fill)
.padding([0, 24])
.spacing(12);
content = content.push(id);
let col = column![
text(fl!("enter-password")),
text_input("", password, Message::Password)
.on_submit(Message::SubmitPassword)
.password(),
container(text(fl!("router-wps-button"))).padding(8),
row![
button(Button::Secondary)
.custom(vec![container(text(fl!("cancel")))
.padding([0, 24])
.into()])
.on_press(Message::CancelNewConnection),
button(Button::Secondary).custom(vec![container(text(
fl!("connect")
))
.padding([0, 24])
.into()])
]
.spacing(24)
]
.spacing(8)
.padding([0, 48])
.align_items(Alignment::Center);
content = content.push(col);
}
NewConnectionState::Waiting(access_point) => {
let connecting = row![
icon("network-wireless-symbolic", 24)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(24))
.height(Length::Units(24)),
text(format!("{}", fl!("connecting")))
.size(14)
.width(Length::Fill)
.height(Length::Units(24))
.horizontal_alignment(Horizontal::Right)
.vertical_alignment(Vertical::Center)
];
content = content.push(connecting);
}
NewConnectionState::Failure(access_point) => {
let id = row![
icon("network-wireless-symbolic", 24)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(24))
.height(Length::Units(24)),
text(&access_point.ssid).size(14),
]
.align_items(Alignment::Center)
.width(Length::Fill)
.padding([0, 24])
.spacing(8);
content = content.push(id);
let col = column![
text(fl!("unable-to-connect")),
text(fl!("check-wifi-connection")),
row![
button(Button::Secondary)
.custom(vec![container(text("Cancel"))
.padding([0, 24])
.into()])
.on_press(Message::CancelNewConnection),
button(Button::Secondary)
.custom(vec![container(text("Connect"))
.padding([0, 24])
.into()])
.on_press(Message::SelectWirelessAccessPoint(
access_point.clone()
))
]
.spacing(24)
]
.spacing(16)
.padding([0, 48])
.align_items(Alignment::Center);
content = content.push(col);
}
}
} else if self.wifi {
let mut list_col = column![];
for ap in &self.wireless_access_points {
if self.active_conns.iter().any(|a| ap.ssid == a.name()) {
continue;
}
let button = button(button_style)
.custom(vec![row![
icon("network-wireless-symbolic", 16)
.style(Svg::Custom(|theme| svg::Appearance {
color: Some(theme.palette().text),
}))
.width(Length::Units(16))
.height(Length::Units(16)),
text(&ap.ssid)
.size(14)
.height(Length::Units(24))
.vertical_alignment(Vertical::Center)
]
.align_items(Alignment::Center)
.spacing(12)
.into()])
.on_press(Message::SelectWirelessAccessPoint(ap.clone()))
.width(Length::Fill)
.padding([8, 24]);
list_col = list_col.push(button);
}
content = content.push(scrollable(list_col).height(Length::Units(300)));
} }
content = content.push(scrollable(list_col).height(Length::Units(300)));
} }
self.applet_helper.popup_container(content).into() self.applet_helper.popup_container(content).into()
} }

View file

@ -39,6 +39,25 @@ pub async fn active_connections(
continue; continue;
} }
for device in connection.devices().await.unwrap_or_default() { for device in connection.devices().await.unwrap_or_default() {
let mut ip_addresses = Vec::new();
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()
{
ip_addresses.push(IpAddr::V6(address_data.address));
}
match device match device
.downcast_to_device() .downcast_to_device()
.await .await
@ -46,25 +65,6 @@ pub async fn active_connections(
.and_then(|inner| inner) .and_then(|inner| inner)
{ {
Some(SpecificDevice::Wired(wired_device)) => { 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()
{
ip_addresses.push(IpAddr::V4(address_data.address));
}
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 { info.push(ActiveConnectionInfo::Wired {
name: connection.id().await?, name: connection.id().await?,
hw_address: wired_device.hw_address().await?, hw_address: wired_device.hw_address().await?,
@ -76,6 +76,7 @@ pub async fn active_connections(
if let Ok(access_point) = wireless_device.active_access_point().await { if let Ok(access_point) = wireless_device.active_access_point().await {
info.push(ActiveConnectionInfo::WiFi { info.push(ActiveConnectionInfo::WiFi {
name: String::from_utf8_lossy(&access_point.ssid().await?).into_owned(), name: String::from_utf8_lossy(&access_point.ssid().await?).into_owned(),
ip_addresses,
hw_address: wireless_device.hw_address().await?, hw_address: wireless_device.hw_address().await?,
flags: access_point.flags().await?, flags: access_point.flags().await?,
rsn_flags: access_point.rsn_flags().await?, rsn_flags: access_point.rsn_flags().await?,
@ -84,25 +85,6 @@ pub async fn active_connections(
} }
} }
Some(SpecificDevice::WireGuard(_)) => { Some(SpecificDevice::WireGuard(_)) => {
let mut ip_addresses = Vec::new();
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()
{
ip_addresses.push(IpAddr::V6(address_data.address));
}
info.push(ActiveConnectionInfo::Vpn { info.push(ActiveConnectionInfo::Vpn {
name: connection.id().await?, name: connection.id().await?,
ip_addresses, ip_addresses,
@ -135,6 +117,7 @@ pub enum ActiveConnectionInfo {
}, },
WiFi { WiFi {
name: String, name: String,
ip_addresses: Vec<IpAddr>,
hw_address: String, hw_address: String,
flags: ApFlags, flags: ApFlags,
rsn_flags: ApSecurityFlags, rsn_flags: ApSecurityFlags,
@ -145,3 +128,13 @@ pub enum ActiveConnectionInfo {
ip_addresses: Vec<IpAddr>, ip_addresses: Vec<IpAddr>,
}, },
} }
impl ActiveConnectionInfo {
pub fn name(&self) -> String {
match &self {
ActiveConnectionInfo::Wired { name, .. } => name.clone(),
ActiveConnectionInfo::WiFi { name, .. } => name.clone(),
ActiveConnectionInfo::Vpn { name, .. } => name.clone(),
}
}
}