Skip to content

Commit

Permalink
Merge pull request #77 from MalpenZibo/76_no-battery-display
Browse files Browse the repository at this point in the history
76 - Fix no battery indicator displayed
  • Loading branch information
MalpenZibo authored Dec 13, 2024
2 parents 1a82805 + c788c14 commit 7d922dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/services/upower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
}
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/utils/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

0 comments on commit 7d922dc

Please sign in to comment.