diff --git a/razer_control_gui/src/daemon/daemon.rs b/razer_control_gui/src/daemon/daemon.rs index 4cc548d..1013c26 100644 --- a/razer_control_gui/src/daemon/daemon.rs +++ b/razer_control_gui/src/daemon/daemon.rs @@ -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() { @@ -204,12 +204,31 @@ 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); } @@ -217,22 +236,16 @@ fn start_battery_monitor_task() -> JoinHandle<()> { 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 { @@ -243,7 +256,7 @@ fn start_battery_monitor_task() -> JoinHandle<()> { } true }); - // use login1::OrgFreedesktopLogin1ManagerPrepareForSleep; + loop { dbus_system.process(time::Duration::from_millis(1000)).unwrap(); } }) }