Crate notify_rust [] [src]

Desktop Notifications for Rust.

Desktop notifications are popup messages generated to notify the user of certain events.

Platform Support

Since Version 3.3 this crate builds on macOS, however since the semantic of notifications is quite different between the XDG specification and macOS, only the a very small subset of functions is supported.

Examples

Example 1: Simple Notification

Notification::new()
    .summary("Firefox News")
    .body("This will almost look like a real firefox notification.")
    .icon("firefox")
    .timeout(Timeout::Milliseconds(6000)) //milliseconds
    .show().unwrap();

Example 2: Persistent Notification

Notification::new()
    .summary("Category:email")
    .body("This has nothing to do with emails.\nIt should not go away until you acknoledge it.")
    .icon("thunderbird")
    .appname("thunderbird")
    .hint(NotificationHint::Category("email".to_owned()))
    .hint(NotificationHint::Resident(true)) // this is not supported by all implementations
    .timeout(Timeout::Never) // this however is
    .show().unwrap();

Careful! There are no checks whether you use hints twice. It is possible to set urgency=Low AND urgency=Critical, in which case the behavior of the server is undefined.

Example 3: Ask the user to do something

Notification::new()
    .summary("click me")
    .action("default", "default")
    .action("clicked", "click here")
    .hint(NotificationHint::Resident(true))
    .show()
    .unwrap()
    .wait_for_action({|action|
        match action {
            "default" => {println!("you clicked \"default\"")},
            "clicked" => {println!("that was correct")},
            // here "__closed" is a hardcoded keyword
            "__closed" => {println!("the notification was closed")},
            _ => ()
        }
    });

Minimal Example

You can ommit almost everything

Notification::new()
    .show();

more examples in the repository.

Reexports

pub use hints::NotificationHint;

Modules

hints

NotificationHints allow to pass extra information to the server.

server

Experimental server taking the place of your Desktop Environments Notification Server.

Structs

Error

D-Bus Error wrapper

Notification

Desktop notification.

ServerInformation

Return value of get_server_information().

Enums

NotificationUrgency

Levels of Urgency.

Timeout

Describes the timeout of a notification

Functions

get_capabilities

Get list of all capabilities of the running notification server.

get_server_information

Returns a struct containing ServerInformation.

handle_actions

Listens for the ActionInvoked(UInt32, String) Signal.

stop_server

Strictly internal. The Notificationserver implemented here exposes a "Stop" function. stops the notification server