use std::path::Path;
use windows::{
Data::Xml::Dom::XmlDocument, UI::Notifications::ToastNotification,
UI::Notifications::ToastNotificationManager,
};
pub use windows::core::{Error, HSTRING};
fn main() {
do_toast().expect("not sure if this is actually failable");
std::thread::sleep(std::time::Duration::from_millis(10));
}
fn do_toast() -> windows::core::Result<()> {
let toast_xml = XmlDocument::new()?;
toast_xml.LoadXml(&HSTRING::from(
format!(r#"<toast duration="long">
<visual>
<binding template="ToastGeneric">
<text id="1">title</text>
<text id="2">first line</text>
<text id="3">third line</text>
<image placement="appLogoOverride" hint-crop="circle" src="file:///c:/path_to_image_above_toast.jpg" alt="alt text" />
<image placement="Hero" src="file:///C:/path_to_image_in_toast.jpg" alt="alt text2" />
<image id="1" src="file:///{}" alt="another_image" />
</binding>
</visual>
<audio src="ms-winsoundevent:Notification.SMS" />
<!-- <audio silent="true" /> -->
</toast>"#,
quick_xml::escape::escape(&Path::new("C:\\path_to_image_in_toast.jpg").display().to_string()),
))).expect("the xml is malformed");
let toast_template = ToastNotification::CreateToastNotification(&toast_xml)?;
let toast_notifier = ToastNotificationManager::CreateToastNotifierWithId(&HSTRING::from(
"{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe",
))?;
toast_notifier.Show(&toast_template)
}