Skip to content

Commit 9d47532

Browse files
committed
v0.10.1
1 parent 6a44d11 commit 9d47532

File tree

9 files changed

+89
-28
lines changed

9 files changed

+89
-28
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.0"
3+
version = "0.10.1"
44
edition = "2021"
55
description = "Wrapper around Windows UWP XAML (WinRT) Notification api"
66
license = "MIT"

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,42 @@ You declare your own style, however you like as long as the XML Supports it.
1313
## Basic Usage
1414

1515
```rust
16-
use win32_notif::{Notif, NotifIcon, NotifState, NotifType, NotifFlags};
16+
use std::{path::absolute, thread::sleep, time::Duration};
17+
18+
use win32_notif::{
19+
NotificationBuilder, NotificationDataSet, notification::visual::{Image, Placement, Text, image::{AdaptiveImageAlign, ImageCrop}, text::HintStyle}, notifier::ToastsNotifier
20+
};
1721

1822
fn main() {
19-
let notifier = ToastsNotifier::new("windows app user model id").unwrap();
23+
let notifier = ToastsNotifier::new("Microsoft.Windows.Explorer").unwrap();
2024

21-
// Not correct, undergoing massive rewrite
2225
let notif = NotificationBuilder::new()
23-
.visual(Text::new(2, None, None, string!("Hello There 👋🏼")))
24-
.action(ActionButton::new(
25-
string!("Yes"),
26-
string!("yes"),
27-
ActivationType::Foreground,
28-
AfterActivationBehavior::Default,
29-
None,
30-
string!("yes"),
31-
HintButtonStyle::Success,
32-
string!("Yes"),
33-
false
34-
))
35-
.build(2, &*NOTIFIER, "tag", "group")
26+
.visual(
27+
Text::create(0, "Welcome to \"win32_notif\"!! 👋")
28+
.align_center(true)
29+
.wrap(true)
30+
.with_style(HintStyle::Title)
31+
)
32+
.visual(
33+
Text::create_binded(1, "desc")
34+
.align_center(true)
35+
.wrap(true)
36+
.with_style(HintStyle::Body)
37+
)
38+
.value("desc", "Data binding works as well {WOW}!")
39+
.build(0, &notifier, "01", "readme")
40+
.unwrap();
41+
42+
notif.show()
3643
.unwrap();
3744

38-
notif.show().unwrap();
45+
sleep(Duration::from_secs(1));
46+
47+
let data = NotificationDataSet::new().unwrap();
48+
49+
data.insert("desc", "Hello, the message is edited").unwrap();
50+
51+
notifier.update(&data, "readme", "01").unwrap();
3952
}
4053
```
4154

@@ -68,8 +81,9 @@ We've actually implemented a lot of the Notification APIs
6881
- Inputs
6982
- Selections
7083
- Visual
84+
- **_Idiomatic Rust Builder Style (with\_... methods)_**
7185

72-
and a lot of other things... 🎉
86+
**_and a lot of other things... 🎉_**
7387

7488
## Future Project Plan
7589

examples/ahq.png

1.04 MB
Loading

examples/bind.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ use win32_notif::{
66
action::{ActivationType, AfterActivationBehavior},
77
ActionButton,
88
},
9-
group::{Group, SubGroup},
109
visual::{
1110
text::{HintAlign, HintStyle},
1211
Text,
1312
},
14-
AdaptiveText, Scenario,
1513
},
1614
NotificationBuilder, ToastsNotifier,
1715
};
1816

19-
const GUID: u128 = 23885548255760334674942869530154890271u128;
17+
const _GUID: u128 = 23885548255760334674942869530154890271u128;
2018

2119
pub fn main() {
2220
let notifier = ToastsNotifier::new("com.ahqstore.app").unwrap();

examples/lunch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use win32_notif::{
1111
visual::{Image, Placement, Text},
1212
ToastDuration,
1313
},
14-
ManageNotification, NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier,
14+
NotificationActivatedEventHandler, NotificationBuilder, ToastsNotifier,
1515
};
1616

1717
fn main() {
@@ -29,7 +29,7 @@ fn main() {
2929
Some(HeaderActivationType::Foreground),
3030
))
3131
.visual(
32-
Image::create(20, format!("file:///{path}"))
32+
Image::create(20, format!("file:///{path}").as_str())
3333
.with_placement(Placement::Hero)
3434
.without_image_query(),
3535
)

examples/readme.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::{path::absolute, thread::sleep, time::Duration};
2+
3+
use win32_notif::{
4+
NotificationBuilder, NotificationDataSet, notification::visual::{Image, Placement, Text, image::{AdaptiveImageAlign, ImageCrop}, text::HintStyle}, notifier::ToastsNotifier
5+
};
6+
7+
fn 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+
.align_center(true)
17+
.wrap(true)
18+
.with_style(HintStyle::Title)
19+
)
20+
.visual(
21+
Text::create_binded(1, "desc")
22+
.align_center(true)
23+
.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, &notifier, "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+
}

src/structs/notification/widgets/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ToXML for Header {
3131
fn to_xml(&self) -> String {
3232
format!(
3333
r#"
34-
<header title=\"{}\" arguments=\"{}\" id=\"{}\" activationType="{}" />
34+
<header title="{}" arguments="{}" id="{}" activationType="{}" />
3535
"#,
3636
self.title, self.arguments, self.id, self.activation_type
3737
)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use quick_xml::escape::escape;
2+
13
use crate::{notification::ToastVisualableXML, ToXML};
24

35
use super::{TextOrImageElement, VisualElement};
@@ -98,10 +100,10 @@ impl Image {
98100
/// - `file:///path/to/file`
99101
///
100102
/// If none of the above is provided, the `src` will be set to `file:///path/to/file`
101-
pub fn create<T: Into<String>>(id: u64, src: T) -> Self {
103+
pub fn create(id: u64, src: &str) -> Self {
102104
Self::new(
103105
id,
104-
src.into(),
106+
escape(src).into(),
105107
None,
106108
false,
107109
Placement::None,

0 commit comments

Comments
 (0)