#toast #windows #notify #notifications #desktop-notifications

yanked windows-toast

Show desktop notifications on Windows

1.3.8 Feb 11, 2023
1.3.7 Feb 4, 2023
1.3.4 Jan 31, 2023

#14 in #toast

Download history 24/week @ 2024-02-25 61/week @ 2024-03-31

61 downloads per month

MIT license

31KB
683 lines

windows-toast

Show desktop notifications on Windows

Example

use std::{collections::HashMap, thread::sleep, time::Duration as Dur};
use windows_toast::{ActivationType, Crop, Duration, Toast, MSEDGE_APP_ID};

fn main() {
    let handler = Toast::new(MSEDGE_APP_ID)
        .set_title("Hello from Rust! 🦀")
        .set_description("It works!")
        .set_image("https://rustacean.net/assets/rustacean-flat-happy.png")
        .set_icon("https://crates.io/assets/cargo.png", Crop::Circle)
        .add_button(
            "Yes!",
            "https://www.rust-lang.org",
            ActivationType::Protocol,
            Some("https://icons.veryicon.com/png/o/object/material-design-icons/done-1.png"),
        )
        .add_button(
            "Certainly!",
            "https://www.rust-lang.org",
            ActivationType::Protocol,
            Some("https://icons.veryicon.com/png/o/business/simple-linear-icon-icon/cancel-44.png"),
        )
        .set_progress("Downloading", "Active", "0.0", "0/10")
        .add_selection(vec!["Rust 1", "Rust 2", "Rust 3"], "selection")
        .add_input("Message", "msg")
        .on_activated(Box::new(move |args| {
            println!("Activated! Args: {:?}", args);
        }))
        .show()
        .unwrap();

    let mut i = 0;

    while i != 10 {
        sleep(Dur::from_secs(1));
        handler
            .update_progress(
                "Downloading",
                "Active",
                &format!("0.{}", i),
                &format!("{}/10", i),
                None,
                None
            )
            .unwrap();

        i += 2;
    }

    sleep(Dur::from_secs(1));
    handler
        .update_progress("Success", "Done", "1.0", "10/10. Bye!", None, None)
        .unwrap();
    sleep(Dur::from_secs(2));

    handler.hide().unwrap();
}

Dependencies

~141MB
~2M SLoC