mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 15:56:51 +00:00
fix: can't set tray menus and icons in js (#13707)
This commit is contained in:
parent
3eb3162404
commit
5bbcaaec89
5
.changes/fix-js-set-icon-tray-menu.md
Normal file
5
.changes/fix-js-set-icon-tray-menu.md
Normal 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
4
Cargo.lock
generated
@ -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",
|
||||
|
||||
@ -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()),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user