mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Check inotify paths are valid. Add dgu/egpu/ac_online checks
This commit is contained in:
@@ -7,6 +7,7 @@ use rog_platform::supported::ChargeSupportedFunctions;
|
||||
use std::sync::Arc;
|
||||
use zbus::dbus_interface;
|
||||
use zbus::export::futures_util::lock::Mutex;
|
||||
use zbus::export::futures_util::StreamExt;
|
||||
use zbus::Connection;
|
||||
use zbus::SignalContext;
|
||||
|
||||
@@ -74,11 +75,23 @@ impl CtrlPower {
|
||||
}
|
||||
}
|
||||
|
||||
fn mains_online(&self) -> bool {
|
||||
if self.power.has_online() {
|
||||
if let Ok(v) = self.power.get_online() {
|
||||
return v == 1;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_charge_control_end_threshold(
|
||||
ctxt: &SignalContext<'_>,
|
||||
limit: u8,
|
||||
) -> zbus::Result<()>;
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_mains_online(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -167,7 +180,29 @@ impl CtrlTask for CtrlPower {
|
||||
)
|
||||
.await;
|
||||
|
||||
self.watch_charge_control_end_threshold(signal_ctxt).await?;
|
||||
self.watch_charge_control_end_threshold(signal_ctxt.clone())
|
||||
.await?;
|
||||
|
||||
let ctrl = self.clone();
|
||||
match ctrl.power.monitor_online() {
|
||||
Ok(mut watch) => {
|
||||
tokio::spawn(async move {
|
||||
let mut buffer = [0; 32];
|
||||
watch
|
||||
.event_stream(&mut buffer)
|
||||
.unwrap()
|
||||
.for_each(|_| async {
|
||||
if let Ok(value) = ctrl.power.get_online() {
|
||||
Self::notify_mains_online(&signal_ctxt, value == 1)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
.await;
|
||||
});
|
||||
}
|
||||
Err(e) => info!("inotify watch failed: {}", e),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user