Skip to content

Commit 7c24f61

Browse files
author
Mohammod Al Amin Ashik
committed
fix: Auto-update system tray menu when spaces change
- Remove dead_code attribute from update_tray_spaces function - Add AppHandle parameter to create_space and delete_space commands - Call update_tray_spaces after space creation, deletion, and activation - Add refresh_tray_menu command for manual tray refresh The system tray now automatically reflects: - New spaces when created - Space removal when deleted - Active space indicator when switching spaces Fixes issue where creating a new space didn't appear in system tray.
1 parent c8c815c commit 7c24f61

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

apps/desktop/src-tauri/src/commands/space.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use uuid::Uuid;
1212

1313
use crate::commands::gateway::GatewayAppState;
1414
use crate::state::AppState;
15+
use crate::tray;
1516

1617
/// Space change event payload
1718
#[derive(Debug, Clone, Serialize)]
@@ -76,6 +77,7 @@ const DEFAULT_SPACE_CONFIG: &str = r#"{
7677
pub async fn create_space(
7778
name: String,
7879
icon: Option<String>,
80+
app: AppHandle,
7981
state: State<'_, AppState>,
8082
gateway_state: State<'_, Arc<RwLock<GatewayAppState>>>,
8183
) -> Result<Space, String> {
@@ -109,13 +111,19 @@ pub async fn create_space(
109111
});
110112
}
111113

114+
// Update system tray menu
115+
if let Err(e) = tray::update_tray_spaces(&app, &state).await {
116+
warn!("Failed to update tray menu: {}", e);
117+
}
118+
112119
Ok(space)
113120
}
114121

115122
/// Delete a space.
116123
#[tauri::command]
117124
pub async fn delete_space(
118125
id: String,
126+
app: AppHandle,
119127
state: State<'_, AppState>,
120128
gateway_state: State<'_, Arc<RwLock<GatewayAppState>>>,
121129
) -> Result<(), String> {
@@ -134,6 +142,11 @@ pub async fn delete_space(
134142
gw.emit_domain_event(mcpmux_core::DomainEvent::SpaceDeleted { space_id: uuid });
135143
}
136144

145+
// Update system tray menu
146+
if let Err(e) = tray::update_tray_spaces(&app, &state).await {
147+
warn!("Failed to update tray menu: {}", e);
148+
}
149+
137150
Ok(())
138151
}
139152

@@ -242,6 +255,11 @@ pub async fn set_active_space<R: tauri::Runtime>(
242255
// will be emitted by the gateway when they make their next request
243256
// and the SpaceResolver returns the new active space.
244257

258+
// Update system tray menu to reflect new active space
259+
if let Err(e) = tray::update_tray_spaces(&app_handle, &state).await {
260+
warn!("Failed to update tray menu: {}", e);
261+
}
262+
245263
Ok(())
246264
}
247265

@@ -372,3 +390,11 @@ pub async fn remove_server_from_config(
372390

373391
Ok(false)
374392
}
393+
394+
/// Refresh the system tray menu to reflect current spaces
395+
#[tauri::command]
396+
pub async fn refresh_tray_menu(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
397+
tray::update_tray_spaces(&app, &state)
398+
.await
399+
.map_err(|e| format!("Failed to update tray menu: {}", e))
400+
}

apps/desktop/src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ pub fn run() {
600600
commands::read_space_config,
601601
commands::save_space_config,
602602
commands::remove_server_from_config,
603+
commands::refresh_tray_menu,
603604
// Server Discovery commands (v2)
604605
commands::discover_servers,
605606
commands::get_server_definition,

apps/desktop/src-tauri/src/tray.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ fn handle_switch_space<R: Runtime>(app: &AppHandle<R>, space_id: &str) {
132132
}
133133

134134
/// Update tray menu with current spaces
135-
#[allow(dead_code)]
136135
pub async fn update_tray_spaces<R: Runtime>(
137136
app: &AppHandle<R>,
138137
state: &AppState,

0 commit comments

Comments
 (0)