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
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
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 ✓
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
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 ✓
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
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 ✓
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
Sourcepub fn duration(self, duration: Duration) -> Toast
pub fn duration(self, duration: Duration) -> Toast
Set the length of time to show the toast
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
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
The default is determined by your app id. If you are using the powershell workaround, it will be the powershell icon
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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.
This will be above the toast text and the icon.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
May be done many times. Will appear below text.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
Sourcepub fn sound(self, src: Option<Sound>) -> Toast
pub fn sound(self, src: Option<Sound>) -> Toast
Set the sound for the toast or silence it
Default is Sound::IM
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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.
Examples found in repository?
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
Sourcepub fn progress(self, progress: &Progress) -> Toast
pub fn progress(self, progress: &Progress) -> Toast
Set the progress for the toast
Examples found in repository?
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
Sourcepub fn on_activated<F>(self, f: F) -> Self
pub fn on_activated<F>(self, f: F) -> Self
Examples found in repository?
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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");
Examples found in repository?
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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");
}
Examples found in repository?
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}
Sourcepub fn show(&self) -> Result<()>
pub fn show(&self) -> Result<()>
Display the toast on the screen
Examples found in repository?
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
let toast = Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound);
toast
.show()
// silently consume errors
.expect("notification failed");
toast
.show()
// silently consume errors
.expect("notification failed");
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let duration = Duration::Short;
let sound = Some(Sound::SMS);
Toast::new(Toast::POWERSHELL_APP_ID)
.title("first toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
Toast::new(Toast::POWERSHELL_APP_ID)
.title("another toast")
.text1("line1")
.duration(duration)
.sound(sound)
.show()
// silently consume errors
.expect("notification failed");
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
Toast::new("application that needs a toast with an image")
.hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
.icon(
Path::new("c:/this/style/works/too/image.png"),
IconCrop::Circular,
"alt text",
)
.title("Lots of pictures here")
.text1("One above the text as the hero")
.text2("One to the left as an icon, and several below")
.image(Path::new("c:/photos/sun.png"), "the sun")
.image(Path::new("c:/photos/moon.png"), "the moon")
.sound(None) // will be silent
.show()
.expect("notification failed");
}
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
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(move |action| {
match action {
Some(action) => println!("You've clicked {}!", action),
None => println!("You've clicked me!"),
}
exit(0);
})
.add_button("Yes", "yes")
.add_button("No", "no")
.on_dismissed(|reason| {
match reason {
Some(ToastDismissalReason::UserCanceled) => println!("UserCanceled"),
Some(ToastDismissalReason::ApplicationHidden) => println!("ApplicationHidden"),
Some(ToastDismissalReason::TimedOut) => println!("TimedOut"),
_ => println!("Unknown"),
}
exit(0)
})
.show()
.expect("unable to send notification");
println!("Waiting 10 seconds for the notification to be clicked...");
sleep(StdDuration::from_secs(10));
println!("The notification wasn't clicked!");
}
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
fn main() {
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)
.title("File Transfer from Phone")
.text1("Transferring files to your computer...")
.progress(&progress)
.duration(Duration::Long);
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");
};
if let Ok(update_result) = toast.set_progress(&progress) {
match update_result {
NotificationUpdateResult::Succeeded => {
println!("notification updated successfully.");
}
NotificationUpdateResult::Failed => {
println!("failed to update notification")
}
NotificationUpdateResult::NotificationNotFound => {
println!("notification not found. Please ensure the notification ID and Tag are correct.");
}
_ => println!("unknown notification update result"),
}
};
}
}