Struct tauri_winrt_notification::Toast
source · 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 erroniously 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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}
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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}
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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}
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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}
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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}
sourcepub fn on_activated<F: FnMut() -> Result<()> + Send + 'static>(
self,
f: F
) -> Self
pub fn on_activated<F: FnMut() -> Result<()> + Send + 'static>( self, f: F ) -> Self
Examples found in repository?
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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 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");
}
10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
Toast::new(Toast::POWERSHELL_APP_ID)
.title("Look at this flip!")
.text1("(╯°□°)╯︵ ┻━┻")
.sound(Some(Sound::SMS))
.duration(Duration::Short)
.on_activated(handle_notification_click)
.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!");
}
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");
}