battery: Exit on NoBattery instead of letting subscription handle it

This commit is contained in:
Ian Douglas Scott 2024-07-01 18:20:26 -07:00 committed by Ian Douglas Scott
parent 0ef2393288
commit 61a9102fce
2 changed files with 20 additions and 29 deletions

10
Cargo.lock generated
View file

@ -1324,7 +1324,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-settings-subscriptions" name = "cosmic-settings-subscriptions"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#21cc79434fa24f1fbd6dc4e8d394aa51d5ee12d9" source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#c19240ad2c9f11ef5cec8ed8c70255c3dc9ae8d4"
dependencies = [ dependencies = [
"futures", "futures",
"iced_futures", "iced_futures",
@ -1511,7 +1511,7 @@ version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=20fda69#20fda698341efbdc870b8027d6d49f5bf3f36109" source = "git+https://github.com/gfx-rs/wgpu?rev=20fda69#20fda698341efbdc870b8027d6d49f5bf3f36109"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"libloading 0.8.3", "libloading 0.7.4",
"winapi", "winapi",
] ]
@ -1774,7 +1774,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412"
dependencies = [ dependencies = [
"libloading 0.8.3", "libloading 0.7.4",
] ]
[[package]] [[package]]
@ -2608,7 +2608,7 @@ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"com", "com",
"libc", "libc",
"libloading 0.8.3", "libloading 0.7.4",
"thiserror", "thiserror",
"widestring", "widestring",
"winapi", "winapi",
@ -6537,7 +6537,7 @@ dependencies = [
"js-sys", "js-sys",
"khronos-egl", "khronos-egl",
"libc", "libc",
"libloading 0.8.3", "libloading 0.7.4",
"log", "log",
"metal", "metal",
"naga", "naga",

View file

@ -156,15 +156,11 @@ impl CosmicBatteryApplet {
enum Message { enum Message {
TogglePopup, TogglePopup,
CloseRequested(window::Id), CloseRequested(window::Id),
Update {
on_battery: bool,
percent: f64,
time_to_empty: i64,
},
SetKbdBrightness(i32), SetKbdBrightness(i32),
SetScreenBrightness(i32), SetScreenBrightness(i32),
SetChargingLimit(chain::Toggler, bool), SetChargingLimit(chain::Toggler, bool),
KeyboardBacklight(KeyboardBacklightUpdate), KeyboardBacklight(KeyboardBacklightUpdate),
UpowerDevice(DeviceDbusEvent),
GpuOn(PathBuf, String, Option<Vec<Entry>>), GpuOn(PathBuf, String, Option<Vec<Entry>>),
GpuOff(PathBuf), GpuOff(PathBuf),
ToggleGpuApps(PathBuf), ToggleGpuApps(PathBuf),
@ -273,14 +269,19 @@ impl cosmic::Application for CosmicBatteryApplet {
return get_popup(popup_settings); return get_popup(popup_settings);
} }
} }
Message::Update { Message::UpowerDevice(event) => match event {
on_battery, DeviceDbusEvent::Update {
percent, on_battery,
time_to_empty, percent,
} => { time_to_empty,
self.update_battery(percent, on_battery); } => {
self.time_remaining = Duration::from_secs(time_to_empty as u64); self.update_battery(percent, on_battery);
} self.time_remaining = Duration::from_secs(time_to_empty as u64);
}
DeviceDbusEvent::NoBattery => {
std::process::exit(0);
}
},
Message::KeyboardBacklight(event) => match event { Message::KeyboardBacklight(event) => match event {
KeyboardBacklightUpdate::Sender(tx) => { KeyboardBacklightUpdate::Sender(tx) => {
self.kbd_sender = Some(tx); self.kbd_sender = Some(tx);
@ -682,17 +683,7 @@ impl cosmic::Application for CosmicBatteryApplet {
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {
let mut subscriptions = vec![ let mut subscriptions = vec![
device_subscription(0).map( device_subscription(0).map(Message::UpowerDevice),
|DeviceDbusEvent::Update {
on_battery,
percent,
time_to_empty,
}| Message::Update {
on_battery,
percent,
time_to_empty,
},
),
kbd_backlight_subscription(0).map(Message::KeyboardBacklight), kbd_backlight_subscription(0).map(Message::KeyboardBacklight),
power_profile_subscription(0).map(|event| match event { power_profile_subscription(0).map(|event| match event {
PowerProfileUpdate::Update { profile } => Message::Profile(profile), PowerProfileUpdate::Update { profile } => Message::Profile(profile),