Skip to content

Commit

Permalink
Minor refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JosuGZ committed Oct 31, 2024
1 parent 471254c commit e1a64a0
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions razer_control_gui/src/daemon/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() {
let proxy_ac = dbus_system.with_proxy("org.freedesktop.UPower", "/org/freedesktop/UPower/devices/line_power_AC0", time::Duration::from_millis(5000));
use battery::OrgFreedesktopUPowerDevice;
if let Ok(online) = proxy_ac.online() {
println!("Online AC0: {:?}", online);
info!("AC0 online: {:?}", online);
d.set_ac_state(online);
d.restore_standard_effect();
if let Ok(json) = config::Configuration::read_effects_file() {
Expand Down Expand Up @@ -204,35 +204,48 @@ fn start_screensaver_monitor_task() -> JoinHandle<()> {
fn start_battery_monitor_task() -> JoinHandle<()> {
thread::spawn(move || {
let dbus_system = Connection::new_system()
.expect("failed to connect to D-Bus system bus");
let proxy_ac = dbus_system.with_proxy("org.freedesktop.UPower", "/org/freedesktop/UPower/devices/line_power_AC0", time::Duration::from_millis(5000));
.expect("should be able to connect to D-Bus system bus");
info!("Connected to the system D-Bus");

let proxy_ac = dbus_system.with_proxy(
"org.freedesktop.UPower",
"/org/freedesktop/UPower/devices/line_power_AC0",
time::Duration::from_millis(5000)
);

let proxy_battery = dbus_system.with_proxy(
"org.freedesktop.UPower",
"/org/freedesktop/UPower/devices/battery_BAT0",
time::Duration::from_millis(5000)
);

let proxy_login = dbus_system.with_proxy(
"org.freedesktop.login1",
"/org/freedesktop/login1",
time::Duration::from_millis(5000)
);

let _id = proxy_ac.match_signal(|h: battery::OrgFreedesktopDBusPropertiesPropertiesChanged, _: &Connection, _: &Message| {
let online: Option<&bool> = arg::prop_cast(&h.changed_properties, "Online");
if let Some(online) = online {
println!("Online AC0: {:?}", online);
info!("AC0 online: {:?}", online);
if let Ok(mut d) = DEV_MANAGER.lock() {
d.set_ac_state(*online);
}
}
true
});

let proxy_battery = dbus_system.with_proxy("org.freedesktop.UPower", "/org/freedesktop/UPower/devices/battery_BAT0", time::Duration::from_millis(5000));
// use battery::OrgFreedesktopUPowerDevice;
// if let Ok(perc) = proxy_battery.percentage() {
// println!("battery percentage: {:.1}", perc);
// }
let _id = proxy_battery.match_signal(|h: battery::OrgFreedesktopDBusPropertiesPropertiesChanged, _: &Connection, _: &Message| {
let perc: Option<&f64> = arg::prop_cast(&h.changed_properties, "Percentage");
if let Some(perc) = perc {
println!("battery percentage: {:.1}", perc);
info!("Battery percentage: {:.1}", perc);
}
true
});

let proxy_login = dbus_system.with_proxy("org.freedesktop.login1", "/org/freedesktop/login1", time::Duration::from_millis(5000));
let _id = proxy_login.match_signal(|h: login1::OrgFreedesktopLogin1ManagerPrepareForSleep, _: &Connection, _: &Message| {
println!("PrepareForSleep {:?}", h.start);
info!("PrepareForSleep {:?}", h.start);
if let Ok(mut d) = DEV_MANAGER.lock() {
d.set_ac_state_get();
if h.start {
Expand All @@ -243,7 +256,7 @@ fn start_battery_monitor_task() -> JoinHandle<()> {
}
true
});
// use login1::OrgFreedesktopLogin1ManagerPrepareForSleep;

loop { dbus_system.process(time::Duration::from_millis(1000)).unwrap(); }
})
}
Expand Down

0 comments on commit e1a64a0

Please sign in to comment.