Skip to content

Commit daeb263

Browse files
authored
chore: Add unpackaged-app example (#45)
1 parent 0c94be3 commit daeb263

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Cargo.lock

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ windows-version = "0.1"
3131
"Data_Xml_Dom",
3232
"UI_Notifications"
3333
]
34+
35+
[target.'cfg(windows)'.dev-dependencies]
36+
windows-registry = "0.5.0"

examples/unpackaged_app.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2017-2022 allenbenz <[email protected]>
2+
// Copyright 2022-2025 Tauri Programme within The Commons Conservancy
3+
// SPDX-License-Identifier: Apache-2.0
4+
// SPDX-License-Identifier: MIT
5+
6+
use std::{thread::sleep, time::Duration};
7+
8+
use tauri_winrt_notification::Toast;
9+
use windows_registry::CURRENT_USER;
10+
11+
// App's AUMID (Application User Model Id), should be unique and no longer than 129 characters.
12+
// https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast-other-apps#aumid-restrictions
13+
const APP_ID: &str = "tauri.UnpackagedAppWinRtNotificationExample";
14+
15+
// App's display name
16+
const APP_NAME: &str = "Unpackaged App";
17+
18+
fn main() -> windows_registry::Result<()> {
19+
init_registry()?;
20+
21+
Toast::new(APP_ID)
22+
.title("Notification from an unpackaged app")
23+
.scenario(tauri_winrt_notification::Scenario::Reminder)
24+
.add_button("OK", "ok")
25+
.show()
26+
.expect("unable to send notification");
27+
28+
// The notification won't appear if we clean up registry too early
29+
sleep(Duration::from_secs(3));
30+
clean_up_registry()
31+
}
32+
33+
// Create registry key for this example
34+
fn init_registry() -> windows_registry::Result<()> {
35+
let icon_path = std::env::current_dir()?.join(r"resources\tauri.png");
36+
37+
let key = CURRENT_USER.create(format!(r"SOFTWARE\Classes\AppUserModelId\{APP_ID}"))?;
38+
key.set_string("DisplayName", APP_NAME)?;
39+
key.set_string("IconBackgroundColor", "0")?;
40+
key.set_hstring("IconUri", &icon_path.as_path().into())
41+
}
42+
43+
// Remove this example from the registry
44+
fn clean_up_registry() -> windows_registry::Result<()> {
45+
CURRENT_USER.remove_tree(format!(r"SOFTWARE\Classes\AppUserModelId\{APP_ID}"))
46+
}

resources/tauri.png

574 Bytes
Loading

0 commit comments

Comments
 (0)