fix: can't set tray menus and icons in js (#13707)

This commit is contained in:
Tony 2025-06-26 19:42:01 +08:00 committed by GitHub
parent 3eb3162404
commit 5bbcaaec89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
tauri: "patch:bug"
---
Fix a regression that the JavaScript API can no longer set menus and icons for tray icons

4
Cargo.lock generated
View File

@ -10768,9 +10768,9 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
[[package]]
name = "wry"
version = "0.52.0"
version = "0.52.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b08db04817a654a7e3339647d9cf8b497ed9ddcd4ec7cfda5a3a220c10a3bba3"
checksum = "12a714d9ba7075aae04a6e50229d6109e3d584774b99a6a8c60de1698ca111b9"
dependencies = [
"base64 0.22.1",
"block2 0.6.0",

View File

@ -110,13 +110,15 @@ fn remove_by_id<R: Runtime>(app: AppHandle<R>, id: &str) -> crate::Result<()> {
#[command(root = "crate")]
fn set_icon<R: Runtime>(
app: AppHandle<R>,
webview: Webview<R>,
rid: ResourceId,
icon: Option<JsImage>,
) -> crate::Result<()> {
let resources_table = app.resources_table();
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
let webview_resources_table = webview.resources_table();
let icon = match icon {
Some(i) => Some(i.into_img(&resources_table)?.as_ref().clone()),
Some(i) => Some(i.into_img(&webview_resources_table)?.as_ref().clone()),
None => None,
};
tray.set_icon(icon)
@ -125,19 +127,21 @@ fn set_icon<R: Runtime>(
#[command(root = "crate")]
fn set_menu<R: Runtime>(
app: AppHandle<R>,
webview: Webview<R>,
rid: ResourceId,
menu: Option<(ResourceId, ItemKind)>,
) -> crate::Result<()> {
let resources_table = app.resources_table();
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
if let Some((rid, kind)) = menu {
let webview_resources_table = webview.resources_table();
match kind {
ItemKind::Menu => {
let menu = resources_table.get::<Menu<R>>(rid)?;
let menu = webview_resources_table.get::<Menu<R>>(rid)?;
tray.set_menu(Some((*menu).clone()))?;
}
ItemKind::Submenu => {
let submenu = resources_table.get::<Submenu<R>>(rid)?;
let submenu = webview_resources_table.get::<Submenu<R>>(rid)?;
tray.set_menu(Some((*submenu).clone()))?;
}
_ => return Err(anyhow::anyhow!("unexpected menu item kind").into()),