pub struct Toast { /* private fields */ }Implementations§
Source§impl Toast
impl Toast
Sourcepub const POWERSHELL_APP_ID: &'static str = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\
\\WindowsPowerShell\\v1.0\\powershell.exe"
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.
Sourcepub fn new(app_id: &str) -> Toast
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
Sourcepub fn title(self, content: &str) -> Toast
pub fn title(self, content: &str) -> Toast
Sets the title of the toast.
Will be white. Supports Unicode ✓
Sourcepub fn text1(self, content: &str) -> Toast
pub fn text1(self, content: &str) -> Toast
Add/Sets the first line of text below title.
Will be grey. Supports Unicode ✓
Sourcepub fn text2(self, content: &str) -> Toast
pub fn text2(self, content: &str) -> Toast
Add/Sets the second line of text below title.
Will be grey. Supports Unicode ✓
Sourcepub fn scenario(self, scenario: Scenario) -> Toast
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.
Sourcepub fn icon(self, source: &Path, crop: IconCrop, alt_text: &str) -> Toast
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
Sourcepub fn hero(self, source: &Path, alt_text: &str) -> Toast
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.
Sourcepub fn image(self, source: &Path, alt_text: &str) -> Toast
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.
Sourcepub fn sound(self, src: Option<Sound>) -> Toast
pub fn sound(self, src: Option<Sound>) -> Toast
Set the sound for the toast or None to silence it.
Default is Some(Sound::Default).
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.
pub fn on_activated<F>(self, f: F) -> Self
Sourcepub fn on_dismissed<F>(self, f: F) -> Self
pub fn on_dismissed<F>(self, f: F) -> Self
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");Sourcepub fn set_progress(
&self,
progress: &Progress,
) -> Result<NotificationUpdateResult>
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");
}