feat(ipc): connect GUI to daemon via D-Bus reload and live status detection
This commit is contained in:
@@ -74,6 +74,16 @@ impl Watcher {
|
||||
// thread exits when the connection drops.
|
||||
let _ = self.sink.send(event);
|
||||
}
|
||||
|
||||
/// Instruct the daemon to reload schedules from the database immediately.
|
||||
fn reload_schedules(&self) {
|
||||
let _ = self.sink.send(FocusEvent::ReloadSchedules);
|
||||
}
|
||||
|
||||
/// Ping method to check if the daemon is alive.
|
||||
fn ping(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Acquire the bus name and export [`Watcher`], returning the live connection.
|
||||
@@ -115,3 +125,25 @@ pub fn serve(sink: Sender<FocusEvent>) -> Result<Connection, WatcherError> {
|
||||
pub fn release(connection: &Connection) {
|
||||
let _ = connection.release_name(BUS_NAME);
|
||||
}
|
||||
|
||||
/// Tell the running daemon via D-Bus to reload schedules from storage.
|
||||
pub fn notify_daemon_reload() -> Result<(), zbus::Error> {
|
||||
let conn = Connection::session()?;
|
||||
let proxy =
|
||||
zbus::blocking::Proxy::new(&conn, BUS_NAME, OBJECT_PATH, "vu.valiq.blocker.Watcher")?;
|
||||
let _: () = proxy.call("ReloadSchedules", &())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Query if the daemon is running and responding on D-Bus.
|
||||
pub fn is_daemon_running() -> bool {
|
||||
if let Ok(conn) = Connection::session() {
|
||||
if let Ok(proxy) =
|
||||
zbus::blocking::Proxy::new(&conn, BUS_NAME, OBJECT_PATH, "vu.valiq.blocker.Watcher")
|
||||
{
|
||||
let res: zbus::Result<bool> = proxy.call("Ping", &());
|
||||
return res.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user