Fail cleanly instead of panicking if the tray icon is ever missing
build_tray() propagates every fallible step through `?` -- menu items, the menu itself, the tray builder -- except the icon lookup, which called .unwrap() on default_window_icon(). The icon is configured in tauri.conf.json today, so this never fires in practice, but it was the one spot in an otherwise all-`?` function where a missing precondition would panic the whole app during .setup() instead of failing through the same tauri::Error path as everything around it. Found while auditing every non-test .unwrap() in the codebase for anything that could panic on a normal condition rather than an already-exceptional one (a poisoned mutex, a compile-time-constant CString). This was the only site that qualified.
This commit is contained in:
parent
1faeef15fc
commit
07b48a66fd
1 changed files with 9 additions and 1 deletions
|
|
@ -400,8 +400,16 @@ fn build_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||||
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||||
let menu = Menu::with_items(app, &[&show, &hide, &quit])?;
|
let menu = Menu::with_items(app, &[&show, &hide, &quit])?;
|
||||||
|
|
||||||
|
// Configured in tauri.conf.json, so this is always `Some` today — but a
|
||||||
|
// missing icon should fail setup cleanly through the existing `?` chain
|
||||||
|
// rather than panic and take the whole app down with it.
|
||||||
|
let icon = app
|
||||||
|
.default_window_icon()
|
||||||
|
.cloned()
|
||||||
|
.ok_or_else(|| tauri::Error::AssetNotFound("default window icon".into()))?;
|
||||||
|
|
||||||
TrayIconBuilder::with_id("textream")
|
TrayIconBuilder::with_id("textream")
|
||||||
.icon(app.default_window_icon().unwrap().clone())
|
.icon(icon)
|
||||||
.tooltip("Textream")
|
.tooltip("Textream")
|
||||||
.menu(&menu)
|
.menu(&menu)
|
||||||
// The menu still opens on right-click regardless of this setting; it
|
// The menu still opens on right-click regardless of this setting; it
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue