| 1 | //! Demonstrates setting an interruption level on a macOS notification. |
| 2 | //! |
| 3 | //! Interruption levels control whether a notification breaks through |
| 4 | //! Focus modes. Requires macOS 12+. |
| 5 | //! |
| 6 | //! Run with: |
| 7 | //! ```text |
| 8 | //! cargo run --example interruption_level --features preview-macos-un |
| 9 | //! ``` |
| 10 | |
| 11 | #![allow(unused_imports)] |
| 12 | mod common; |
| 13 | |
| 14 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 15 | cfg_if::cfg_if! { |
| 16 | if #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] { |
| 17 | if !common::setup(file!()) { |
| 18 | return Ok(()); |
| 19 | } |
| 20 | notify_rust::check_bundle()?; |
| 21 | |
| 22 | notify_rust::Notification::new() |
| 23 | .summary("Time Sensitive") |
| 24 | .body("This notification bypasses Focus settings.") |
| 25 | .urgency(notify_rust::InterruptionLevel::TimeSensitive) |
| 26 | .show()?; |
| 27 | |
| 28 | println!("Notification sent."); |
| 29 | // TODO: add run_bundled script |
| 30 | // add oslog dev-dep |
| 31 | Ok(()) |
| 32 | } else { |
| 33 | println!("this example requires --features preview-macos-un on macOS"); |
| 34 | Ok(()) |
| 35 | } |
| 36 | } |
| 37 | } |