diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 26fe9c0d..c60bf85e 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -4,7 +4,7 @@ use crate::{ backend::{ Power, PowerProfileRequest, PowerProfileUpdate, get_charging_limit, - power_profile_subscription, set_charging_limit, + power_profile_subscription, set_charging_limit, unset_charging_limit, }, config, dgpu::{Entry, GpuUpdate, dgpu_subscription}, @@ -310,6 +310,10 @@ impl cosmic::Application for CosmicBatteryApplet { return cosmic::iced::Task::perform(set_charging_limit(), |_| { cosmic::Action::None }); + } else { + return cosmic::iced::Task::perform(unset_charging_limit(), |_| { + cosmic::Action::None + }); } } Message::Errored(why) => { diff --git a/cosmic-applet-battery/src/backend/mod.rs b/cosmic-applet-battery/src/backend/mod.rs index f21308ab..21c82a7c 100644 --- a/cosmic-applet-battery/src/backend/mod.rs +++ b/cosmic-applet-battery/src/backend/mod.rs @@ -250,3 +250,22 @@ pub async fn set_charging_limit() -> Result<()> { } Ok(()) } + +// unset battery charging thresholds via s76 power_daemon +pub async fn unset_charging_limit() -> Result<()> { + if let Ok(conn) = Connection::system().await { + if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await { + match backend { + Backend::S76PowerDaemon(proxy) => { + let _ = proxy.set_charge_thresholds(&(90, 100)).await; + } + Backend::PowerProfilesDaemon(_) => { + tracing::info!( + "Unsetting charging limit via Power Profiles Daemon is not supported." + ); + } + } + } + } + Ok(()) +}