pub struct ToastsNotifier { /* private fields */ }Implementations§
Source§impl ToastsNotifier
impl ToastsNotifier
Sourcepub fn new<T: Into<String>>(app_id: T) -> Result<Self, NotifError>
pub fn new<T: Into<String>>(app_id: T) -> Result<Self, NotifError>
Examples found in repository?
examples/expires.rs (line 13)
12fn main() {
13 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
14
15 let notif = NotificationBuilder::new()
16 .audio(Audio::new(Src::Reminder, true, false))
17 .visual(Text::create(
18 1,
19 "This will automatically vanish (exp: 10secs)!",
20 ))
21 .with_duration(ToastDuration::Short)
22 .with_expiry(Duration::from_secs(10))
23 .build(0, ¬ifier, "01", "ahq")
24 .expect("Unable to build notification");
25
26 _ = notif.show();
27}More examples
examples/simple.rs (line 15)
14pub fn main() {
15 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
16
17 let notification = NotificationBuilder::new()
18 .with_scenario(Scenario::IncomingCall)
19 .with_use_button_style(true)
20 .visual(
21 Group::new()
22 .with_subgroup(
23 SubGroup::new().with_visual(Text::create(0, "Hello World").with_style(HintStyle::Title)),
24 )
25 .with_subgroup(
26 SubGroup::new().with_visual(
27 Text::create(0, "Hello World x2")
28 .with_style(HintStyle::Header)
29 .with_align(HintAlign::Right),
30 ),
31 ),
32 )
33 .action(
34 ActionButton::create("Answer")
35 .with_tooltip("Answer")
36 .with_id("answer"),
37 )
38 .build(1, ¬ifier, "a", "ahq")
39 .expect("Error");
40
41 notification.show().expect("Not Sent");
42}examples/downloading.rs (line 12)
11pub fn main() {
12 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
13
14 let notification = NotificationBuilder::new()
15 .with_scenario(Scenario::IncomingCall)
16 .with_use_button_style(true)
17 .visual(
18 Text::create_binded(1, "status")
19 )
20 .visual(
21 Progress::create(AdaptiveText::BindTo("typeof"), ProgressValue::BindTo("value"))
22 )
23 .value("status", "AHQ Store")
24 .value("typeof", "Downloading...")
25 .value("value", "indeterminate")
26 .build(1, ¬ifier, "a", "ahq")
27 .expect("Error");
28
29 notification.show().expect("Not Sent");
30
31 let data = NotificationDataSet::new().unwrap();
32 for perc in 1..=100 {
33 data.insert("value", format!("{}", perc as f32 / 100.0).as_str()).unwrap();
34
35 _ = notifier.update(&data, "ahq", "a");
36
37 sleep(Duration::from_millis(100));
38 }
39}examples/bind.rs (line 20)
19pub fn main() {
20 let notifier = ToastsNotifier::new("com.ahqstore.app").unwrap();
21
22 let mut argv = args();
23
24 argv.next();
25 argv.next();
26 argv.next();
27
28 if let Some(_) = argv.next() {
29 let notification = NotificationBuilder::new()
30 .with_use_button_style(true)
31 .visual(
32 Text::create_binded(0, "hi")
33 .with_style(HintStyle::Header)
34 .with_align(HintAlign::Right),
35 )
36 .value("hi", "This is binded string")
37 .action(
38 ActionButton::create("test")
39 .with_tooltip("Answer")
40 .with_id("answer")
41 .with_activation_type(ActivationType::Background)
42 .with_after_activation_behavior(AfterActivationBehavior::PendingUpdate),
43 )
44 .value("test", "Hello World")
45 .build(1, ¬ifier, "a", "ahq")
46 .expect("Error");
47
48 notification.show().expect("Not Sent");
49 }
50
51 loop {
52 sleep(Duration::from_millis(10));
53 }
54}examples/input.rs (line 8)
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, ¬ifier, "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}examples/readme.rs (line 11)
7fn main() {
8 let path = absolute("./examples/ahq.png").unwrap();
9 let path = path.to_string_lossy();
10
11 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
12
13 let notif = NotificationBuilder::new()
14 .visual(
15 Text::create(0, "Welcome to \"win32_notif\"!! 👋")
16 .with_align_center(true)
17 .with_wrap(true)
18 .with_style(HintStyle::Title)
19 )
20 .visual(
21 Text::create_binded(1, "desc")
22 .with_align_center(true)
23 .with_wrap(true)
24 .with_style(HintStyle::Body)
25 )
26 .visual(
27 Image::create(2, format!("file:///{path}").as_str())
28 .with_align(AdaptiveImageAlign::Default)
29 .with_alt("AHQ Logo")
30 .with_crop(ImageCrop::Circle)
31 .with_placement(Placement::AppLogoOverride)
32 )
33 .value("desc", "Data binding works as well {WOW}!")
34 .build(0, ¬ifier, "01", "readme")
35 .unwrap();
36
37 notif.show()
38 .unwrap();
39
40 sleep(Duration::from_secs(1));
41
42 let data = NotificationDataSet::new().unwrap();
43
44 data.insert("desc", "Hello, the message is edited").unwrap();
45
46 notifier.update(&data, "readme", "01").unwrap();
47}Additional examples can be found in:
pub unsafe fn new_with_guid<T: Into<String>>( app_id: T, guid: Option<u128>, ) -> Result<Self, NotifError>
Available on crate feature
experimental only.pub fn manager(&self) -> Result<ToastsManager, NotifError>
Sourcepub fn update(
&self,
data: &NotificationDataSet,
group: &str,
tag: &str,
) -> Result<NotificationUpdateResult, NotifError>
pub fn update( &self, data: &NotificationDataSet, group: &str, tag: &str, ) -> Result<NotificationUpdateResult, NotifError>
Examples found in repository?
examples/downloading.rs (line 35)
11pub fn main() {
12 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
13
14 let notification = NotificationBuilder::new()
15 .with_scenario(Scenario::IncomingCall)
16 .with_use_button_style(true)
17 .visual(
18 Text::create_binded(1, "status")
19 )
20 .visual(
21 Progress::create(AdaptiveText::BindTo("typeof"), ProgressValue::BindTo("value"))
22 )
23 .value("status", "AHQ Store")
24 .value("typeof", "Downloading...")
25 .value("value", "indeterminate")
26 .build(1, ¬ifier, "a", "ahq")
27 .expect("Error");
28
29 notification.show().expect("Not Sent");
30
31 let data = NotificationDataSet::new().unwrap();
32 for perc in 1..=100 {
33 data.insert("value", format!("{}", perc as f32 / 100.0).as_str()).unwrap();
34
35 _ = notifier.update(&data, "ahq", "a");
36
37 sleep(Duration::from_millis(100));
38 }
39}More examples
examples/readme.rs (line 46)
7fn main() {
8 let path = absolute("./examples/ahq.png").unwrap();
9 let path = path.to_string_lossy();
10
11 let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
12
13 let notif = NotificationBuilder::new()
14 .visual(
15 Text::create(0, "Welcome to \"win32_notif\"!! 👋")
16 .with_align_center(true)
17 .with_wrap(true)
18 .with_style(HintStyle::Title)
19 )
20 .visual(
21 Text::create_binded(1, "desc")
22 .with_align_center(true)
23 .with_wrap(true)
24 .with_style(HintStyle::Body)
25 )
26 .visual(
27 Image::create(2, format!("file:///{path}").as_str())
28 .with_align(AdaptiveImageAlign::Default)
29 .with_alt("AHQ Logo")
30 .with_crop(ImageCrop::Circle)
31 .with_placement(Placement::AppLogoOverride)
32 )
33 .value("desc", "Data binding works as well {WOW}!")
34 .build(0, ¬ifier, "01", "readme")
35 .unwrap();
36
37 notif.show()
38 .unwrap();
39
40 sleep(Duration::from_secs(1));
41
42 let data = NotificationDataSet::new().unwrap();
43
44 data.insert("desc", "Hello, the message is edited").unwrap();
45
46 notifier.update(&data, "readme", "01").unwrap();
47}pub unsafe fn as_raw(&self) -> &ToastNotifier
Auto Trait Implementations§
impl Freeze for ToastsNotifier
impl RefUnwindSafe for ToastsNotifier
impl Send for ToastsNotifier
impl Sync for ToastsNotifier
impl Unpin for ToastsNotifier
impl UnwindSafe for ToastsNotifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more