Skip to main content

mac_usernotifications/
interrupt.rs

1use objc2_user_notifications::UNNotificationInterruptionLevel;
2
3/// Controls how a notification interrupts the user.
4///
5/// Maps to [`UNNotificationInterruptionLevel`](https://developer.apple.com/documentation/usernotifications/unnotificationinterruptionlevel). Available on macOS 12+.
6/// On older systems the value is silently ignored by the OS.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum InterruptionLevel {
9    /// Adds to the notification list without lighting the screen or playing a sound.
10    Passive,
11
12    /// Presents immediately, lights the screen, and can play a sound. The default.
13    Active,
14
15    /// Presents immediately and bypasses Focus settings.
16    TimeSensitive,
17
18    /// Presents immediately, bypasses mute and Do Not Disturb. Requires a special entitlement.
19    Critical,
20}
21
22impl InterruptionLevel {
23    pub(crate) fn to_un_level(self) -> UNNotificationInterruptionLevel {
24        match self {
25            InterruptionLevel::Passive => UNNotificationInterruptionLevel::Passive,
26            InterruptionLevel::Active => UNNotificationInterruptionLevel::Active,
27            InterruptionLevel::TimeSensitive => UNNotificationInterruptionLevel::TimeSensitive,
28            InterruptionLevel::Critical => UNNotificationInterruptionLevel::Critical,
29        }
30    }
31}