Fix: synchronize system monitoring with active tab group

This commit is contained in:
TomZz
2026-06-13 22:59:32 +08:00
parent 805cec5000
commit 8193223dc2
2 changed files with 45 additions and 21 deletions
+3 -14
View File
@@ -552,12 +552,8 @@ impl Ashell {
BackendEvent::Connected { tab_id } => {
if let Some(tab) = self.tabs.iter_mut().find(|t| t.id == tab_id) {
tab.connected = true;
if tab.session.is_some() {
if self.system_tab_id.is_none() {
self.system_tab_id = Some(tab_id.clone());
}
}
}
self.sync_system_tab_to_active_group();
self.request_active_system_snapshot();
if self
.connection_progress
@@ -669,15 +665,7 @@ impl Ashell {
}
return changed;
}
// Reassign system_tab_id if the closed tab was monitored
if self.system_tab_id.as_deref() == Some(tab_id.as_str()) {
self.system_tab_id = self.tabs.iter().find(|t| t.kind == TabKind::Ssh && t.connected).map(|t| t.id.clone());
self.cpu_history.clear();
self.net_rx_history.clear();
self.net_tx_history.clear();
self.remote_sample_in_flight = false;
self.request_active_system_snapshot();
}
let was_active = self.active_tab.as_deref() == Some(tab_id.as_str());
if was_active
|| self.active_tab.as_ref().is_some_and(|active_id| !self.tabs.iter().any(|tab| &tab.id == active_id))
@@ -689,6 +677,7 @@ impl Ashell {
self.focus_pane_with_id(new_id);
}
}
self.sync_system_tab_to_active_group();
self.status = reason.into();
self.remote_sample_in_flight = false;
return changed;
+42 -7
View File
@@ -483,6 +483,7 @@ impl Ashell {
}
}
self.focus_handle.focus(window, cx);
self.sync_system_tab_to_active_group();
cx.notify();
}
@@ -576,13 +577,7 @@ impl Ashell {
return;
}
// Reassign system_tab_id if the closed tab was monitored
if self.system_tab_id.as_deref() == Some(id.as_str()) {
self.system_tab_id = self.tabs.iter().find(|t| t.kind == TabKind::Ssh && t.connected).map(|t| t.id.clone());
if self.system_tab_id.is_none() {
self.system_status = Some("monitored session closed".to_string().into());
}
}
if was_active
@@ -610,6 +605,7 @@ impl Ashell {
self.focus_pane_with_id(active_id);
}
}
self.sync_system_tab_to_active_group();
cx.notify();
}
@@ -978,6 +974,7 @@ impl Ashell {
}
self.focus_handle.focus(window, cx);
}
self.sync_system_tab_to_active_group();
cx.notify();
}
@@ -989,6 +986,44 @@ impl Ashell {
}
}
pub(crate) fn sync_system_tab_to_active_group(&mut self) {
let mut group_ssh_tabs = vec![];
if let Some(group_id) = &self.active_group {
if let Some(group) = self.tab_groups.iter().find(|g| g.id == *group_id) {
let ids = group.pane_root.tab_ids();
for id in ids {
if let Some(tab) = self.tabs.iter().find(|t| t.id == *id) {
if tab.kind == TabKind::Ssh && tab.connected {
group_ssh_tabs.push(tab.id.clone());
}
}
}
}
}
// Check if current system_tab_id is valid in this group
let is_current_valid = self.system_tab_id
.as_ref()
.map_or(false, |id| group_ssh_tabs.contains(id));
if !is_current_valid {
let new_id = group_ssh_tabs.into_iter().next();
if self.system_tab_id != new_id {
self.system_tab_id = new_id;
self.cpu_history.clear();
self.net_rx_history.clear();
self.net_tx_history.clear();
self.remote_sample_in_flight = false;
if self.system_tab_id.is_none() {
self.system_status = Some("monitored session closed".to_string().into());
} else {
self.system_status = None;
}
self.request_active_system_snapshot();
}
}
}
pub(crate) fn start_drag_split(
&mut self,
parent_path: Vec<usize>,