input/
input.rs

1use std::time::Duration;
2
3use win32_notif::{NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier, notification::{actions::{ActionButton, Input, action::ActivationType}, visual::Text}};
4// Input Example
5
6
7fn main() {
8  let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
9
10  let notification = NotificationBuilder::new()
11    .visual(
12      Text::create(0, "Enter your name")
13    )
14    .action(
15      Input::create_text_input("0", "Name", "AHQ")
16    )
17    .action(
18      ActionButton::create("Submit")
19        .with_input_id("0")
20        // Required or else it would go to file explorer
21        .with_activation_type(ActivationType::Foreground)
22    )
23    .on_activated(NotificationActivatedEventHandler::new(|_notif, data| {
24      let data = data.unwrap();
25
26      println!("{:#?}", data);
27
28      Ok(())
29    }))
30    // Notification will be gone after 5 secs
31    .with_expiry(Duration::from_secs(5))
32    // sequence: a custom defined id (never used)
33    // tag, group: Unique notification identifier
34    // Notifier, ofc you its the notifier
35    .build(0, &notifier, "01", "input")
36    .unwrap();
37
38  notification.show()
39    .unwrap();
40
41  // App should be running
42  loop {
43    std::thread::sleep(Duration::from_secs(2));
44  }
45}