Struct notify_rust::Notification
source · [−]#[non_exhaustive]pub struct Notification {
pub appname: String,
pub summary: String,
pub subtitle: Option<String>,
pub body: String,
pub icon: String,
pub actions: Vec<String>,
pub timeout: Timeout,
/* private fields */
}
Expand description
Desktop notification.
A desktop notification is configured via builder pattern, before it is launched with show()
.
Example
Notification::new()
.summary("☝️ A notification")
.show()?;
Fields (Non-exhaustive)
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.appname: String
Filled by default with executable name.
summary: String
Single line to summarize the content.
subtitle: Option<String>
Subtitle for macOS
body: String
Multiple lines possible, may support simple markup,
check out get_capabilities()
-> body-markup
and body-hyperlinks
.
icon: String
Use a file:// URI or a name in an icon theme, must be compliant freedesktop.org.
actions: Vec<String>
See Notification::actions()
and Notification::action()
timeout: Timeout
Lifetime of the Notification in ms. Often not respected by server, sorry.
Implementations
sourceimpl Notification
impl Notification
sourcepub fn new() -> Notification
pub fn new() -> Notification
Constructs a new Notification.
Most fields are empty by default, only appname
is initialized with the name of the current
executable.
The appname is used by some desktop environments to group notifications.
sourcepub fn appname(&mut self, appname: &str) -> &mut Notification
pub fn appname(&mut self, appname: &str) -> &mut Notification
Overwrite the appname field used for Notification.
Platform Support
Please note that this method has no effect on macOS. Here you can only set the application via set_application()
sourcepub fn summary(&mut self, summary: &str) -> &mut Notification
pub fn summary(&mut self, summary: &str) -> &mut Notification
Set the summary
.
Often acts as title of the notification. For more elaborate content use the body
field.
sourcepub fn subtitle(&mut self, subtitle: &str) -> &mut Notification
pub fn subtitle(&mut self, subtitle: &str) -> &mut Notification
Set the subtitle
.
This is only useful on macOS, it’s not part of the XDG specification and will therefore be eaten by gremlins under your CPU 😈🤘.
sourcepub fn sound_name(&mut self, name: &str) -> &mut Notification
pub fn sound_name(&mut self, name: &str) -> &mut Notification
Set the sound_name
for the NSUserNotification
sourcepub fn body(&mut self, body: &str) -> &mut Notification
pub fn body(&mut self, body: &str) -> &mut Notification
Set the content of the body
field.
Multiline textual content of the notification. Each line should be treated as a paragraph. Simple html markup should be supported, depending on the server implementation.
sourcepub fn icon(&mut self, icon: &str) -> &mut Notification
pub fn icon(&mut self, icon: &str) -> &mut Notification
Set the icon
field.
You can use common icon names here, usually those in /usr/share/icons
can all be used.
You can also use an absolute path to file.
Platform support
macOS does not have support manually setting the icon. However you can pretend to be another app using set_application()
sourcepub fn auto_icon(&mut self) -> &mut Notification
pub fn auto_icon(&mut self) -> &mut Notification
Set the icon
field automatically.
This looks at your binary’s name and uses it to set the icon.
Platform support
macOS does not support manually setting the icon. However you can pretend to be another app using set_application()
sourcepub fn timeout<T: Into<Timeout>>(&mut self, timeout: T) -> &mut Notification
pub fn timeout<T: Into<Timeout>>(&mut self, timeout: T) -> &mut Notification
Set the timeout
.
This sets the time (in milliseconds) from the time the notification is displayed until it is closed again by the Notification Server. According to specification -1 will leave the timeout to be set by the server and 0 will cause the notification never to expire.
Platform support
This only works on XDG Desktops, macOS does not support manually setting the timeout.
sourcepub fn actions(&mut self, actions: Vec<String>) -> &mut Notification
👎 Deprecated: please use .action() only
pub fn actions(&mut self, actions: Vec<String>) -> &mut Notification
please use .action() only
Set actions
.
To quote http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
Actions are sent over as a list of pairs. Each even element in the list (starting at index 0) represents the identifier for the action. Each odd element in the list is the localized string that will be displayed to the user.
There is nothing fancy going on here yet. Careful! This replaces the internal list of actions!
(xdg only)
sourcepub fn action(&mut self, identifier: &str, label: &str) -> &mut Notification
pub fn action(&mut self, identifier: &str, label: &str) -> &mut Notification
Add an action.
This adds a single action to the internal list of actions.
(xdg only)
sourcepub fn id(&mut self, id: u32) -> &mut Notification
pub fn id(&mut self, id: u32) -> &mut Notification
Set an Id ahead of time
Setting the id ahead of time allows overriding a known other notification.
Though if you want to update a notification, it is easier to use the update()
method of
the NotificationHandle
object that show()
returns.
(xdg only)
sourcepub fn finalize(&self) -> Notification
pub fn finalize(&self) -> Notification
Finalizes a Notification.
Part of the builder pattern, returns a complete copy of the built notification.
sourcepub fn schedule_raw(&self, timestamp: f64) -> Result<NotificationHandle>
pub fn schedule_raw(&self, timestamp: f64) -> Result<NotificationHandle>
Schedules a Notification
Sends a Notification at the specified timestamp.
This is a raw f64
, if that is a bit too raw for you please activate the feature "chrono"
,
then you can use Notification::schedule()
instead, which accepts a chrno::DateTime<T>
.
sourcepub fn show(&self) -> Result<NotificationHandle>
pub fn show(&self) -> Result<NotificationHandle>
Sends Notification to NSUserNotificationCenter
.
Returns an Ok
no matter what, since there is currently no way of telling the success of
the notification.
Trait Implementations
sourceimpl Clone for Notification
impl Clone for Notification
sourcefn clone(&self) -> Notification
fn clone(&self) -> Notification
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Notification
impl Debug for Notification
sourceimpl Default for Notification
impl Default for Notification
sourcefn default() -> Notification
fn default() -> Notification
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for Notification
impl Send for Notification
impl Sync for Notification
impl Unpin for Notification
impl UnwindSafe for Notification
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more