Skip to content

Commit e2b80b2

Browse files
committed
v0.10.2 - more examples
1 parent 9d47532 commit e2b80b2

File tree

11 files changed

+164
-15
lines changed

11 files changed

+164
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "win32_notif"
3-
version = "0.10.1"
3+
version = "0.10.2"
44
edition = "2021"
55
description = "Wrapper around Windows UWP XAML (WinRT) Notification api"
66
license = "MIT"

examples/downloading.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::{thread::sleep, time::Duration};
2+
3+
use win32_notif::{
4+
NotificationBuilder, NotificationDataSet, ToastsNotifier, notification::{
5+
AdaptiveText, Scenario, visual::{
6+
Progress, Text, progress::ProgressValue
7+
}
8+
}
9+
};
10+
11+
pub 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, &notifier, "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/input.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::time::Duration;
2+
3+
use win32_notif::{NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier, notification::{actions::{ActionButton, Input, action::ActivationType}, visual::Text}};
4+
// Input Example
5+
6+
7+
fn 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+
}

examples/readme.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ fn main() {
1313
let notif = NotificationBuilder::new()
1414
.visual(
1515
Text::create(0, "Welcome to \"win32_notif\"!! 👋")
16-
.align_center(true)
17-
.wrap(true)
16+
.with_align_center(true)
17+
.with_wrap(true)
1818
.with_style(HintStyle::Title)
1919
)
2020
.visual(
2121
Text::create_binded(1, "desc")
22-
.align_center(true)
23-
.wrap(true)
22+
.with_align_center(true)
23+
.with_wrap(true)
2424
.with_style(HintStyle::Body)
2525
)
2626
.visual(

examples/select.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::time::Duration;
2+
3+
use win32_notif::{NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier, notification::{actions::{ActionButton, Input, action::ActivationType, input::Selection}, visual::Text}};
4+
// Input Selection Example
5+
6+
7+
fn 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_selection_input(
16+
"0",
17+
"Name",
18+
"AHQ",
19+
vec![
20+
Selection::new("1", "AHQ Novel"),
21+
Selection::new("2", "AHQ Soft"),
22+
Selection::new("3", "Wings of Fire")
23+
]
24+
)
25+
)
26+
.action(
27+
ActionButton::create("Submit")
28+
.with_input_id("0")
29+
// Required or else it would go to file explorer
30+
.with_activation_type(ActivationType::Foreground)
31+
)
32+
.on_activated(NotificationActivatedEventHandler::new(|_notif, data| {
33+
let data = data.unwrap();
34+
35+
println!("{:#?}", data);
36+
37+
Ok(())
38+
}))
39+
// Notification will be gone after 5 secs
40+
.with_expiry(Duration::from_secs(5))
41+
// sequence: a custom defined id (never used)
42+
// tag, group: Unique notification identifier
43+
// Notifier, ofc you its the notifier
44+
.build(0, &notifier, "01", "input")
45+
.unwrap();
46+
47+
notification.show()
48+
.unwrap();
49+
50+
// App should be running
51+
loop {
52+
std::thread::sleep(Duration::from_secs(2));
53+
}
54+
}

src/structs/notification/widgets/group/subgroup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl ToXML for SubGroup {
7070
.collect::<Vec<_>>()
7171
.join("\n");
7272

73+
// XML Formatting
7374
format!(
7475
"
7576
<subgroup {wt} {stack}>

src/structs/notification/widgets/visual/image.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ impl Image {
112112
)
113113
}
114114

115-
/// The `src` should be the either of the following following
116-
/// - `https://url or http://url`
117-
/// - `file:///path/to/file`
115+
/// The `src` should be in the form of `file:///path/to/file`
116+
///
117+
/// Technically `https://` and `http://` too should work according to the
118+
/// C# Windows UWP Notifications, but we were not able to replicate that.
119+
///
120+
/// We still allow setting http or https including others of windows C# API
118121
///
119122
/// If none of the above is provided, the `src` will be set to `file:///path/to/file`
120123
pub fn new(

src/structs/notification/widgets/visual/progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Progress {
5050
self
5151
}
5252

53-
pub fn override_value_string(mut self, value: AdaptiveText) -> Self {
53+
pub fn with_override_value(mut self, value: AdaptiveText) -> Self {
5454
self.value_string_override = Some(value.to_string());
5555
self
5656
}

src/structs/notification/widgets/visual/text.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,27 @@ impl Text {
130130
}
131131

132132
/// Only for IncomingCall scenarios
133-
pub fn align_center(mut self, center: bool) -> Self {
134-
self.callScenarioCenterAlign = center;
133+
pub fn with_align_center(mut self, shall_it_align_center: bool) -> Self {
134+
self.callScenarioCenterAlign = shall_it_align_center;
135135
self
136136
}
137137

138-
pub fn wrap(mut self, wrap: bool) -> Self {
138+
pub fn with_wrap(mut self, wrap: bool) -> Self {
139139
self.wrap = wrap;
140140
self
141141
}
142142

143-
pub fn max_lines(mut self, max_lines: u32) -> Self {
143+
#[deprecated(since="0.10.2", note="Use [Self::with_wrap] instead")]
144+
pub fn wrap(self, wrap: bool) -> Self {
145+
self.with_wrap(wrap)
146+
}
147+
148+
pub fn with_max_lines(mut self, max_lines: u32) -> Self {
144149
self.maxLines = max_lines;
145150
self
146151
}
147152

148-
pub fn min_lines(mut self, min_lines: u32) -> Self {
153+
pub fn with_min_lines(mut self, min_lines: u32) -> Self {
149154
self.minLines = min_lines;
150155
self
151156
}

0 commit comments

Comments
 (0)