stynx_code_services/notifications/
mod.rs1use async_trait::async_trait;
2use stynx_code_errors::AppResult;
3
4#[async_trait]
5pub trait NotificationService: Send + Sync {
6 async fn notify(&self, title: &str, body: &str) -> AppResult<()>;
7 async fn bell(&self) -> AppResult<()>;
8}
9
10pub struct TerminalNotifier;
11
12impl TerminalNotifier {
13 pub fn new() -> Self {
14 Self
15 }
16}
17
18#[async_trait]
19impl NotificationService for TerminalNotifier {
20 async fn notify(&self, title: &str, body: &str) -> AppResult<()> {
21
22 if std::env::var("TERM_PROGRAM")
23 .map(|v| v.contains("iTerm"))
24 .unwrap_or(false)
25 {
26 eprint!("\x1b]9;{title}: {body}\x07");
27 } else {
28 eprintln!("[{title}] {body}");
29 }
30 tracing::info!(title, body, "sent notification");
31 Ok(())
32 }
33
34 async fn bell(&self) -> AppResult<()> {
35 eprint!("\x07");
36 Ok(())
37 }
38}