xpc: implement signals
This commit is contained in:
@@ -347,7 +347,66 @@ impl DaemonInterface for XpcDaemonInterface {
|
||||
Ok(())
|
||||
}
|
||||
async fn wait_for_signals(&mut self) -> Result<()> {
|
||||
Err(anyhow::anyhow!("Feature not implemented for XPC"))
|
||||
let mach_port_name = Self::build_service_name()?;
|
||||
let mut client = XPCClient::connect(&mach_port_name);
|
||||
|
||||
// Send a subscription/warm-up message so the server loop starts selecting for this client
|
||||
client.send_message(Message::Dictionary(Self::build_request("SubscribeSignals", None)));
|
||||
|
||||
println!("Waiting for XPC signals...");
|
||||
while let Some(msg) = client.next().await {
|
||||
match msg {
|
||||
Message::Dictionary(map) => {
|
||||
let name_key = Self::key("name");
|
||||
let args_key = Self::key("arguments");
|
||||
let name = match map.get(&name_key) { Some(Message::String(s)) => s.to_string_lossy().into_owned(), _ => continue };
|
||||
|
||||
match name.as_str() {
|
||||
"ConversationsUpdated" => {
|
||||
println!("Signal: Conversations updated");
|
||||
}
|
||||
"MessagesUpdated" => {
|
||||
if let Some(Message::Dictionary(args)) = map.get(&args_key) {
|
||||
if let Some(Message::String(cid)) = args.get(&Self::key("conversation_id")) {
|
||||
println!("Signal: Messages updated for conversation {}", cid.to_string_lossy());
|
||||
}
|
||||
}
|
||||
}
|
||||
"UpdateStreamReconnected" => {
|
||||
println!("Signal: Update stream reconnected");
|
||||
}
|
||||
"AttachmentDownloadCompleted" => {
|
||||
if let Some(Message::Dictionary(args)) = map.get(&args_key) {
|
||||
if let Some(Message::String(aid)) = args.get(&Self::key("attachment_id")) {
|
||||
println!("Signal: Attachment downloaded: {}", aid.to_string_lossy());
|
||||
}
|
||||
}
|
||||
}
|
||||
"AttachmentDownloadFailed" => {
|
||||
if let Some(Message::Dictionary(args)) = map.get(&args_key) {
|
||||
if let Some(Message::String(aid)) = args.get(&Self::key("attachment_id")) {
|
||||
eprintln!("Signal: Attachment download failed: {}", aid.to_string_lossy());
|
||||
}
|
||||
}
|
||||
}
|
||||
"AttachmentUploadCompleted" => {
|
||||
if let Some(Message::Dictionary(args)) = map.get(&args_key) {
|
||||
let upload = args.get(&Self::key("upload_guid")).and_then(|v| match v { Message::String(s) => Some(s.to_string_lossy().into_owned()), _ => None }).unwrap_or_default();
|
||||
let attachment = args.get(&Self::key("attachment_guid")).and_then(|v| match v { Message::String(s) => Some(s.to_string_lossy().into_owned()), _ => None }).unwrap_or_default();
|
||||
println!("Signal: Attachment uploaded: upload={}, attachment={}", upload, attachment);
|
||||
}
|
||||
}
|
||||
"ConfigChanged" => {
|
||||
println!("Signal: Config changed");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Message::Error(xpc_connection::MessageError::ConnectionInvalid) => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
async fn config(&mut self, _cmd: ConfigCommands) -> Result<()> {
|
||||
let mach_port_name = Self::build_service_name()?;
|
||||
|
||||
Reference in New Issue
Block a user