Skip to main content

gpui_platform/
notification.rs

1//! System notification types shared by `gpui` and its platform backends.
2
3use gpui_shared_string::SharedString;
4
5/// A notification posted to the operating system's notification center,
6/// rather than rendered as in-app UI.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct SystemNotification {
9    /// Stable identity for the notification. Posting a new notification with
10    /// the same tag replaces the previous one where the platform supports it,
11    /// and responses carry the tag back to the application.
12    pub tag: SharedString,
13    /// The notification's headline.
14    pub title: SharedString,
15    /// Additional text displayed below the title.
16    pub body: SharedString,
17    /// Buttons offered on the notification. Platforms that cannot display
18    /// action buttons show the notification without them.
19    pub actions: Vec<SystemNotificationAction>,
20}
21
22/// A button offered on a [`SystemNotification`].
23#[derive(Clone, Debug, PartialEq, Eq, Hash)]
24pub struct SystemNotificationAction {
25    /// Identifies the action in [`SystemNotificationResponse::action_id`]
26    /// when the user presses this button.
27    pub id: SharedString,
28    /// The button's user-visible label.
29    pub label: SharedString,
30}
31
32/// The user's activation of a [`SystemNotification`].
33#[derive(Clone, Debug, PartialEq, Eq)]
34pub struct SystemNotificationResponse {
35    /// The [`SystemNotification::tag`] of the activated notification.
36    pub tag: SharedString,
37    /// The pressed action button's [`SystemNotificationAction::id`], or
38    /// `None` when the user activated the notification body itself.
39    pub action_id: Option<SharedString>,
40}