Expand description
A mostly usable binding to the Windows ToastNotification API.
§Basic Example
use winrt_toast_reborn::{Toast, Text, Header, ToastManager};
use winrt_toast_reborn::content::text::TextPlacement;
let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
let mut toast = Toast::new();
toast
.text1("Title")
.text2(Text::new("Body"))
.text3(
Text::new("Via SMS")
.with_placement(TextPlacement::Attribution)
);
manager.show(&toast).expect("Failed to show toast");§Rich Toast with Images and Actions
use winrt_toast_reborn::{Toast, Text, Image, Action, ToastManager, ToastDuration};
use winrt_toast_reborn::content::image::{ImagePlacement, ImageHintCrop};
use std::path::Path;
fn main() -> winrt_toast_reborn::Result<()> {
let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
// Create images
let hero_image = Image::new_local(Path::new("hero.jpg"))?
.with_placement(ImagePlacement::Hero);
let logo_image = Image::new_local(Path::new("logo.png"))?
.with_placement(ImagePlacement::AppLogoOverride)
.with_hint_crop(ImageHintCrop::Circle);
let mut toast = Toast::new();
toast
.text1("Meeting Reminder")
.text2("Team standup starts in 5 minutes")
.text3("Conference Room A")
.image(1, hero_image)
.image(2, logo_image)
.duration(ToastDuration::Long)
.action(Action::new("Join", "join_meeting", "meeting_id=123"))
.action(Action::new("Snooze", "snooze", ""));
manager.show(&toast)?;
Ok(())
}§Interactive Toast with Input Fields
use winrt_toast_reborn::{Toast, Input, Selection, Action, ToastManager};
use winrt_toast_reborn::content::input::InputType;
fn main() -> winrt_toast_reborn::Result<()> {
let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
let mut toast = Toast::new();
toast
.text1("Quick Reply")
.text2("Choose your response:")
.input(
Input::new("response", InputType::Selection)
.with_title("Select option")
.with_default_input("yes")
)
.selection(Selection::new("yes", "Yes"))
.selection(Selection::new("no", "No"))
.selection(Selection::new("maybe", "Maybe later"))
.action(Action::new("Send", "send_response", "").with_input_id("response"));
manager.show(&toast)?;
Ok(())
}Re-exports§
pub use content::action::Action;pub use content::audio::Audio;pub use content::header::Header;pub use content::image::Image;pub use content::input::Input;pub use content::input::Selection;pub use content::text::Text;pub use url;
Modules§
- content
- Contents in a toast notification.
Structs§
- Activated
Action - Represents an action that was activated by the user.
This is passed to the
on_activatedcallback. - Toast
- Represents a Windows toast.
- Toast
Dismissed - Represents the dismissal of a toast notification.
This is passed to the
on_dismissedcallback. - Toast
Failed - Represents an error trying to show a toast notification.
This is passed to the
on_failedcallback. - Toast
Manager - An interface that provides access to the toast notification manager.
Enums§
- Dismissal
Reason - Specifies the reason that a toast notification is no longer being shown
- Scenario
- The scenario your toast is used for, like an alarm or reminder.
- Toast
Duration - The amount of time the toast should display
- WinToast
Error - The error type used in this crate.
Functions§
- register
- Register the application to Windows registry.
- unregister
- Unregister the application from Windows registry.
Type Aliases§
- Result
- The result type used in this crate.