Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/components/quick_setting_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn quick_setting_button<'a, Msg: Clone + 'static>(
on_press: Msg,
on_right_press: Option<Msg>,
with_submenu: Option<(SubMenu, Option<SubMenu>, Msg)>,
header_end: Option<String>,
) -> Element<'a, Msg> {
let target: f32 = if active { 1.0 } else { 0.0 };
let icon_kind: IconKind = icon.into();
Expand All @@ -32,19 +33,27 @@ pub fn quick_setting_button<'a, Msg: Clone + 'static>(
subtitle: Option<String>,
icon_kind: IconKind,
on_press: Msg,
with_submenu: Option<(SubMenu, Option<SubMenu>, Msg)>|
with_submenu: Option<(SubMenu, Option<SubMenu>, Msg)>,
header_end: Option<String>|
-> Element<'a, Msg> {
let (submenu_btn_style, settings_btn_style) = use_theme(|theme| {
(
theme.quick_settings_submenu_button_style(t),
theme.quick_settings_button_style(t),
)
});
let title_el: Element<'a, Msg> = match header_end {
Some(end) => row!(text(title).size(font_size.sm), text(end).size(font_size.xs),)
.spacing(space.xxs)
.align_y(Alignment::Center)
.into(),
None => text(title).size(font_size.sm).into(),
};
let main_content = row!(
icon_kind.to_text().size(font_size.lg),
container(
Column::with_capacity(2)
.push(text(title).size(font_size.sm))
.push(title_el)
.push(
subtitle
.map(|s| { text(s).wrapping(text::Wrapping::None).size(font_size.xs) })
Expand Down Expand Up @@ -92,12 +101,21 @@ pub fn quick_setting_button<'a, Msg: Clone + 'static>(
icon_kind.clone(),
on_press.clone(),
with_submenu.clone(),
header_end.clone(),
)
})
.animation(Easing::EASE.quick())
.into()
} else {
build_btn(target, title, subtitle, icon_kind, on_press, with_submenu)
build_btn(
target,
title,
subtitle,
icon_kind,
on_press,
with_submenu,
header_end,
)
};

if let Some(on_right_press) = on_right_press {
Expand Down
1 change: 1 addition & 0 deletions src/modules/settings/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ impl BluetoothSettings {
sub_menu,
Message::ToggleSubMenu,
)),
None,
),
self.bluetooth_menu(id)
.map(|menu| (sub_menu == Some(SubMenu::Bluetooth), menu)),
Expand Down
18 changes: 15 additions & 3 deletions src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ impl Settings {
Message::ToggleInhibitIdle,
None,
None,
None,
),
None,
)
Expand Down Expand Up @@ -680,6 +681,7 @@ impl Settings {
Message::CustomButton(button.name.clone()),
None,
None,
None,
),
None,
)
Expand Down Expand Up @@ -930,9 +932,19 @@ impl Settings {
}
MenuType::WifiTooltip => {
if let Some(label) = self.network.connected_wifi_label() {
row![StaticIcon::Wifi4.to_text(), iced::widget::text(label)]
.spacing(space.xs)
.into()
let band = self.network.connected_wifi_band();
let font_size = use_theme(|t| t.font_size);
let primary = use_theme(|t| t.iced_theme.palette().primary);
let mut r = row![StaticIcon::Wifi4.to_text(), iced::widget::text(label)]
.spacing(space.xs);
if let Some(b) = band {
r = r.push(iced::widget::text(b).size(font_size.xs).style(
move |_theme: &Theme| iced::widget::text::Style {
color: Some(primary),
},
));
}
r.into()
} else {
fallback(t!("settings-tooltip-empty-wifi"))
}
Expand Down
42 changes: 32 additions & 10 deletions src/modules/settings/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
ReadOnlyService, Service, ServiceEvent,
network::{
AccessPointData, ActiveConnectionInfo, KnownConnection, NetworkCommand, NetworkEvent,
NetworkService, Vpn, dbus::ConnectivityState,
NetworkService, Vpn, dbus::ConnectivityState, frequency_band,
},
},
t,
Expand Down Expand Up @@ -384,17 +384,19 @@ impl NetworkSettings {
self.service.as_ref().and_then(|service| {
if service.wifi_present {
let active_connection = service.active_connections.iter().find_map(|c| match c {
ActiveConnectionInfo::WiFi { name, strength, .. } => {
Some((name, strength, c.get_icon()))
}
ActiveConnectionInfo::WiFi {
name,
strength,
band,
} => Some((name, strength, *band, c.get_icon())),
_ => None,
});

Some((
quick_setting_button(
active_connection.map_or_else(|| StaticIcon::Wifi0, |(_, _, icon)| icon),
active_connection.map_or_else(|| StaticIcon::Wifi0, |(_, _, _, icon)| icon),
t!("settings-network-wifi"),
active_connection.map(|(name, _, _)| name.to_string()),
active_connection.map(|(name, _, _, _)| name.to_string()),
service.wifi_enabled,
Message::ToggleWiFi,
Some(Message::OpenMore),
Expand All @@ -403,13 +405,15 @@ impl NetworkSettings {
sub_menu,
Message::ToggleWifiMenu,
)),
active_connection.and_then(|(_, _, band, _)| band.map(|b| b.to_string())),
),
service.wifi_enabled.then_some((
sub_menu == Some(SubMenu::Wifi),
Self::wifi_menu(
service,
id,
active_connection.map(|(name, strength, _)| (name.as_str(), *strength)),
active_connection
.map(|(name, strength, _, _)| (name.as_str(), *strength)),
self.config.wifi_more_cmd.is_some(),
),
)),
Expand Down Expand Up @@ -479,6 +483,7 @@ impl NetworkSettings {
} else {
None
},
None,
),
Some((
sub_menu == Some(SubMenu::Vpn),
Expand Down Expand Up @@ -506,6 +511,7 @@ impl NetworkSettings {
Message::ToggleAirplaneMode,
Some(Message::OpenMore),
None,
None,
),
None,
)
Expand Down Expand Up @@ -566,7 +572,9 @@ impl NetworkSettings {

styled_button(
Element::from(
container(
container({
let primary = use_theme(|t| t.iced_theme.palette().primary);
let font_size = use_theme(|t| t.font_size);
row!(
icon(if ac.public {
ActiveConnectionInfo::get_wifi_icon(ac.strength)
Expand All @@ -575,10 +583,15 @@ impl NetworkSettings {
})
.width(Length::Shrink),
text(ac.ssid.as_str()).width(Length::Fill),
text(frequency_band(ac.frequency).unwrap_or(""))
.size(font_size.xs)
.style(move |_theme: &Theme| text::Style {
color: Some(primary),
}),
)
.align_y(Alignment::Center)
.spacing(8),
)
.spacing(space.xs)
})
.style(move |theme: &Theme| {
container::Style {
text_color: if is_active {
Expand Down Expand Up @@ -715,6 +728,15 @@ impl NetworkSettings {
})
}

pub fn connected_wifi_band(&self) -> Option<&'static str> {
self.service.as_ref().and_then(|service| {
service.active_connections.iter().find_map(|c| match c {
ActiveConnectionInfo::WiFi { band, .. } => *band,
_ => None,
})
})
}

pub fn vpn_tooltip_label(&self) -> Option<String> {
self.service.as_ref().and_then(|service| {
let active_vpns: Vec<_> = service
Expand Down
2 changes: 2 additions & 0 deletions src/modules/settings/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ impl PowerSettings {
Message::TogglePowerProfile,
None,
None,
None,
),
None,
))
Expand All @@ -522,6 +523,7 @@ impl PowerSettings {
Message::ToggleChargeLimit,
None,
None,
None,
),
None,
)
Expand Down
2 changes: 2 additions & 0 deletions src/services/network/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,12 @@ impl NetworkDbus<'_> {
.build()
.await?;

let freq = access_point.frequency().await.unwrap_or_default();
info.push(ActiveConnectionInfo::WiFi {
name: String::from_utf8_lossy(&access_point.ssid().await?)
.into_owned(),
strength: access_point.strength().await.unwrap_or_default(),
band: super::frequency_band(freq),
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/services/network/iwd_dbus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ impl IwdDbus<'_> {
info.push(ActiveConnectionInfo::WiFi {
name: ssid,
strength: map_iwd_rssi_to_percent(signal_strength),
band: None,
});
}
Ok(info)
Expand Down
11 changes: 11 additions & 0 deletions src/services/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ pub enum KnownConnection {
Vpn(Vpn),
}

pub fn frequency_band(frequency_mhz: u32) -> Option<&'static str> {
match frequency_mhz {
2400..=2500 => Some("2.4 GHz"),
4900..=5924 => Some("5 GHz"),
5925..=7125 => Some("6 GHz"),
57000..=71000 => Some("60 GHz"),
_ => None,
}
}

#[derive(Debug, Clone)]
pub enum ActiveConnectionInfo {
Wired {
Expand All @@ -135,6 +145,7 @@ pub enum ActiveConnectionInfo {
WiFi {
name: String,
strength: u8,
band: Option<&'static str>,
},
Vpn {
name: String,
Expand Down