Replies: 1 comment
-
I'm facing the same issue. Currently I use the following workaround: fn create_tauri_setup(
menu: Arc<Mutex<Option<Menu<Wry>>>>,
) -> impl Fn(&mut tauri::App<Wry>) -> Result<(), Box<dyn std::error::Error>> {
move |app: &mut tauri::App<Wry>| {
let handle = app.handle();
let (_, tray_menu) = tray::create_tray(handle)?;
menu.lock().unwrap().replace(tray_menu);
Ok(())
}
}
fn create_tauri_run(
menu: Arc<Mutex<Option<Menu<Wry>>>>,
) -> impl Fn(&tauri::AppHandle<Wry>, tauri::RunEvent) {
move |app: &tauri::AppHandle<Wry>, event: tauri::RunEvent| {
#[cfg(desktop)]
match &event {
tauri::RunEvent::WindowEvent {
event: tauri::WindowEvent::CloseRequested { api, .. },
label,
..
} => {
api.prevent_close();
// Hide the window instead
let window = app
.get_webview_window(label)
.expect("Failed to get window with");
window.hide().expect("Failed to hide window");
menu.lock()
.unwrap()
.as_ref()
.unwrap()
.get("toggle")
.unwrap()
.as_menuitem_unchecked()
.set_text("Show")
.unwrap();
}
_ => (),
}
}
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let menu: Arc<Mutex<Option<Menu<Wry>>>> = Arc::new(Mutex::new(None));
tauri::Builder::default()
.setup(create_tauri_setup(menu.clone()))
.plugin(tauri_plugin_opener::init())
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(create_tauri_run(menu.clone()))
} The above example gets the menu instance from setup and saves it in an |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Tauri 2.0, after creating a tray icon menu, how do I update the menu content within the program? For example, in a system monitoring software, the values in the menu need to be updated in real-time. In Tauri 1.0, I could get the already created menu items using the following method and then update them
but in 2.0, I don't seem to see any
get_
methods for this purpose, or can I achieve this through other ways? Thank you.Beta Was this translation helpful? Give feedback.
All reactions