1
2
3
4
5
6
7
8
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
use crate::{h, Result, TAG};
use windows::{
core::HSTRING,
UI::Notifications::{
NotificationData, ToastNotification, ToastNotificationManager, ToastNotifier,
},
};
pub struct ToastHandler<'a> {
id: &'a str,
toast: ToastNotification,
manager: ToastNotifier,
}
impl<'a> ToastHandler<'a> {
pub fn new(id: &'a str, toast: ToastNotification, manager: ToastNotifier) -> Self {
Self { id, toast, manager }
}
pub fn hide(&self) -> Result<()> {
self.manager.Hide(&self.toast)?;
Ok(())
}
pub fn update_progress(
&self,
title: &str,
status: &str,
value: &str,
value_string: &str,
) -> Result<()> {
let manager = ToastNotificationManager::CreateToastNotifierWithId(h!(self.id))?;
let notify_data = NotificationData::new()?;
let values = notify_data.Values()?;
for (key, value) in [
("title", title),
("status", status),
("value", value),
("value_string", value_string),
] {
values.Insert(h!(key), h!(value))?;
}
manager.UpdateWithTagAndGroup(¬ify_data, h!(TAG), h!(TAG))?;
Ok(())
}
}