From 012e9469b2bcf98568acaa21248e8ba129c203b7 Mon Sep 17 00:00:00 2001 From: Brayo Date: Thu, 11 Jul 2024 14:03:36 +0300 Subject: [PATCH] feat: set modules menu during all initializations paths --- src-tauri/src/manager.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src-tauri/src/manager.rs b/src-tauri/src/manager.rs index c8b9632..344a09f 100644 --- a/src-tauri/src/manager.rs +++ b/src-tauri/src/manager.rs @@ -46,6 +46,7 @@ pub struct ManagerState { pub modules_running: BTreeMap, pub modules_in_path: BTreeSet, pub modules_pid: HashMap, + pub modules_menu_set: bool, } impl ManagerState { @@ -55,6 +56,7 @@ impl ManagerState { modules_running: BTreeMap::new(), modules_in_path: get_modules_in_path(), modules_pid: HashMap::new(), + modules_menu_set: false, } } fn started_module(&mut self, name: &str, pid: u32) { @@ -113,6 +115,7 @@ impl ManagerState { let app = get_app_handle().lock().expect("failed to get app handle"); let tray_handle = app.tray_handle(); tray_handle.set_menu(menu).expect("failed to set tray menu"); + self.modules_menu_set = true; } pub fn start_module(&self, name: &str) { if !self.is_module_running(name) { @@ -182,6 +185,15 @@ pub fn start_manager() -> Arc> { state.lock().unwrap().start_module(module); } + // populate the tray menu if not yet already done + let modules_menu_set = state.lock().unwrap().modules_menu_set; + if !modules_menu_set { + let state_clone = Arc::clone(&state); + thread::spawn(move || { + state_clone.lock().unwrap().update_tray_menu(); + }); + } + let state_clone = Arc::clone(&state); thread::spawn(move || { handle(rx, state_clone);