From 3ee5c0372dbdaa946b15e460a37ac0434c03d666 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 6 Mar 2025 16:31:41 -0500 Subject: [PATCH] cleanup --- examples/application/src/notif.rs | 89 ------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 examples/application/src/notif.rs diff --git a/examples/application/src/notif.rs b/examples/application/src/notif.rs deleted file mode 100644 index 19f80f43..00000000 --- a/examples/application/src/notif.rs +++ /dev/null @@ -1,89 +0,0 @@ -use std::error::Error; -use std::time::Duration; -use std::{collections::HashMap, convert::Infallible}; - -use cosmic::{app::Message, Task}; -use zbus::{export::futures_util::StreamExt, proxy, zvariant::Value, Connection}; - -#[proxy( - default_service = "org.freedesktop.Notifications", - default_path = "/org/freedesktop/Notifications" -)] -trait Notifications { - /// Call the org.freedesktop.Notifications.Notify D-Bus method - fn notify( - &self, - app_name: &str, - replaces_id: u32, - app_icon: &str, - summary: &str, - body: &str, - actions: &[&str], - hints: HashMap<&str, &Value<'_>>, - expire_timeout: i32, - ) -> zbus::Result; - - // We need to define the signal we want to listen for - #[zbus(signal)] - fn action_invoked(&self, id: u32, action_key: String) -> zbus::Result<()>; - - // We need to define the signal we want to listen for - #[zbus(signal)] - fn activation_token(&self, id: u32, activation_token: String) -> zbus::Result<()>; -} - -pub fn notif_task() -> Task> { - Task::future(async { - match notif().await { - Ok(t) => t, - Err(err) => { - tracing::error!("Ooops: {err:?}"); - panic!("oops"); - } - } - }) -} - -pub async fn notif( -) -> Result, Box> { - tokio::time::sleep(Duration::from_secs(2)).await; - let connection = Connection::session().await?; - - let proxy = NotificationsProxy::new(&connection).await?; - let mut actions = proxy.receive_action_invoked().await?; - let mut tokens = proxy.receive_activation_token().await?; - - let _reply = proxy - .notify( - "my-app", - 0, - "dialog-information", - "A summary", - "Some body", - &["default", "asdf"], - HashMap::new(), - 5000, - ) - .await?; - - let token = if let Some(msg) = tokens.next().await { - // struct `JobNewArgs` is generated from `job_new` signal function arguments - let args: ActivationTokenArgs = msg.args().expect("Error parsing message"); - - println!("action: id={} action={}", args.id, args.activation_token,); - args.activation_token - } else { - eprintln!("no token"); - panic!("oops"); - }; - if let Some(msg) = actions.next().await { - // struct `JobNewArgs` is generated from `job_new` signal function arguments - let args: ActionInvokedArgs = msg.args().expect("Error parsing message"); - - println!("action: id={} action={}", args.id, args.action_key,); - } - - Ok(Message::Cosmic(cosmic::app::cosmic::Message::Activate( - token, - ))) -}