Skip to content

Commit

Permalink
feat: set modules menu during all initializations paths
Browse files Browse the repository at this point in the history
  • Loading branch information
brayo-pip committed Jul 11, 2024
1 parent 1bb120d commit 012e946
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src-tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct ManagerState {
pub modules_running: BTreeMap<String, bool>,
pub modules_in_path: BTreeSet<String>,
pub modules_pid: HashMap<String, u32>,
pub modules_menu_set: bool,
}

impl ManagerState {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -182,6 +185,15 @@ pub fn start_manager() -> Arc<Mutex<ManagerState>> {
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);
Expand Down

0 comments on commit 012e946

Please sign in to comment.