From 045df65fc46cb4082757be77bf0a385d1e2e7ea4 Mon Sep 17 00:00:00 2001 From: Simone Camito Date: Wed, 11 Dec 2024 11:54:33 +0100 Subject: [PATCH 1/3] initialize service even if the powerprofile dbus is not present --- src/services/upower/mod.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/services/upower/mod.rs b/src/services/upower/mod.rs index 9ff2fcf..10e8bcc 100644 --- a/src/services/upower/mod.rs +++ b/src/services/upower/mod.rs @@ -10,7 +10,7 @@ use iced::{ subscription::channel, Subscription, }; -use log::error; +use log::{error, warn}; use std::{any::TypeId, time::Duration}; use zbus::zvariant::ObjectPath; @@ -158,11 +158,21 @@ impl UPowerService { conn: &zbus::Connection, ) -> anyhow::Result<(Option<(BatteryData, ObjectPath<'static>)>, PowerProfile)> { let battery = UPowerService::initialize_battery_data(conn).await?; - let power_profile = UPowerService::initialize_power_profile_data(conn).await?; + let power_profile = UPowerService::initialize_power_profile_data(conn).await; match (battery, power_profile) { - (Some(battery), power_profile) => Ok((Some((battery.0, battery.1)), power_profile)), - _ => Ok((None, power_profile)), + (Some(battery), Ok(power_profile)) => Ok((Some((battery.0, battery.1)), power_profile)), + (Some(battery), Err(err)) => { + warn!("Failed to get power profile: {}", err); + + Ok((Some((battery.0, battery.1)), PowerProfile::Unknown)) + } + (None, Ok(power_profile)) => Ok((None, power_profile)), + (None, Err(err)) => { + warn!("Failed to get power profile: {}", err); + + Ok((None, PowerProfile::Unknown)) + } } } From 1a5b5b32333372aacba51b067a6f52b243c3d086 Mon Sep 17 00:00:00 2001 From: Simone Camito Date: Wed, 11 Dec 2024 12:01:42 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b973b4..7fdfd4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix upower service startup fail in case of missing `org.freedesktop.UPower.PowerProfiles` dbus interface + ## [0.3.0] - 2024-11-26 A small release with some new Hyprland related modules From c788c14b5b347bb00c463e43176975b42ddfcd98 Mon Sep 17 00:00:00 2001 From: Simone Camito Date: Fri, 13 Dec 2024 08:49:26 +0100 Subject: [PATCH 3/3] fix clippy --- src/utils/launcher.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/utils/launcher.rs b/src/utils/launcher.rs index 070bca1..885d2dd 100644 --- a/src/utils/launcher.rs +++ b/src/utils/launcher.rs @@ -2,50 +2,55 @@ use std::process::Command; pub fn execute_command(command: String) { tokio::spawn(async move { - Command::new("bash") + let _ = Command::new("bash") .arg("-c") .arg(&command) .spawn() - .unwrap_or_else(|_| panic!("Failed to execute command {}", &command)); + .unwrap_or_else(|_| panic!("Failed to execute command {}", &command)) + .wait(); }); } pub fn suspend() { tokio::spawn(async move { - Command::new("bash") + let _ = Command::new("bash") .arg("-c") .arg("systemctl suspend") .spawn() - .expect("Failed to execute command."); + .expect("Failed to execute command.") + .wait(); }); } pub fn shutdown() { tokio::spawn(async move { - Command::new("bash") + let _ = Command::new("bash") .arg("-c") .arg("shutdown now") .spawn() - .expect("Failed to execute command."); + .expect("Failed to execute command.") + .wait(); }); } pub fn reboot() { tokio::spawn(async move { - Command::new("bash") + let _ = Command::new("bash") .arg("-c") .arg("systemctl reboot") .spawn() - .expect("Failed to execute command."); + .expect("Failed to execute command.") + .wait(); }); } pub fn logout() { tokio::spawn(async move { - Command::new("bash") + let _ = Command::new("bash") .arg("-c") .arg("loginctl kill-user $(whoami)") .spawn() - .expect("Failed to execute command."); + .expect("Failed to execute command.") + .wait(); }); }