fix: allow network resets

also updates libcosmic and cosmic-protocolss, and adds clipboard support to the network applet
This commit is contained in:
Ashley Wulber 2024-06-13 19:45:37 -04:00
parent 91786f50a3
commit d1a6e089b4
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
6 changed files with 280 additions and 80 deletions

146
Cargo.lock generated
View file

@ -174,7 +174,7 @@ dependencies = [
"url",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols 0.31.2",
"zbus 4.2.2",
]
@ -715,7 +715,7 @@ dependencies = [
[[package]]
name = "clipboard_macos"
version = "0.1.0"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"objc",
"objc-foundation",
@ -725,7 +725,7 @@ dependencies = [
[[package]]
name = "clipboard_wayland"
version = "0.2.2"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"dnd",
"mime 0.1.0",
@ -735,7 +735,7 @@ dependencies = [
[[package]]
name = "clipboard_x11"
version = "0.4.2"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"thiserror",
"x11rb",
@ -1184,11 +1184,11 @@ dependencies = [
[[package]]
name = "cosmic-client-toolkit"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=e4e6f8c#e4e6f8ca4d7c239c02a8cdfd48a74cb0969425eb"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=c8d3a1c#c8d3a1c3d40d16235f4720969a54ed570ec7a976"
dependencies = [
"cosmic-protocols",
"libc",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"wayland-client",
]
@ -1205,7 +1205,7 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"atomicwrites",
"cosmic-config-derive",
@ -1227,7 +1227,7 @@ dependencies = [
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"quote",
"syn 1.0.109",
@ -1291,21 +1291,22 @@ dependencies = [
"cosmic-config",
"ron",
"serde",
"smithay-client-toolkit",
"smithay-client-toolkit 0.18.0",
"tracing",
"wayland-protocols-wlr",
"wayland-protocols-wlr 0.2.0",
"xdg-shell-wrapper-config",
]
[[package]]
name = "cosmic-protocols"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=e4e6f8c#e4e6f8ca4d7c239c02a8cdfd48a74cb0969425eb"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=c8d3a1c#c8d3a1c3d40d16235f4720969a54ed570ec7a976"
dependencies = [
"bitflags 2.5.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols 0.32.1",
"wayland-protocols-wlr 0.3.1",
"wayland-scanner",
"wayland-server",
]
@ -1321,7 +1322,7 @@ dependencies = [
[[package]]
name = "cosmic-text"
version = "0.11.2"
source = "git+https://github.com/pop-os/cosmic-text.git#a3a6262e5d654bf6d110f18e6b7b8a31a764e64f"
source = "git+https://github.com/pop-os/cosmic-text.git#8bb45d7aca5b4a109924f3162d670297b6bd4a19"
dependencies = [
"bitflags 2.5.0",
"fontdb",
@ -1343,7 +1344,7 @@ dependencies = [
[[package]]
name = "cosmic-theme"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"almost",
"cosmic-config",
@ -1770,12 +1771,12 @@ dependencies = [
[[package]]
name = "dnd"
version = "0.1.0"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"bitflags 2.5.0",
"mime 0.1.0",
"raw-window-handle",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"smithay-clipboard",
]
@ -2764,7 +2765,7 @@ dependencies = [
[[package]]
name = "iced"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"dnd",
"iced_accessibility",
@ -2782,7 +2783,7 @@ dependencies = [
[[package]]
name = "iced_accessibility"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"accesskit",
"accesskit_unix",
@ -2791,7 +2792,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"bitflags 2.5.0",
"dnd",
@ -2802,7 +2803,7 @@ dependencies = [
"palette",
"raw-window-handle",
"serde",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"smol_str",
"thiserror",
"web-time",
@ -2813,7 +2814,7 @@ dependencies = [
[[package]]
name = "iced_futures"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"futures",
"iced_core",
@ -2826,7 +2827,7 @@ dependencies = [
[[package]]
name = "iced_graphics"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -2850,7 +2851,7 @@ dependencies = [
[[package]]
name = "iced_renderer"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"iced_graphics",
"iced_tiny_skia",
@ -2862,13 +2863,13 @@ dependencies = [
[[package]]
name = "iced_runtime"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"dnd",
"iced_accessibility",
"iced_core",
"iced_futures",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"thiserror",
"window_clipboard",
]
@ -2876,7 +2877,7 @@ dependencies = [
[[package]]
name = "iced_sctk"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"enum-repr",
"float-cmp",
@ -2888,11 +2889,11 @@ dependencies = [
"itertools 0.12.1",
"lazy_static",
"raw-window-handle",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"thiserror",
"tracing",
"wayland-backend",
"wayland-protocols",
"wayland-protocols 0.32.1",
"window_clipboard",
"xkbcommon",
"xkbcommon-dl",
@ -2902,7 +2903,7 @@ dependencies = [
[[package]]
name = "iced_style"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"iced_core",
"once_cell",
@ -2912,7 +2913,7 @@ dependencies = [
[[package]]
name = "iced_tiny_skia"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"bytemuck",
"cosmic-text",
@ -2929,7 +2930,7 @@ dependencies = [
[[package]]
name = "iced_wgpu"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -2944,10 +2945,10 @@ dependencies = [
"raw-window-handle",
"resvg",
"rustix 0.38.34",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols 0.32.1",
"wayland-sys",
"wgpu",
]
@ -2955,7 +2956,7 @@ dependencies = [
[[package]]
name = "iced_widget"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"dnd",
"iced_renderer",
@ -2963,7 +2964,7 @@ dependencies = [
"iced_style",
"num-traits",
"ouroboros",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"thiserror",
"unicode-segmentation",
"window_clipboard",
@ -3636,7 +3637,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libcosmic"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#7abcec759101c624329cccb1b63924a748ed04ae"
source = "git+https://github.com/pop-os/libcosmic#f820eb7ffe8ad6e5931f481469eeb79d1a68ab50"
dependencies = [
"apply",
"ashpd",
@ -3969,7 +3970,7 @@ dependencies = [
[[package]]
name = "mime"
version = "0.1.0"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"smithay-clipboard",
]
@ -5290,7 +5291,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "smithay-client-toolkit"
version = "0.18.0"
source = "git+https://github.com/smithay/client-toolkit//?rev=3bed072#3bed072b966022f5f929d12f3aff089b1ace980b"
source = "git+https://github.com/smithay/client-toolkit?rev=3bed072#3bed072b966022f5f929d12f3aff089b1ace980b"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -5307,8 +5308,36 @@ dependencies = [
"wayland-client",
"wayland-csd-frame",
"wayland-cursor",
"wayland-protocols",
"wayland-protocols-wlr",
"wayland-protocols 0.31.2",
"wayland-protocols-wlr 0.2.0",
"wayland-scanner",
"xkbcommon",
"xkeysym",
]
[[package]]
name = "smithay-client-toolkit"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "837d3067369e24aeda699a5d9fc5aa14ca14a84dd70aeed7156bfa04a5605b32"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
"calloop",
"calloop-wayland-source",
"cursor-icon",
"libc",
"log",
"memmap2 0.9.4",
"pkg-config",
"rustix 0.38.34",
"thiserror",
"wayland-backend",
"wayland-client",
"wayland-csd-frame",
"wayland-cursor",
"wayland-protocols 0.32.1",
"wayland-protocols-wlr 0.3.1",
"wayland-scanner",
"xkbcommon",
"xkeysym",
@ -5317,11 +5346,11 @@ dependencies = [
[[package]]
name = "smithay-clipboard"
version = "0.8.0"
source = "git+https://github.com/pop-os/smithay-clipboard?tag=pop-dnd-4#ab422ddcc95a9a1717df094f9c8fe69e2fdb2a27"
source = "git+https://github.com/pop-os/smithay-clipboard?tag=pop-dnd-5#d099e82a4c1e7d3e88dc34b7333de21928b1b22c"
dependencies = [
"libc",
"raw-window-handle",
"smithay-client-toolkit",
"smithay-client-toolkit 0.19.1",
"wayland-backend",
]
@ -6304,6 +6333,19 @@ dependencies = [
"wayland-server",
]
[[package]]
name = "wayland-protocols"
version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83d0f1056570486e26a3773ec633885124d79ae03827de05ba6c85f79904026c"
dependencies = [
"bitflags 2.5.0",
"wayland-backend",
"wayland-client",
"wayland-scanner",
"wayland-server",
]
[[package]]
name = "wayland-protocols-wlr"
version = "0.2.0"
@ -6313,7 +6355,21 @@ dependencies = [
"bitflags 2.5.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols 0.31.2",
"wayland-scanner",
"wayland-server",
]
[[package]]
name = "wayland-protocols-wlr"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7dab47671043d9f5397035975fe1cac639e5bca5cc0b3c32d09f01612e34d24"
dependencies = [
"bitflags 2.5.0",
"wayland-backend",
"wayland-client",
"wayland-protocols 0.32.1",
"wayland-scanner",
"wayland-server",
]
@ -6523,7 +6579,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "window_clipboard"
version = "0.4.1"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-6#8a816d8f218e290041bb5ef6d3b695c38e0a53b7"
source = "git+https://github.com/pop-os/window_clipboard.git?tag=pop-dnd-7#a5be70405574e98c292537fd3b01a1352550b9bf"
dependencies = [
"clipboard-win",
"clipboard_macos",
@ -6775,7 +6831,7 @@ version = "0.1.0"
source = "git+https://github.com/pop-os/xdg-shell-wrapper#b5480042615ecfcf30262d5a40625e8f430b474a"
dependencies = [
"serde",
"wayland-protocols-wlr",
"wayland-protocols-wlr 0.2.0",
]
[[package]]

View file

@ -22,10 +22,10 @@ resolver = "2"
[workspace.dependencies]
anyhow = "1.0.81"
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "e4e6f8c" }
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "c8d3a1c" }
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = [
"client",
], rev = "e4e6f8c" }
], rev = "c8d3a1c" }
cosmic-time = { git = "https://github.com/pop-os/cosmic-time", default-features = false, features = [
"libcosmic",
"once_cell",
@ -64,8 +64,3 @@ ignored = ["libcosmic"]
# [patch."https://github.com/pop-os/libcosmic"]
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//" }
# libcosmic = { git = "https://github.com/pop-os/libcosmic//" }
[patch."https://github.com/Smithay/client-toolkit"]
sctk = { git = "https://github.com/smithay/client-toolkit//", package = "smithay-client-toolkit", rev = "3bed072" }
[patch."crates-io"]

View file

@ -15,6 +15,15 @@ i18n-embed-fl.workspace = true
i18n-embed.workspace = true
itertools = "0.13.0"
libcosmic.workspace = true
libcosmic.features = [
"applet",
"applet-token",
"clipboard",
"tokio",
"wayland",
"desktop",
"dbus-config",
]
rust-embed.workspace = true
tokio = { version = "1.36.0", features = ["full"] }
tracing-log.workspace = true

View file

@ -17,3 +17,4 @@ enter-password = Enter the password or encryption key
router-wps-button = You can also connect by pressing the "WPS" 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
reset = Reset

View file

@ -1,3 +1,5 @@
use std::collections::HashSet;
use cosmic::app::Command;
use cosmic::applet::token::subscription::{
activation_token_subscription, TokenRequest, TokenUpdate,
@ -5,6 +7,7 @@ use cosmic::applet::token::subscription::{
use cosmic::applet::{menu_button, menu_control_padding, padded_control};
use cosmic::cctk::sctk::reexports::calloop;
use cosmic::iced_widget::Row;
use cosmic::widget::icon::from_name;
use cosmic::{
iced::{
wayland::popup::{destroy_popup, get_popup},
@ -17,7 +20,6 @@ use cosmic::{
window,
},
iced_style::application,
theme::Button,
widget::{button, container, divider, icon, scrollable, text, text_input, Column},
Element, Theme,
};
@ -45,7 +47,7 @@ pub fn run() -> cosmic::iced::Result {
cosmic::applet::run::<CosmicNetworkApplet>(false, ())
}
#[derive(Debug)]
#[derive(Debug, Clone)]
enum NewConnectionState {
EnterPassword {
access_point: AccessPoint,
@ -99,6 +101,7 @@ struct CosmicNetworkApplet {
timeline: Timeline,
toggle_wifi_ctr: u128,
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
failed_known_ssids: HashSet<String>,
}
fn wifi_icon(strength: u8) -> &'static str {
@ -114,8 +117,38 @@ fn wifi_icon(strength: u8) -> &'static str {
}
impl CosmicNetworkApplet {
fn update_nm_state(&mut self, new_state: NetworkManagerState) {
fn update_nm_state(&mut self, mut new_state: NetworkManagerState) {
self.update_togglers(&new_state);
// check for failed conns that can be reset
for new_s in &mut new_state.active_conns {
let state = match new_s {
ActiveConnectionInfo::WiFi { state, .. } => state,
_ => continue,
};
if matches!(state, ActiveConnectionState::Activated) {
self.failed_known_ssids.remove(&new_s.name());
continue;
}
if matches!(
state,
ActiveConnectionState::Activating | ActiveConnectionState::Deactivating
) {
continue;
}
if self.nm_state.active_conns.iter().any(|old_s| {
matches!(
old_s,
ActiveConnectionInfo::WiFi {
state: ActiveConnectionState::Activating,
..
} if new_s.name() == old_s.name()
)
}) {
self.failed_known_ssids.insert(new_s.name());
}
}
self.nm_state = new_state;
self.update_icon_name();
}
@ -189,6 +222,7 @@ pub(crate) enum Message {
Frame(Instant),
Token(TokenUpdate),
OpenSettings,
ResetFailedKnownSsid(String),
// Errored(String),
}
@ -280,26 +314,40 @@ impl cosmic::Application for CosmicNetworkApplet {
self.update_nm_state(state);
}
NetworkManagerEvent::RequestResponse {
state,
mut state,
success,
req,
} => {
if let NetworkManagerRequest::SelectAccessPoint(ssid) = &req {
if self
let conn_match = self
.new_connection
.as_ref()
.map(|c| c.ssid() == ssid)
.unwrap_or_default()
&& success
{
.unwrap_or_default();
if conn_match && success {
if let Some(s) =
state.active_conns.iter_mut().find(|ap| &ap.name() == ssid)
{
match s {
ActiveConnectionInfo::WiFi { state, .. } => {
*state = ActiveConnectionState::Activated;
}
_ => {}
};
}
self.failed_known_ssids.remove(ssid);
self.new_connection = None;
self.show_visible_networks = false;
} else if !matches!(
&self.new_connection,
Some(NewConnectionState::EnterPassword { .. })
)
{
self.failed_known_ssids.insert(ssid.clone());
}
} else if let NetworkManagerRequest::Password(ssid, _) = &req {
if let Some(
NewConnectionState::EnterPassword { access_point, .. }
| NewConnectionState::Waiting(access_point),
) = self.new_connection.take()
if let Some(NewConnectionState::Waiting(access_point)) =
self.new_connection.clone()
{
if !success && ssid == &access_point.ssid {
self.new_connection =
@ -308,11 +356,28 @@ impl cosmic::Application for CosmicNetworkApplet {
self.new_connection = None;
self.show_visible_networks = false;
}
} else if let Some(NewConnectionState::EnterPassword {
access_point, ..
}) = self.new_connection.clone()
{
if success && ssid == &access_point.ssid {
self.new_connection = None;
self.show_visible_networks = false;
}
}
} else if self
.new_connection
.as_ref()
.map(|c| c.ssid()).is_some_and(|ssid| {
state.active_conns.iter().any(|c|
matches!(c, ActiveConnectionInfo::WiFi { name, state: ActiveConnectionState::Activated, .. } if ssid == name)
)
}) {
self.new_connection = None;
self.show_visible_networks = false;
}
if self.nm_state.connectivity != state.connectivity
&& !matches!(req, NetworkManagerRequest::Reload)
if !matches!(req, NetworkManagerRequest::Reload)
&& matches!(state.connectivity, NmConnectivityState::Portal)
{
let mut browser = std::process::Command::new("xdg-open");
@ -439,6 +504,38 @@ impl cosmic::Application for CosmicNetworkApplet {
cosmic::process::spawn(cmd);
}
},
Message::ResetFailedKnownSsid(ssid) => {
let ap = if let Some(pos) = self
.nm_state
.known_access_points
.iter()
.position(|ap| ap.ssid == ssid)
{
self.nm_state.known_access_points.remove(pos)
} else if let Some((pos, ap)) = self
.nm_state
.active_conns
.iter()
.position(|conn| conn.name() == ssid)
.zip(
self.nm_state
.wireless_access_points
.iter()
.find(|ap| ap.ssid == ssid),
)
{
self.nm_state.active_conns.remove(pos);
ap.clone()
} else {
tracing::warn!("Failed to find known access point with ssid: {}", ssid);
return Command::none();
};
if let Some(tx) = self.nm_sender.as_ref() {
let _ = tx.unbounded_send(NetworkManagerRequest::Forget(ssid.clone()));
self.show_visible_networks = true;
return self.update(Message::SelectWirelessAccessPoint(ap));
}
}
}
Command::none()
}
@ -553,6 +650,17 @@ impl cosmic::Application for CosmicNetworkApplet {
),
_ => {}
};
if self.failed_known_ssids.contains(name) {
btn_content.push(
cosmic::widget::button::icon(
from_name("view-refresh-symbolic").size(16),
)
.icon_size(16)
.on_press(Message::ResetFailedKnownSsid(name.clone()))
.into(),
)
}
known_wifi.push(Element::from(
column![menu_button(
Row::with_children(btn_content)
@ -646,6 +754,15 @@ impl cosmic::Application for CosmicNetworkApplet {
btn_content.push(ssid.into());
}
if self.failed_known_ssids.contains(&known.ssid) {
btn_content.push(
cosmic::widget::button::icon(from_name("view-refresh-symbolic").size(16))
.icon_size(16)
.on_press(Message::ResetFailedKnownSsid(known.ssid.clone()))
.into(),
)
}
let mut btn = menu_button(
Row::with_children(btn_content)
.align_items(Alignment::Center)

View file

@ -218,6 +218,33 @@ async fn start_listening(
})
.await;
}
Some(NetworkManagerRequest::Forget(ssid)) => {
let s = NetworkManagerSettings::new(&conn).await.unwrap();
let known_conns = s.list_connections().await.unwrap_or_default();
let mut success = false;
for c in known_conns {
let settings = c.get_settings().await.ok().unwrap_or_default();
let s = Settings::new(settings);
if s.wifi
.clone()
.and_then(|w| w.ssid)
.and_then(|ssid| String::from_utf8(ssid).ok())
.is_some_and(|s| s == ssid)
{
_ = c.delete().await;
success = true;
break;
}
}
let state = NetworkManagerState::new(&conn).await.unwrap_or_default();
_ = output
.send(NetworkManagerEvent::RequestResponse {
req: NetworkManagerRequest::Forget(ssid.clone()),
success,
state,
})
.await;
}
_ => {
return State::Finished;
}
@ -236,6 +263,7 @@ pub enum NetworkManagerRequest {
SelectAccessPoint(String),
Disconnect(String),
Password(String, String),
Forget(String),
Reload,
}
@ -432,6 +460,7 @@ impl NetworkManagerState {
let mut known_conn = None;
for c in known_conns {
let settings = c.get_settings().await.ok().unwrap_or_default();
let s = Settings::new(settings);
if let Some(cur_ssid) = s
.wifi
@ -445,22 +474,12 @@ impl NetworkManagerState {
}
}
}
let active_conn = if let Some(known_conn) = known_conn.as_ref() {
// update settings if needed
let mut settings = known_conn.get_settings().await.ok().unwrap_or_default();
settings.extend(conn_settings.iter().map(|s| {
let map = (
s.0.to_string(),
s.1.iter()
.filter_map(|(k, v)| {
OwnedValue::try_from(v).map(|v| (k.to_string(), v)).ok()
})
.collect::<HashMap<_, _>>(),
);
map
}));
known_conn.update(conn_settings).await?;
if password.is_some() {
known_conn.update(conn_settings).await?;
}
nm.activate_connection(known_conn, &device).await?
} else {
@ -473,11 +492,14 @@ impl NetworkManagerState {
.unwrap()
.interface(dummy.inner().interface().to_owned())
.unwrap()
.path(dummy.inner().path().to_owned())
.unwrap()
.build()
.await
.unwrap();
ActiveConnection::from(active)
};
_ = tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
let mut state =
enums::ActiveConnectionState::from(active_conn.state().await.unwrap_or_default());
return match state {