Skip to main content

Toast

Struct Toast 

Source
pub struct Toast { /* private fields */ }

Implementations§

Source§

impl Toast

Source

pub const POWERSHELL_APP_ID: &'static str = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\ \\WindowsPowerShell\\v1.0\\powershell.exe"

This can be used if you do not have a AppUserModelID.

However, the toast will erroneously report its origin as powershell.

Source

pub fn new(app_id: &str) -> Toast

Constructor for the toast builder.

app_id is the running application’s AppUserModelID.

If the program you are using this in was not installed, use Toast::POWERSHELL_APP_ID for now

Source

pub fn title(self, content: &str) -> Toast

Sets the title of the toast.

Will be white. Supports Unicode ✓

Source

pub fn text1(self, content: &str) -> Toast

Add/Sets the first line of text below title.

Will be grey. Supports Unicode ✓

Source

pub fn text2(self, content: &str) -> Toast

Add/Sets the second line of text below title.

Will be grey. Supports Unicode ✓

Source

pub fn duration(self, duration: Duration) -> Toast

Set the length of time to show the toast

Source

pub fn scenario(self, scenario: Scenario) -> Toast

Set the scenario of the toast

The system keeps the notification on screen until the user acts upon/dismisses it. The system also plays the suitable notification sound as well.

Source

pub fn icon(self, source: &Path, crop: IconCrop, alt_text: &str) -> Toast

Set the icon shown in the upper left of the toast

Source paths must be absolute and not contain a UNC prefix.

The default is determined by your app id. If you are using the powershell workaround, it will be the powershell icon

Source

pub fn hero(self, source: &Path, alt_text: &str) -> Toast

Add/Set a Hero image for the toast.

Source paths must be absolute and not contain a UNC prefix.

This will be above the toast text and the icon.

Source

pub fn image(self, source: &Path, alt_text: &str) -> Toast

Add an image to the toast.

Source paths must be absolute and not contain a UNC prefix.

May be done many times. Will appear below text.

Source

pub fn sound(self, src: Option<Sound>) -> Toast

Set the sound for the toast or None to silence it.

Default is Some(Sound::Default).

Source

pub fn add_button(self, content: &str, action: &str) -> Toast

Adds a button to the notification content is the text of the button. action will be sent as an argument on_activated when the button is clicked.

Source

pub fn progress(self, progress: &Progress) -> Toast

Set the progress for the toast

Source

pub fn on_activated<F>(self, f: F) -> Self
where F: Fn(Option<String>) -> Result<()> + Send + 'static,

Source

pub fn on_dismissed<F>(self, f: F) -> Self
where F: Fn(Option<ToastDismissalReason>) -> Result<()> + Send + 'static,

Set the function to be called when the toast is dismissed f will be called with the reason the toast was dismissed. If the toast was dismissed by the user, the reason will be ToastDismissalReason::UserCanceled. If the toast was dismissed by the application, the reason will be ToastDismissalReason::ApplicationHidden. If the toast was dismissed because it timed out, the reason will be ToastDismissalReason::TimedOut. If the reason is unknown, the reason will be None.

§Example
use tauri_winrt_notification::{Toast, ToastDismissalReason};

let toast = Toast::new(Toast::POWERSHELL_APP_ID);
toast.on_dismissed(|reason| {
    match reason {
        Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
        Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
        Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
        _ => println!("Unknown"),
    }
    Ok(())
}).show().expect("notification failed");
Source

pub fn set_progress( &self, progress: &Progress, ) -> Result<NotificationUpdateResult>

Update progress bar title, status, progress value, progress value string If the notification update is successful, the reason will be NotificationUpdateResult::Succeeded. If the update notification fails, the reason will be NotificationUpdateResult::Failed. If no notification is found, the reason will be NotificationUpdateResult::NotificationNotFound.

§Example
use std::{thread::sleep, time::Duration as StdDuration};
use tauri_winrt_notification::{Toast, Progress};

let mut progress = Progress {
    tag: "my_tag".to_string(),
    title: "video.mp4".to_string(),
    status: "Transferring files...".to_string(),
    value: 0.0,
    value_string: "0/1000 MB".to_string(),
};

let toast = Toast::new(Toast::POWERSHELL_APP_ID).progress(&progress);
toast.show().expect("notification failed");

for i in 1..=10 {
    sleep(StdDuration::from_secs(1));

    progress.value = i as f32 / 10.0;
    progress.value_string = format!("{}/1000 MB", i * 100);

    if i == 10 {
        progress.status = String::from("Completed!");
    };

    toast.set_progress(&progress).expect("failed to set notification progress");
}
Source

pub fn show(&self) -> Result<()>

Display the toast on the screen

Auto Trait Implementations§

§

impl !Send for Toast

§

impl !Sync for Toast

§

impl Freeze for Toast

§

impl RefUnwindSafe for Toast

§

impl Unpin for Toast

§

impl UnsafeUnpin for Toast

§

impl UnwindSafe for Toast

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.