1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
//! Show desktop notifications on Windows
//! # Use case
//!```rust
//! 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_audio("ms-winsoundevent:Notification.Looping.Alarm", true)
//! .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_duration(Duration::Long)
//! .set_progress("Downloading", "Active", "0.0", "0/10")
//! .set_selection(vec!["Rust 1", "Rust 2", "Rust 3"], "selection")
//! .set_input("Message", "msg")
//! .on_click("https://!www.rust-lang.org/learn/get-started")
//! .on_activated(Box::new(move |args| {
//! println!("Activated! Args: {:?}", args);
//! }))
//! .on_dismissed(Box::new(move |args| {
//! println!("Dismissed! Reason: {:?}", args);
//! }))
//! .on_failed(Box::new(move |args| {
//! println!("Failed! Reason: {:?}", 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),
//! )
//! .unwrap();
//! i += 2;
//! }
//! sleep(Dur::from_secs(1));
//! handler
//! .update_progress("Success", "Done", "1.0", "10/10. Bye!")
//! .unwrap();
//! sleep(Dur::from_secs(2));
//! handler.hide().unwrap();
//! }
//! ```
//!
//! <img style="display: inline!important" src="https://github.com/gpoddmi/windows-toast/blob/main/assets/test_windows11.png?raw=true"></img>
//!
mod toast;
mod toast_hadler;
mod toastify;
use anyhow::Result;
use std::collections::HashMap;
use toastify::Toastify;
pub use toast::Toast;
pub use toast_hadler::ToastHandler;
const TAG: &'static str = "windows_toast";
/// This can be used if you do not have a AppUserModelID.
pub const MSEDGE_APP_ID: &'static str = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge";
#[macro_export]
macro_rules! h {
($s:literal) => {
&HSTRING::from($s)
};
($s:expr) => {
&HSTRING::from($s)
};
}
#[derive(Debug)]
pub enum Crop {
Circle,
Square,
}
#[derive(Debug)]
pub enum Duration {
Long,
Short,
}
#[derive(Debug)]
pub enum ActivationType {
Protocol,
System,
Background,
Foreground,
}
#[derive(Debug)]
pub enum Dismissed {
UserCanceled,
ApplicationHidden,
TimedOut,
None,
}
impl<'a> Crop {
fn as_str(&self) -> &'a str {
match self {
Self::Circle => "circle",
Self::Square => "square",
}
}
}
impl<'a> Duration {
fn as_str(&self) -> &'a str {
match self {
Self::Short => "short",
Self::Long => "long",
}
}
}
impl<'a> ActivationType {
fn as_str(&self) -> &'a str {
match self {
Self::Protocol => "protocol",
Self::System => "system",
Self::Background => "background",
Self::Foreground => "foreground",
}
}
}