| 1 | mod common; |
| 2 | |
| 3 | fn main() { |
| 4 | if !common::setup(file!()) { |
| 5 | return; |
| 6 | } |
| 7 | |
| 8 | use notify_rust::{CloseReason, Notification, NotificationResponse, Timeout}; |
| 9 | |
| 10 | Notification::new() |
| 11 | .summary("How was your day?") |
| 12 | .body("Click a button or just dismiss me.") |
| 13 | .action("good", "good") |
| 14 | .action("bad", "bad") |
| 15 | .timeout(Timeout::Never) |
| 16 | .show() |
| 17 | .unwrap() |
| 18 | // typed, forward-compatible replacement for `wait_for_action` |
| 19 | .wait_for_response(|response: &NotificationResponse| match response { |
| 20 | NotificationResponse::Default => log::info!("body clicked"), |
| 21 | NotificationResponse::Action(key) => log::info!("button {key:?} clicked"), |
| 22 | // inline replies only come from the macOS `preview-macos-un` backend |
| 23 | NotificationResponse::Reply(text) => log::info!("user replied: {text}"), |
| 24 | // no more hardcoded `"__closed"`, the close reason is typed |
| 25 | NotificationResponse::Closed(CloseReason::Dismissed) => { |
| 26 | log::info!("dismissed by the user") |
| 27 | } |
| 28 | NotificationResponse::Closed(reason) => log::info!("closed: {reason:?}"), |
| 29 | }) |
| 30 | .unwrap(); |
| 31 | } |