feat: display WPS hint only when WPS is available

This commit is contained in:
mkljczk 2025-02-10 13:16:33 +01:00 committed by GitHub
parent a046692241
commit 82ca8bab37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 24 deletions

View file

@ -981,30 +981,34 @@ impl cosmic::Application for CosmicNetworkApplet {
.spacing(12), .spacing(12),
); );
content = content.push(id); content = content.push(id);
let col = padded_control( let enter_password_col = column![
column![ text::body(fl!("enter-password")),
text::body(fl!("enter-password")), text_input::secure_input(
text_input::secure_input( "",
"", password,
password, Some(Message::TogglePasswordVisibility),
Some(Message::TogglePasswordVisibility), *password_hidden,
*password_hidden, )
) .on_input(Message::Password)
.on_input(Message::Password) .on_paste(Message::Password)
.on_paste(Message::Password) .on_submit(Message::SubmitPassword)
.on_submit(Message::SubmitPassword), .password(),
container(text::body(fl!("router-wps-button"))).padding(8), ]
row![ .push_maybe(
button::standard(fl!("cancel")) access_point
.on_press(Message::CancelNewConnection), .wps_push
button::suggested(fl!("connect")).on_press(Message::SubmitPassword) .then(|| container(text::body(fl!("router-wps-button"))).padding(8)),
]
.spacing(24)
]
.spacing(8)
.align_x(Alignment::Center),
) )
.align_x(Alignment::Center); .push(
row![
button::standard(fl!("cancel")).on_press(Message::CancelNewConnection),
button::suggested(fl!("connect")).on_press(Message::SubmitPassword)
]
.spacing(24),
);
let col =
padded_control(enter_password_col.spacing(8).align_x(Alignment::Center))
.align_x(Alignment::Center);
content = content.push(col); content = content.push(col);
} }
NewConnectionState::Waiting(access_point) => { NewConnectionState::Waiting(access_point) => {

View file

@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use cosmic_dbus_networkmanager::{device::wireless::WirelessDevice, interface::enums::DeviceState}; use cosmic_dbus_networkmanager::{
device::wireless::WirelessDevice,
interface::enums::{ApFlags, DeviceState},
};
use futures_util::StreamExt; use futures_util::StreamExt;
use itertools::Itertools; use itertools::Itertools;
@ -33,6 +36,7 @@ pub async fn handle_wireless_device(
let mut aps = HashMap::<String, AccessPoint>::new(); let mut aps = HashMap::<String, AccessPoint>::new();
for ap in access_points { for ap in access_points {
let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned(); let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned();
let wps_push = ap.flags().await?.contains(ApFlags::WPS_PBC);
let strength = ap.strength().await?; let strength = ap.strength().await?;
if let Some(access_point) = aps.get(&ssid) { if let Some(access_point) = aps.get(&ssid) {
if access_point.strength > strength { if access_point.strength > strength {
@ -51,6 +55,7 @@ pub async fn handle_wireless_device(
.as_ref() .as_ref()
.and_then(|str_addr| HwAddress::from_str(str_addr)) .and_then(|str_addr| HwAddress::from_str(str_addr))
.unwrap_or_default(), .unwrap_or_default(),
wps_push,
}, },
); );
} }
@ -69,4 +74,5 @@ pub struct AccessPoint {
pub working: bool, pub working: bool,
pub path: ObjectPath<'static>, pub path: ObjectPath<'static>,
pub hw_address: HwAddress, pub hw_address: HwAddress,
pub wps_push: bool,
} }