lunch/
lunch.rs

1use std::{path::absolute, thread, time::Duration};
2
3use win32_notif::{
4  notification::{
5    actions::{
6      action::{ActivationType, AfterActivationBehavior},
7      ActionButton,
8    },
9    audio::{Audio, Src},
10    header::{Header, HeaderActivationType},
11    visual::{Image, Placement, Text},
12    ToastDuration,
13  },
14  NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier,
15};
16
17fn main() {
18  let path = absolute("./examples/strawberry.jpg").unwrap();
19  let path = path.to_string_lossy();
20
21  let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
22
23  let notif = NotificationBuilder::new()
24    .audio(Audio::new(Src::Reminder, true, false))
25    .header(Header::new(
26      "food01",
27      "Order Food",
28      "food",
29      Some(HeaderActivationType::Foreground),
30    ))
31    .visual(
32      Image::create(20, format!("file:///{path}").as_str())
33        .with_placement(Placement::Hero)
34        .without_image_query(),
35    )
36    .visual(Text::create(1, "Would you like to order lunch today?"))
37    .action(
38      ActionButton::create("Yes")
39        .with_tooltip("Yes")
40        .with_activation_type(ActivationType::Foreground)
41        .with_after_activation_behavior(AfterActivationBehavior::PendingUpdate)
42        .with_id("yes"),
43    )
44    .action(
45      ActionButton::create("No")
46        .with_tooltip("No")
47        .with_activation_type(ActivationType::Foreground)
48        .with_after_activation_behavior(AfterActivationBehavior::Default)
49        .with_id("no"),
50    )
51    .with_duration(ToastDuration::Long)
52    .on_activated(NotificationActivatedEventHandler::new(|_a, b| {
53      println!("Triggered");
54      let args = b.unwrap();
55
56      println!("{args:?}");
57      if let Some(x) = args.button_id {
58        if &x == "yes" {}
59      }
60
61      Ok(())
62    }))
63    .build(0, &notifier, "01", "ahq")
64    .expect("Unable to build notification");
65
66  _ = notif.show();
67
68  loop {
69    thread::sleep(Duration::from_millis(200));
70  }
71}