### Get Server Information Usage Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/types.md Example of how to retrieve and display server information. Requires a successful call to `get_server_information`. ```rust let info = get_server_information()?; println!("Server: {} v{}", info.name, info.version); ``` -------------------------------- ### Progress Notification Example Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Shows how to display a progress bar within a notification. ```rust use notify_rust::Notification; Notification::new() .summary("Download Progress") .body("Downloading file...") .progress(50, 100, 50, true) // current, total, value, show_percentage .show() .unwrap(); ``` -------------------------------- ### Get Server Information with notify-rust Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md This example retrieves and formats the name and version of the notification server. It requires the 'unix' and not 'target_os = "macos"' features. ```rust #[cfg(all(unix, not(target_os = "macos")))] fn get_notification_server() -> Result { use notify_rust::get_server_information; let info = get_server_information()?; Ok(format!("{} {}", info.name, info.version)) } ``` -------------------------------- ### Minimal Notification Example Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification.md Demonstrates the simplest way to create and display a notification with just a summary. ```APIDOC ## Minimal Notification ### Description Creates and shows a basic notification with a summary. ### Code Example ```rust use notify_rust::Notification; Notification::new() .summary("Hello, World!") .show()?; ``` ``` -------------------------------- ### Display a Simple Notification Source: https://github.com/hoodie/notify-rust/blob/main/README.md Use this basic example to show a simple desktop notification. Ensure you handle the Result returned by show(). ```rust use notify_rust::Notification; Notification::new() .summary("Firefox News") .body("This will almost look like a real firefox notification.") .icon("firefox") .show()?; ``` -------------------------------- ### Notification Reuse Example Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates reusing a notification handle to update an existing notification. ```rust use notify_rust::Notification; let mut notification = Notification::new() .summary("Initial State") .body("This notification will be updated."); let handle = notification.show().unwrap(); // Update the notification content notification.body("Updated State"); handle.update(notification); // Close the notification after a delay std::thread::sleep(std::time::Duration::from_secs(5)); handle.close().unwrap(); ``` -------------------------------- ### Async/Await Usage Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Provides an example of using asynchronous operations to show notifications. ```rust use notify_rust::Notification; #[tokio::main] async fn main() { Notification::new() .summary("Async notification") .body("This was shown asynchronously.") .show_async() .await .unwrap(); } ``` -------------------------------- ### Handle Other CloseReason Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Example for handling the Other variant, which captures unrecognized or platform-specific close reason codes. ```rust CloseReason::Other(code) => println!("Unknown close reason: {}", code) ``` -------------------------------- ### Check Server Capabilities with notify-rust Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md This example checks if the notification server supports body markup and actions. It requires the 'unix' and not 'target_os = "macos"' features. ```rust #[cfg(all(unix, not(target_os = "macos")))] fn check_server_features() -> Result<()> { use notify_rust::get_capabilities; let caps = get_capabilities()?; let supports_markup = caps.iter() .any(|c| c == "body-markup"); let supports_actions = caps.iter() .any(|c| c == "actions"); println!("Supports HTML: {}", supports_markup); println!("Supports actions: {}", supports_actions); Ok(()) } ``` -------------------------------- ### Get Server Capabilities (XDG) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Queries the notification server for its supported capabilities on Linux/BSD systems using XDG. ```APIDOC ## Get Server Capabilities (XDG) ### Description Queries the notification server for its supported capabilities. This function is specific to XDG-compliant systems (Linux/BSD). ### Method Rust function call ### Function Signature `get_capabilities()` ### Returns Information about server capabilities. ``` -------------------------------- ### Schedule a Notification for macOS Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md This example schedules a notification to appear at a specific future time on macOS. It requires the `chrono` crate and the `target_os = "macos"` configuration. ```rust #[cfg(target_os = "macos")] { use chrono::Local; use chrono::Duration; let later = Local::now() + Duration::minutes(10); notification.schedule(later)?; } ``` -------------------------------- ### Usage of ResponseHandler Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Example of using a closure as a ResponseHandler with the wait_for_response method. The closure takes a NotificationResponse and prints it. ```rust let handler = |response: &NotificationResponse| { println!("Response: {:?}", response); }; handle.wait_for_response(handler)?; ``` -------------------------------- ### DbusStack Usage Example Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/types.md Demonstrates how to match on the DbusStack enum to determine which D-Bus implementation is currently active. This helps in conditional logic based on the D-Bus backend. ```rust match dbus_stack() { Some(DbusStack::Dbus) => println!("Using dbus-rs"), Some(DbusStack::Zbus) => println!("Using zbus"), None => println!("No D-Bus implementation"), } ``` -------------------------------- ### Get Notification Settings (Async) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/macos_functions.md Asynchronously queries the current notification settings for the application. Requires the `preview-macos-un` feature. ```rust #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] { let settings = notify_rust::get_notification_settings().await?; println!("Auth: {:?}", settings.authorizationStatus); println!("Sound enabled: {:?}", settings.soundSetting); } ``` -------------------------------- ### Get Server Information (XDG) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Retrieves detailed information about the notification server on Linux/BSD systems using XDG. ```APIDOC ## Get Server Information (XDG) ### Description Retrieves detailed information about the notification server, such as its name, vendor, version, and D-Bus specification version. This function is specific to XDG-compliant systems (Linux/BSD). ### Method Rust function call ### Function Signature `get_server_information()` ### Returns Details about the notification server. ``` -------------------------------- ### Simple Linux/BSD App Cargo.toml Configuration Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md A basic Cargo.toml setup for a Linux or BSD application using the notify-rust crate. This configuration includes the core dependency without any special features. ```toml [package] name = "my-notifier" version = "0.1.0" edition = "2021" [dependencies] notify-rust = "4" ``` -------------------------------- ### Asynchronous Action Waiting for Notifications Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification_handle.md Provides an example of asynchronously waiting for a notification action response, requiring the 'zbus' feature. ```rust #[cfg(feature = "zbus")] async fn async_example() -> Result<()> { use notify_rust::Notification; let handle = Notification::new() .summary("Async Test") .action("button", "Click Me") .show_async() .await?; handle.wait_for_action_async(|response| { println!("Response: {:?}", response); }).await; Ok(()) } ``` -------------------------------- ### Get Notification Server Capabilities (Rust) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md Queries the notification server for its supported capabilities. Use this to check if features like markup or actions are supported before attempting to use them. ```rust #[cfg(all(unix, not(target_os = "macos")))] { use notify_rust::get_capabilities; let caps = get_capabilities()?; println!("Server capabilities: {:?}", caps); if caps.contains(&"body-markup".to_string()) { println!("Server supports HTML markup in body"); } } ``` -------------------------------- ### Send Adaptive Notification with notify-rust Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md This example sends a notification that adapts its body content based on whether the server supports HTML markup. It requires the 'unix' and not 'target_os = "macos"' features. ```rust #[cfg(all(unix, not(target_os = "macos")))] fn send_adaptive_notification(summary: &str, body: &str) -> Result<()> { use notify_rust::{Notification, get_capabilities}; let caps = get_capabilities()?; let supports_markup = caps.iter() .any(|c| c == "body-markup"); let mut notif = Notification::new() .summary(summary); if supports_markup { notif.body(&format!("{}", body)); } else { notif.body(body); } notif.show()?; Ok(()) } ``` -------------------------------- ### Detect D-Bus Implementation with notify-rust Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md This example detects which D-Bus implementation (e.g., zbus or dbus-rs) is being used by the notification service. It requires the 'unix' and not 'target_os = "macos"' features. ```rust #[cfg(all(unix, not(target_os = "macos")))] fn which_dbus() { use notify_rust::dbus_stack; match dbus_stack() { Some(stack) => println!("Using: {:?}", stack), None => println!("No D-Bus"), } } ``` -------------------------------- ### Handle Notification Close Event Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/types.md Provides an example of using a closure to handle notification close events. The closure receives a `CloseReason` and can perform different actions based on why the notification was closed. ```rust handle.on_close(|reason: CloseReason| { match reason { CloseReason::Expired => println!("Timed out"), CloseReason::Dismissed => println!("User dismissed"), CloseReason::CloseAction => println!("Programmatically closed"), CloseReason::Other(code) => println!("Unknown: {}", code), } }); ``` -------------------------------- ### macOS App with Modern Backend Feature Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Configure Cargo.toml for a macOS application that uses the 'preview-macos-un' feature for a modern backend. This example also includes the chrono crate for date and time operations. ```toml [dependencies] notify-rust = { version = "4", features = ["preview-macos-un"] } chrono = "0.4" ``` -------------------------------- ### Standard Configuration (XDG, Async Optional) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md This is the default choice, using the `zbus` library for a higher-level API. It supports asynchronous operations via `show_async()` and `wait_for_action_async()` using the `async-io` runtime. ```toml notify-rust = { version = "4", features = ["z"] } ``` -------------------------------- ### Minimal Configuration (XDG, Synchronous) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Use this configuration for minimal overhead, synchronous blocking calls, and the smallest binary size. It relies on the `dbus-rs` library. ```toml notify-rust = { version = "4", features = ["d"] } ``` -------------------------------- ### Basic Action Handling with Callbacks Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification_handle.md Shows how to display a notification with actions and handle user responses using a callback function. ```rust use notify_rust::Notification; let handle = Notification::new() .summary("Confirm Action") .action("yes", "Yes") .action("no", "No") .show()?; handle.wait_for_action(|action| { match action { "yes" => println!("User confirmed"), "no" => println!("User cancelled"), "__closed" => println!("User closed without responding"), _ => {} } }); ``` -------------------------------- ### Send a Notification with Actions Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Configure a notification with custom actions (buttons) and handle user responses. The `show()` method returns a `NotificationHandle` which can be used to wait for a response. ```rust use notify_rust::Notification; let handle = Notification::new() .summary("Confirm") .action("yes", "Yes") .action("no", "No") .show()?; handle.wait_for_response(|response| { use notify_rust::NotificationResponse; match response { NotificationResponse::Action(key) => println!("Action: {}", key), NotificationResponse::Closed(_) => println!("Closed"), _ => {} } }); ``` -------------------------------- ### Set Desktop Entry Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Specifies the `.desktop` file entry for the application, used to retrieve the correct application icon. Pass the filename without the `.desktop` extension. ```rust notification.hint(Hint::DesktopEntry("firefox".to_owned())); ``` -------------------------------- ### Handle CloseAction CloseReason Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Example for handling the CloseAction variant, indicating the notification was closed programmatically. ```rust CloseReason::CloseAction => println!("Programmatically closed") ``` -------------------------------- ### Get Notification Settings (macOS) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Retrieves the current notification settings and permissions for the application on macOS. ```APIDOC ## Get Notification Settings (macOS) ### Description Retrieves the current notification settings for the application on macOS, including whether notifications are allowed and the alert style. ### Method Rust function call ### Function Signature `get_notification_settings()` ### Returns Notification settings information. ``` -------------------------------- ### Create a Simple Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Use this to display a basic notification with a summary and body. Ensure the notification library is set up correctly for your platform. ```rust Notification::new() .summary("Title") .body("Message") .show()?; ``` -------------------------------- ### Handle Dismissed CloseReason Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Example of handling the Dismissed variant, which occurs when the user actively closes a notification. ```rust CloseReason::Dismissed => println!("User dismissed notification") ``` -------------------------------- ### Basic Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Demonstrates how to create and display a simple desktop notification with a summary and body. ```APIDOC ## Basic Notification ### Description Creates and displays a simple desktop notification. ### Method Rust function call ### Code ```rust use notify_rust::Notification; Notification::new() .summary("Hello, World!") .body("This is a notification") .show()?; ``` ``` -------------------------------- ### Handle Expired CloseReason Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Example of handling the Expired variant of the CloseReason enum, typically when a notification times out. ```rust CloseReason::Expired => println!("Notification expired") ``` -------------------------------- ### Get Bundle Identifier or Default (macOS) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Retrieves the application's bundle identifier or a default value on macOS. ```APIDOC ## Get Bundle Identifier or Default (macOS) ### Description Retrieves the application's bundle identifier on macOS. If not explicitly set, it attempts to determine a default identifier. ### Method Rust function call ### Function Signature `get_bundle_identifier_or_default()` ### Returns The application's bundle identifier or a default. ``` -------------------------------- ### Response Handling Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Shows how to handle user responses to notifications with actions. ```rust use notify_rust::{Notification, NotificationHandle, NotificationResponse}; let handle = Notification::new() .summary("Response test") .body("Click an action.") .action("yes", "Yes") .action("no", "No") .show() .unwrap(); match handle.wait_for_response() { Ok(NotificationResponse::Action(action)) => println!("User clicked: {}", action), Ok(NotificationResponse::Close(reason)) => println!("Notification closed: {:?}", reason), Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### Notification Creation and Display Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/README.md Demonstrates how to create a new notification and display it asynchronously. ```APIDOC ## Notification::new() ### Description Creates a new notification builder. ### Method `Notification::new()` ### Code Example ```rust let mut notification = Notification::new(); ``` ## Notification::show_async() ### Description Displays the notification asynchronously. ### Method `notification.show_async()` ### Parameters None ### Response Returns a `Result`. ### Code Example ```rust let handle = notification.show_async().await.expect("Failed to show notification"); ``` ``` -------------------------------- ### Notification Creation and Display Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates how to create and display a basic notification using the builder pattern. ```APIDOC ## Notification::new() ### Description Creates a new notification builder. ### Method `Notification::new()` ### Parameters None ### Response Returns a `Notification` struct which can be further configured. ## Notification::show() ### Description Displays the notification immediately. ### Method `notification.show()` ### Parameters None ### Response Returns a `Result<(), Error>` indicating success or failure. ## Notification::show_async() ### Description Displays the notification asynchronously. ### Method `notification.show_async()` ### Parameters None ### Response Returns a `Future` that resolves to `Result<(), Error>`. ``` -------------------------------- ### DesktopEntry Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Specifies the .desktop file entry for the application, used to retrieve the correct application icon. Parameter type is String. ```APIDOC ## DesktopEntry(String) ### Description Specifies the `.desktop` file entry for the application. Used to retrieve the correct icon for the application. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust notification.hint(Hint::DesktopEntry("firefox".to_owned())); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get Notification Settings (Blocking) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/macos_functions.md Synchronously queries the current notification settings for the application. Requires the `preview-macos-un` feature. ```rust #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] { let settings = notify_rust::get_notification_settings_blocking()?; if settings.soundSetting == NotificationSetting::Disabled { println!("Sound is disabled"); } } ``` -------------------------------- ### Initialize Logging with env_logger Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md The library uses the `log` crate for debug output. Initialize the logger using `env_logger::init()` to enable logging. ```rust env_logger::init(); ``` -------------------------------- ### show Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification.md Sends the notification to the platform's notification server and returns a handle. ```APIDOC ## show ### Description Sends the notification to the platform's notification server and returns a handle. ### Method `show` ### Returns `Result` — a handle for waiting on actions or updating. ### Errors - D-Bus connection failures (XDG) - System notification service unavailable (macOS/Windows) - Message marshalling errors ### Request Example ```rust use notify_rust::Notification; let handle = Notification::new() .summary("Hello") .show()?; ``` ``` -------------------------------- ### Get Notification ID (XDG Only) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification_handle.md Retrieves the numeric notification ID from the notification server. This method is only supported on the XDG platform. ```rust let notification_id = handle.id(); println!("Notification ID: {}", notification_id); ``` -------------------------------- ### Create a Basic Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates the creation of a simple notification using the Notification::new() constructor and basic builder methods. Requires the 'notify-rust' crate. ```rust use notify_rust::Notification; Notification::new() .summary("Test Summary") .body("This is the notification body.") .show()?; Ok(()) ``` -------------------------------- ### Multithreaded Notification Sending Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Send notifications from any thread as the `Notification` type is thread-safe. This example spawns a new thread to send a notification. ```rust std::thread::spawn(|| { Notification::new() .summary("From thread") .show() .ok(); }); ``` -------------------------------- ### Configure D-Bus Backend Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Shows how to configure the D-Bus backend for notify-rust using environment variables, specifically `DBUS_SESSION_ADDRESS`. This is relevant for Linux systems using D-Bus. Requires the 'notify-rust' crate. ```rust use std::env; use notify_rust::Notification; // Set the D-Bus session address environment variable // env::set_var("DBUS_SESSION_ADDRESS", "unix:path=/run/user/1000/bus"); // Now, notifications will attempt to use this D-Bus address // Notification::new().summary("D-Bus Configured").show()?; Ok(()) ``` -------------------------------- ### InterruptionLevel Usage Example (macOS) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/types.md Shows how to set the interruption level for a notification on macOS using the InterruptionLevel enum. This requires the 'preview-macos-un' feature to be enabled. ```rust #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] notification.interruption_level(InterruptionLevel::Critical); ``` -------------------------------- ### Use Notification Hints Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Shows how to apply various hints to a notification, such as setting an icon, category, or position. Requires the 'notify-rust' crate. ```rust use notify_rust::{Notification, Hint, Image}; Notification::new() .summary("Notification with Hints") .body("Check out these custom hints!") .hint(Hint::Category("email".to_string())) .hint(Hint::Icon(Image::Data { mime: "image/png".to_string(), data: vec![0u8; 10] })) .hint(Hint::Resident(true)) .show()?; Ok(()) ``` -------------------------------- ### Get Notification Server Information (Rust) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md Queries the notification server for its identity and specification version. Useful for debugging or logging which notification server is active. ```rust #[cfg(all(unix, not(target_os = "macos")))] { use notify_rust::get_server_information; let info = get_server_information()?; println!("Server: {} v{}", info.name, info.version); println!("Spec version: {}", info.spec_version); } ``` -------------------------------- ### Configuration Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Information on how to configure notify-rust using environment variables and Cargo features, including details on default features and platform-specific configurations. ```APIDOC ## Configuration ### Description Guides users on configuring the `notify-rust` library through environment variables and Cargo features. ### Environment Variables - **`DBUSRS`**: Specifies the D-Bus backend implementation to use (e.g., `dbus-rs`, `zbus`). - **D-Bus Environment Variables**: Other D-Bus related environment variables that might influence behavior. ### Cargo Features - **Total Features**: 11 features available. - **Default Features**: Explanation of features enabled by default. - **Feature Matrix**: Details dependencies and compatibility between features. - **Feature Selection Guide**: Recommendations for selecting features based on use cases (e.g., minimal, standard, tokio, macOS). ### Conditional Compilation Patterns and examples for using Cargo features to conditionally compile code for different platforms or functionalities. ### `Cargo.toml` Examples Illustrative examples of how to specify features and dependencies in a project's `Cargo.toml` file. ### Runtime Configuration How configuration settings can be applied or modified at runtime. ### MSRV Information Details on the Minimum Supported Rust Version (MSRV) for the library. ### Platform Requirements Outlines the system requirements and dependencies for running `notify-rust` on different operating systems. ``` -------------------------------- ### Cross-Platform App with Images Feature Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Configure Cargo.toml for a cross-platform application that utilizes the 'images' feature of notify-rust. This example also includes the tokio runtime for asynchronous operations. ```toml [dependencies] notify-rust = { version = "4", features = ["z", "images"] } tokio = { version = "1", features = ["full"] } ``` -------------------------------- ### Complete Feature Set Configuration Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Includes all available features for maximum functionality across different platforms and use cases, combining XDG, image support, async, Tokio, and macOS modern backend features. ```toml notify-rust = { version = "4", features = [ "z", "d", "images", "async", "tokio", "preview-macos-un", ] } ``` -------------------------------- ### Get Server Information (XDG) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Retrieves information about the D-Bus notification server, such as its name and version. This is specific to Linux/XDG environments. Requires the 'notify-rust' crate and the 'dbus' feature. ```rust use notify_rust::get_server_information; let (name, vendor, version, spec_version) = get_server_information().unwrap(); println!("Server: {} by {} version {}", name, vendor, version); println!("Spec version: {}", spec_version); Ok(()) ``` -------------------------------- ### XDG Hints Usage Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Illustrates using XDG-specific hints to control notification appearance or behavior. ```rust use notify_rust::{Notification, Hint, Urgency}; Notification::new() .summary("Notification with hints") .body("This uses XDG hints.") .hint(Hint::Urgency(Urgency::Critical)) .hint(Hint::Category("device".to_string())) .show() .unwrap(); ``` -------------------------------- ### Features and Configuration Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Information on available features and how to configure the Notify-Rust library. ```APIDOC ## configuration.md ### Description Details the features available in Notify-Rust and provides guidance on configuration options. ### Features The Notify-Rust library supports conditional compilation for platform-specific backends. Users can enable or disable features based on their target platform: - **`macos`**: Enables macOS specific functionality. - **`windows`**: Enables Windows specific functionality. - **`linux`**: Enables Linux specific functionality (requires `libnotify`). These features can be enabled during the build process using Cargo: ```bash cargo build --features "macos windows" ``` ### Configuration Options While Notify-Rust aims for a consistent API across platforms, some platform-specific behaviors can be influenced by system-level settings or environment variables. Refer to the platform-specific documentation (`xdg_functions.md`, `macos_functions.md`, `windows_notifications.md`) for details. For example, on Linux, the `libnotify` version and its capabilities can affect notification appearance and behavior. ``` -------------------------------- ### XDG Hint System Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Documentation for the XDG hint system integration. ```APIDOC ## hints.md ### Description Documentation for the XDG hint system used for Linux notifications. ### Public Types - **Hint**: Represents a hint that can be attached to a notification. ### Constants - **Hint::Category(category: &str)**: Sets the notification category. - **Hint::Urgency(urgency: Urgency)**: Sets the notification urgency level. See `types.md` for `Urgency` enum. - **Hint::ActionIcons(show_icons: bool)**: Toggles the display of action icons. - **Hint::Resident(persistent: bool)**: Makes the notification persistent. - **Hint::Image(image_path: &str)**: Attaches an image to the notification. - **Hint::SoundName(sound_name: &str)**: Specifies a sound to play. - **Hint::Sound(sound_data: &[u8])**: Provides raw sound data. - **Hint::Custom(key: &str, value: &str)**: Allows setting custom hints. ``` -------------------------------- ### Minimal Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates the most basic usage of creating and showing a notification. ```rust use notify_rust::Notification; Notification::new() .summary("Test notification") .body("This is the body of the test notification.") .show() .unwrap(); ``` -------------------------------- ### Enable Cargo Features Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates how to enable specific Cargo features for the notify-rust crate in `Cargo.toml` to include platform-specific backends or functionalities. This is a build-time configuration. ```toml [dependencies.notify-rust] version = "4.18.0" features = ["dbus", "win-toast", "mac-notification-sys"] ``` -------------------------------- ### Set Image Path Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Points to an image file to be displayed in the notification. This hint works across platforms without requiring the `images` feature. ```rust notification.hint(Hint::ImagePath("/path/to/image.png".to_owned())); ``` -------------------------------- ### Get Default Application Bundle Identifier (macOS) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/macos_functions.md Retrieves the currently set application bundle identifier or a default value on macOS. This is useful for understanding the current notification context or for fallback mechanisms. ```rust #[cfg(target_os = "macos")] { let current_bundle = notify_rust::get_bundle_identifier_or_default(); println!("Current bundle: {}", current_bundle); } ``` -------------------------------- ### Notification with Body and Icon Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Shows how to add a body and an icon to a notification. ```rust use notify_rust::Notification; Notification::new() .summary("Notification with icon") .body("This notification has an icon.") .icon("face-smile") .show() .unwrap(); ``` -------------------------------- ### SoundName Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Uses a themed sound name from the freedesktop.org sound naming specification, allowing for theme-aware sound playback. Parameter type is String. ```APIDOC ## SoundName(String) ### Description A themed sound name from the freedesktop.org sound naming specification. This is theme-aware and preferred over hardcoded paths. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust notification.hint(Hint::SoundName("message-new-instant".to_owned())); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Interaction and Callbacks Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Details on how to interact with notifications and handle callbacks. ```APIDOC ## notification_handle.md ### Description Provides functionality for interacting with notifications and handling user callbacks. ### Public Types - **NotificationHandle**: Represents a handle to a displayed notification, allowing for interaction. ### Methods - **NotificationHandle::close()**: Closes the notification. - **NotificationHandle::on_click(callback: F)**: Registers a callback function to be executed when the notification is clicked. `F` must be a closure that takes no arguments and returns `()`. The closure must be `'static`. - **NotificationHandle::on_close(callback: F)**: Registers a callback function to be executed when the notification is closed. `F` must be a closure that takes no arguments and returns `()`. The closure must be `'static`. ``` -------------------------------- ### Error Handling Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates how to handle potential errors when showing notifications. ```rust use notify_rust::Notification; match Notification::new().summary("Error test").show() { Ok(_) => println!("Notification shown successfully."), Err(e) => eprintln!("Failed to show notification: {}", e), } ``` -------------------------------- ### Callback Patterns Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Demonstrates using callbacks for handling notification close events. ```rust use notify_rust::{Notification, CloseReason}; Notification::new() .summary("Callback test") .body("This notification will trigger a callback.") .on_close(move |reason| { match reason { CloseReason::Expired => println!("Notification expired."), CloseReason::Dismissed => println!("Notification dismissed by user."), CloseReason::UserCancelled => println!("Notification cancelled by user."), _ => println!("Notification closed for unknown reason."), } }) .show() .unwrap(); ``` -------------------------------- ### get_capabilities Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/xdg_functions.md Queries the notification server for its supported capabilities. Returns a list of capability strings. ```APIDOC ## GET /get_capabilities ### Description Queries the notification server for its supported capabilities. ### Method GET ### Endpoint /get_capabilities ### Parameters #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **capabilities** (array of strings) - List of capability strings supported by the server. #### Response Example { "capabilities": ["action-icons", "actions", "body", "body-hyperlinks", "body-markup", "icon-static", "persistence", "sound"] } ### Errors - D-Bus connection failure - Notification server not running ``` -------------------------------- ### Handle Notification Actions and Responses Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Illustrates how to wait for user interaction with a notification, specifically handling actions and closing events. This involves using NotificationHandle and its methods. Requires the 'notify-rust' crate. ```rust use notify_rust::{Notification, NotificationHandle}; let handle: NotificationHandle = Notification::new() .summary("Waiting for response") .body("This notification will wait for your input.") .show()?; // Wait for a specific action to be taken let response = handle.wait_for_action().await; println!("Action taken: {:?}", response); // Or wait for the notification to be closed let close_reason = handle.wait_for_close().await; println!("Notification closed: {:?}", close_reason); Ok(()) ``` -------------------------------- ### Notification Struct and Builder Methods Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Documentation for the Notification struct, its constructor, and over 25 builder methods used to configure notifications. Includes parameter details, return types, error conditions, and platform-specific behavior. ```APIDOC ## Notification Struct ### Description Represents a desktop notification with various configurable properties. ### Methods #### `new()` - **Description**: Creates a new, empty `Notification` instance. - **Signature**: `pub fn new() -> Notification` #### Builder Methods (Examples) - **`summary(summary: &str)`**: Sets the notification's summary (title). - **`body(body: &str)`**: Sets the notification's body text. - **`icon(icon: &str)`**: Sets the notification's icon path or name. - **`timeout(timeout: Timeout)`**: Sets the notification's display duration. ### Parameters Each builder method accepts specific parameters as detailed in the `notification.md` file. ### Return Types Builder methods typically return `&mut self` to allow chaining. ### Error Conditions Refer to the `errors.md` file for potential errors during notification creation or display. ### Platform-Specific Behavior Details on how notification properties are handled on different operating systems are available in `notification.md`. ``` -------------------------------- ### Closing Notifications with a Callback Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification_handle.md Demonstrates how to set up a callback function that is executed when a notification is closed. ```rust use notify_rust::Notification; let handle = Notification::new() .summary("Temporary Message") .body("This will close automatically") .show()?; handle.on_close(|reason| { println!("Notification closed: {:?}", reason); }); ``` -------------------------------- ### Set Sound File Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Specifies the absolute path to a sound file to be played with the notification. ```rust notification.hint(Hint::SoundFile("/path/to/sound.wav".to_owned())); ``` -------------------------------- ### SoundFile Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Specifies the absolute path to a sound file to be played with the notification. Parameter type is String. ```APIDOC ## SoundFile(String) ### Description Path to a sound file to play with the notification. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust notification.hint(Hint::SoundFile("/path/to/sound.wav".to_owned())); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Windows Toast Configuration Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Configures a Windows toast notification with specific app ID and sound. ```rust use notify_rust::Notification; Notification::new() .summary("Windows Toast") .body("A configured Windows notification.") .app_id("my_app_id") // Required for Windows toasts .sound_name("default") // Optional: specify sound .show() .unwrap(); ``` -------------------------------- ### Notification with Actions Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Illustrates how to add interactive actions (buttons) to a notification. ```rust use notify_rust::Notification; Notification::new() .summary("Notification with actions") .body("Click a button!") .action("action1", "Click Me!") .action("action2", "Cancel") .show() .unwrap(); ``` -------------------------------- ### Select D-Bus Implementation at Runtime Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md When both `dbus-rs` and `zbus` are compiled as features, you can choose which D-Bus implementation to use at runtime by setting the `DBUSRS` environment variable. ```bash # Use dbus-rs even if both compiled DBUSRS=1 ./my-app ``` ```bash # Use zbus (default) ./my-app ``` -------------------------------- ### Comprehensive Response Handling with NotificationResponse Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Use `wait_for_response` to handle different user interactions like clicking the body, selecting an action, replying, or closing the notification. Requires importing `NotificationResponse` and `CloseReason`. ```rust use notify_rust::{Notification, NotificationResponse}; let handle = Notification::new() .summary("Action Required") .action("approve", "Approve") .action("reject", "Reject") .show()?; handle.wait_for_response(|response| { match response { NotificationResponse::Default => { println!("User clicked the notification body"); } NotificationResponse::Action(key) => { match key.as_str() { "approve" => println!("User approved"), "reject" => println!("User rejected"), _ => println!("Unknown action: {}", key), } } NotificationResponse::Reply(text) => { println!("User replied: {}", text); } NotificationResponse::Closed(reason) => { match reason { CloseReason::Expired => println!("Notification expired"), CloseReason::Dismissed => println!("User dismissed"), CloseReason::CloseAction => println!("Programmatically closed"), CloseReason::Other(code) => println!("Unknown reason: {}", code), } } } }); ``` -------------------------------- ### Image Support Configuration (XDG) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Enables the `Notification::image_data()` method for XDG systems. This configuration adds `image` and `lazy_static` dependencies and requires image format detection on startup. ```toml notify-rust = { version = "4", features = ["z", "images"] } ``` -------------------------------- ### Create a Notification with Actions Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md This snippet demonstrates how to add custom actions to a notification. The `wait_for_action` method allows you to handle user interaction with these actions. ```rust let handle = Notification::new() .summary("Question") .action("yes", "Yes") .action("no", "No") .show()?; handle.wait_for_action(|action| { // action: "yes", "no", "default", or "__closed" }); ``` -------------------------------- ### Async App with Tokio Runtime Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/configuration.md Set up Cargo.toml for an asynchronous application using notify-rust with the 'z-with-tokio' feature. This configuration explicitly enables the tokio runtime with necessary features. ```toml [dependencies] notify-rust = { version = "4", features = ["z-with-tokio"] } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } ``` -------------------------------- ### Usage of CloseHandler with Reason Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Demonstrates how to use the on_close method with a closure that accepts a CloseReason argument to handle notification closure events. ```rust // With reason parameter handle.on_close(|reason: CloseReason| { println!("Closed: {:?}", reason); }); ``` -------------------------------- ### Check Bundle Notification Settings (Async) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/macos_functions.md Asynchronously checks notification settings for a specific application bundle identifier. Requires the `preview-macos-un` feature. ```rust #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] { let settings = notify_rust::check_bundle("com.apple.Mail").await?; println!("Mail sound setting: {:?}", settings.soundSetting); } ``` -------------------------------- ### Send a Basic Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Use this snippet to send a simple desktop notification with a summary and body. Ensure the `notify-rust` crate is added as a dependency. ```rust use notify_rust::Notification; Notification::new() .summary("Hello, World!") .body("This is a notification") .show()?; ``` -------------------------------- ### Typed Response Handling for Notifications Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification_handle.md Illustrates how to handle different types of notification responses, including default clicks, actions, and closure reasons. ```rust use notify_rust::{Notification, NotificationResponse}; let handle = Notification::new() .summary("Test") .action("approve", "Approve") .show()?; handle.wait_for_response(|response| { match response { NotificationResponse::Default => println!("Body clicked"), NotificationResponse::Action(key) => println!("Action: {}", key), NotificationResponse::Closed(reason) => println!("Closed: {:?}", reason), NotificationResponse::Reply(_) => println!("Inline reply (macOS UN)"), } }); ``` -------------------------------- ### ImagePath Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Points to an image file to display in the notification. Accepts a file URI or absolute path and works across all platforms without requiring extra features. Parameter type is String. ```APIDOC ## ImagePath(String) ### Description Points to an image file to display. Works across all platforms without requiring extra features. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust notification.hint(Hint::ImagePath("/path/to/image.png".to_owned())); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Toast with Subtitle and Image Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/windows_notifications.md Combines a subtitle with the main body text and an image for richer notification content. Ensure the image path is correct. ```rust use notify_rust::Notification; Notification::new() .summary("News Update") .subtitle("Technology") .body("New article published: The Future of AI") .image_path("C:\\app\\assets\\tech-icon.png") .show()?; ``` -------------------------------- ### Create a Persistent Notification (XDG) Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md For XDG-compliant systems, this shows how to create a notification that will not time out. It uses the `Hint::Resident` hint and `Timeout::Never`. ```rust use notify_rust::{Notification, Hint, Timeout}; Notification::new() .summary("Important") .hint(Hint::Resident(true)) .timeout(Timeout::Never) .show()?; ``` -------------------------------- ### Async Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md Illustrates how to send notifications asynchronously using the `zbus` feature. ```APIDOC ## Async Notification ### Description Sends a desktop notification asynchronously, suitable for use in async Rust applications. Requires the `zbus` feature to be enabled. ### Method Rust async function call ### Code ```rust #[cfg(feature = "zbus")] async fn async_example() -> Result<()> { use notify_rust::Notification; let handle = Notification::new() .summary("Async Notification") .show_async() .await?; Ok(()) } ``` ``` -------------------------------- ### Image Notification with Hints Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Display a notification with a custom image path and category. ```rust use notify_rust::{Notification, Hint}; Notification::new() .summary("Image Notification") .body("With a themed image path") .hint(Hint::ImagePath("/usr/share/pixmaps/firefox.png".to_owned())) .hint(Hint::Category("im.received".to_owned())) .show()?; ``` -------------------------------- ### Check Boolean Hint Value Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Demonstrates how to check if a hint is a boolean and retrieve its value using `as_bool()`. ```rust if let Hint::Resident(val) = hint { println!("Is resident: {}", val); } match hint.as_bool() { Some(true) => println!("Boolean hint: true"), Some(false) => println!("Boolean hint: false"), None => println!("Not a boolean hint"), } ``` -------------------------------- ### Response Types and Callbacks Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Details on response types and how to handle callbacks from notification interactions. ```APIDOC ## response.md ### Description Defines response types and callback mechanisms for notification events. ### Public Types - **NotificationResponse**: Represents the response from a notification interaction. - **id**: u32 - The ID of the notification. - **event**: NotificationEvent - The type of event that occurred. - **data**: Option - Additional data associated with the event (e.g., action key). - **NotificationEvent**: Enum representing different notification events. - **Click**: The notification was clicked. - **Close**: The notification was closed by the user or system. - **Timeout**: The notification timed out. - **Action(action_key: String)**: An action button was clicked, with `action_key` being the key of the clicked action. ### Callbacks Callbacks are registered using `NotificationHandle::on_click` and `NotificationHandle::on_close`. These callbacks are invoked when the corresponding event occurs. The `NotificationResponse` struct provides details about the event. ``` -------------------------------- ### Minimal Notification Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification.md Creates and displays a basic notification with a summary. Ensure the `notify_rust` crate is added as a dependency. ```rust use notify_rust::Notification; Notification::new() .summary("Hello, World!") .show()?; ``` -------------------------------- ### Conversion from u32 Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/response.md Demonstrates how to convert a `u32` value into a `CloseReason` enum variant. ```APIDOC ### Conversion from u32 ```rust CloseReason::from(1u32); // Expired CloseReason::from(2u32); // Dismissed CloseReason::from(3u32); // CloseAction CloseReason::from(99u32); // Other(99) ``` ``` -------------------------------- ### Query Server Capabilities for XDG Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/index.md On XDG-compatible Unix systems (excluding macOS), this code queries the notification server for supported capabilities, such as markup support. ```rust #[cfg(all(unix, not(target_os = "macos")))] { let caps = notify_rust::get_capabilities()?; if caps.contains(&"body-markup".to_string()) { // Server supports HTML } } ``` -------------------------------- ### show_async Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/notification.md Asynchronously sends the notification. Platform support: XDG (via zbus), macOS (preview-macos-un). Requires: async feature (XDG), or runs on macOS UNUserNotificationCenter. ```APIDOC ## show_async ### Description Asynchronously sends the notification. ### Method `show_async` ### Returns `Result` ### Platform Support XDG (via zbus), macOS (preview-macos-un). ### Requires `async` feature (XDG), or runs on macOS UNUserNotificationCenter. ### Request Example ```rust #[cfg(feature = "zbus")] let handle = notification.show_async().await?; ``` ``` -------------------------------- ### Windows Specific API Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Documentation for Windows-specific notification functionalities. ```APIDOC ## windows_notifications.md ### Description Windows-specific API functions for sending notifications using the Windows Action Center. ### Functions - **send_notification(notification: &Notification)**: Sends a notification using the Windows Runtime `ToastNotification` API. ### Notes - Requires Windows 10 or later. - The application needs to be registered with the Windows Store or have an AppID configured. - Supports rich content and interactive actions as defined by the Windows notification platform. ``` -------------------------------- ### Set Sound Name Hint Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/hints.md Uses a themed sound name from the freedesktop.org sound naming specification, which is theme-aware and preferred over hardcoded paths. ```rust notification.hint(Hint::SoundName("message-new-instant".to_owned())); ``` -------------------------------- ### Traits and Callbacks Source: https://github.com/hoodie/notify-rust/blob/main/_autodocs/MANIFEST.txt Explains the traits and callback patterns used for handling notification responses and closures. ```APIDOC ## Traits & Callbacks ### ResponseHandler - `trait ResponseHandler: FnOnce(&NotificationResponse)`: A trait for handling notification responses. ### CloseHandler - `trait CloseHandler: Fn(CloseReason) or Fn()`: A trait for handling notification closure events. ### wait_for_action - `FnOnce(&str)`: Callback for when a specific action is triggered. ### wait_for_action_async - `FnOnce(&NotificationResponse)`: Asynchronous callback for when an action is triggered, providing the response. ```