universal_notifications

Crates.iouniversal_notifications
lib.rsuniversal_notifications
version0.1.7
created_at2025-10-03 10:32:55.796242+00
updated_at2025-11-10 21:16:56.356522+00
descriptionWrapper for WINRT toast api and UserNotifications
homepage
repository
max_upload_size
id1866507
size257,309
Niklas Hansen (Y2KForever)

documentation

https://docs.rs/universal-notifications

README

Universal Notifications

An incomplete wrapper for WinRT Toast and MacOS UserNotifications

Known Issues:

  • Only works on Windows 10 and 11.

Usage

//Cargo.toml
[dependencies]
universal_notifications = "0.1.1"

// Or if you want only some features
[dependencies]
universal_notifications = { version = "0.1.1", features = ["windows"]}

Note: All Windows-specific examples require the windows feature and must be run on Windows 10/11.

Examples

Simple Toast

use universal_notifications::Toast;
use universal_notifications::Duration;

fn main() -> windows::core::Result<()> {
    Toast::new(Toast::APP_ID)
        .title("Hello, World!")
        .description("This is a simple toast notification.")
        .duration(Duration::Short)
        .show()?;

    Ok(())
}

Toast with Images and Icons

use std::path::Path;
use universal_notifications::{Toast, Duration, IconCrop};

fn main() -> windows::core::Result<()> {
    let icon_path = Path::new(r"C:\path\to\icon.png");
    let image_path = Path::new(r"C:\path\to\image.jpg");

    Toast::new(Toast::APP_ID)
        .title("Picture Toast")
        .description("This toast has an icon and an image.")
        .icon(icon_path, IconCrop::Circular, "App icon")
        .image(image_path, "Main image")
        .duration(Duration::Long)
        .show()?;

    Ok(())
}

Toast with Actions and Sound

use universal_notifications::{Toast, Duration, ActivationType, Sound, LoopableSound};

fn main() -> windows::core::Result<()> {
    Toast::new(Toast::APP_ID)
        .title("Action Toast")
        .description("You can interact with this notification.")
        .action("Open App", "open", ActivationType::Foreground)
        .action("Dismiss", "dismiss", ActivationType::Background)
        .sound(Some(Sound::Loop(LoopableSound::Alarm)))
        .duration(Duration::Long)
        .show()?;

    Ok(())
}

Silent Toast

use universal_notifications::{Toast, Duration};

fn main() -> windows::core::Result<()> {
    Toast::new(Toast::APP_ID)
        .title("Silent Notification")
        .description("No sound will play for this one.")
        .sound(None)
        .duration(Duration::Short)
        .show()?;

    Ok(())
}
Commit count: 0

cargo fmt