Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unpackaged-app example #45

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ windows-version = "0.1"
"Data_Xml_Dom",
"UI_Notifications"
]

[target.'cfg(windows)'.dev-dependencies]
windows-registry = "0.5.0"
46 changes: 46 additions & 0 deletions examples/unpackaged_app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2017-2022 allenbenz <[email protected]>
// Copyright 2022-2025 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::{thread::sleep, time::Duration};

use tauri_winrt_notification::Toast;
use windows_registry::CURRENT_USER;

// App's AUMID (Application User Model Id), should be unique and no longer than 129 characters.
// https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast-other-apps#aumid-restrictions
const APP_ID: &str = "tauri.UnpackagedAppWinRtNotificationExample";

// App's display name
const APP_NAME: &str = "Unpackaged App";

fn main() -> windows_registry::Result<()> {
init_registry()?;

Toast::new(APP_ID)
.title("Notification from an unpackaged app")
.scenario(tauri_winrt_notification::Scenario::Reminder)
.add_button("OK", "ok")
.show()
.expect("unable to send notification");

// The notification won't appear if we clean up registry too early
sleep(Duration::from_secs(3));
clean_up_registry()
}

// Create registry key for this example
fn init_registry() -> windows_registry::Result<()> {
let icon_path = std::env::current_dir()?.join(r"resources\tauri.png");

let key = CURRENT_USER.create(format!(r"SOFTWARE\Classes\AppUserModelId\{APP_ID}"))?;
key.set_string("DisplayName", APP_NAME)?;
key.set_string("IconBackgroundColor", "0")?;
key.set_hstring("IconUri", &icon_path.as_path().into())
}

// Remove this example from the registry
fn clean_up_registry() -> windows_registry::Result<()> {
CURRENT_USER.remove_tree(format!(r"SOFTWARE\Classes\AppUserModelId\{APP_ID}"))
}
Binary file added resources/tauri.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading