Skip to content

Commit 5bbcaae

Browse files
fix: can't set tray menus and icons in js (#13707)
1 parent 3eb3162 commit 5bbcaae

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: "patch:bug"
3+
---
4+
5+
Fix a regression that the JavaScript API can no longer set menus and icons for tray icons

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/tray/plugin.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ fn remove_by_id<R: Runtime>(app: AppHandle<R>, id: &str) -> crate::Result<()> {
110110
#[command(root = "crate")]
111111
fn set_icon<R: Runtime>(
112112
app: AppHandle<R>,
113+
webview: Webview<R>,
113114
rid: ResourceId,
114115
icon: Option<JsImage>,
115116
) -> crate::Result<()> {
116117
let resources_table = app.resources_table();
117118
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
119+
let webview_resources_table = webview.resources_table();
118120
let icon = match icon {
119-
Some(i) => Some(i.into_img(&resources_table)?.as_ref().clone()),
121+
Some(i) => Some(i.into_img(&webview_resources_table)?.as_ref().clone()),
120122
None => None,
121123
};
122124
tray.set_icon(icon)
@@ -125,19 +127,21 @@ fn set_icon<R: Runtime>(
125127
#[command(root = "crate")]
126128
fn set_menu<R: Runtime>(
127129
app: AppHandle<R>,
130+
webview: Webview<R>,
128131
rid: ResourceId,
129132
menu: Option<(ResourceId, ItemKind)>,
130133
) -> crate::Result<()> {
131134
let resources_table = app.resources_table();
132135
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
133136
if let Some((rid, kind)) = menu {
137+
let webview_resources_table = webview.resources_table();
134138
match kind {
135139
ItemKind::Menu => {
136-
let menu = resources_table.get::<Menu<R>>(rid)?;
140+
let menu = webview_resources_table.get::<Menu<R>>(rid)?;
137141
tray.set_menu(Some((*menu).clone()))?;
138142
}
139143
ItemKind::Submenu => {
140-
let submenu = resources_table.get::<Submenu<R>>(rid)?;
144+
let submenu = webview_resources_table.get::<Submenu<R>>(rid)?;
141145
tray.set_menu(Some((*submenu).clone()))?;
142146
}
143147
_ => return Err(anyhow::anyhow!("unexpected menu item kind").into()),

0 commit comments

Comments
 (0)