devises a strategy for signals
This commit is contained in:
@@ -2,6 +2,7 @@ use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
use dbus::blocking::{Connection, Proxy};
|
||||
use crate::printers::{ConversationPrinter, MessagePrinter};
|
||||
use std::future;
|
||||
|
||||
const DBUS_NAME: &str = "net.buzzert.kordophonecd";
|
||||
const DBUS_PATH: &str = "/net/buzzert/kordophonecd/daemon";
|
||||
@@ -30,6 +31,9 @@ pub enum Commands {
|
||||
#[command(subcommand)]
|
||||
command: ConfigCommands,
|
||||
},
|
||||
|
||||
/// Waits for signals from the daemon.
|
||||
Signals,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -61,6 +65,7 @@ impl Commands {
|
||||
Commands::Conversations => client.print_conversations().await,
|
||||
Commands::Sync => client.sync_conversations().await,
|
||||
Commands::Config { command } => client.config(command).await,
|
||||
Commands::Signals => client.wait_for_signals().await,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +107,25 @@ impl DaemonCli {
|
||||
.map_err(|e| anyhow::anyhow!("Failed to sync conversations: {}", e))
|
||||
}
|
||||
|
||||
pub async fn wait_for_signals(&mut self) -> Result<()> {
|
||||
use dbus::Message;
|
||||
mod dbus_signals {
|
||||
pub use super::dbus_interface::NetBuzzertKordophoneRepositoryConversationsUpdated as ConversationsUpdated;
|
||||
}
|
||||
|
||||
let _id = self.proxy().match_signal(|h: dbus_signals::ConversationsUpdated, _: &Connection, _: &Message| {
|
||||
println!("Signal: Conversations updated");
|
||||
true
|
||||
});
|
||||
|
||||
println!("Waiting for signals...");
|
||||
loop {
|
||||
self.conn.process(std::time::Duration::from_millis(1000))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn config(&mut self, cmd: ConfigCommands) -> Result<()> {
|
||||
match cmd {
|
||||
ConfigCommands::Print => self.print_settings().await,
|
||||
|
||||
Reference in New Issue
Block a user