cm: only notify the user once all sessions have closed
remove_connection fired the "session ended" banner for every connection that closed. With multiple concurrent sessions (a second supporter, or a file-transfer session running alongside remote control) the user saw one banner per close even though support was still ongoing. Track the remaining approved-session count under the same lock and show the banner only when the last session has ended. Denied/never-approved connections still produce no banner. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+19
-2
@@ -140,9 +140,26 @@ impl InvokeUiCM for HeadlessCm {
|
||||
|
||||
fn remove_connection(&self, id: i32, _close: bool) {
|
||||
trace(&format!("remove_connection: id={id}"));
|
||||
let entry = self.approved.lock().unwrap().remove(&id);
|
||||
// Remove this session and read how many approved sessions remain, while
|
||||
// holding the lock so the check is atomic against concurrent add/remove.
|
||||
let (entry, remaining) = {
|
||||
let mut approved = self.approved.lock().unwrap();
|
||||
let entry = approved.remove(&id);
|
||||
(entry, approved.len())
|
||||
};
|
||||
if let Some((peer_id, name)) = entry {
|
||||
std::thread::spawn(move || show_session_ended(&peer_id, &name));
|
||||
// Only notify once EVERY approved session has ended. With multiple
|
||||
// concurrent sessions (a second supporter, or a file-transfer
|
||||
// session running alongside remote control) the user shouldn't get
|
||||
// a "session ended" banner while other sessions are still open —
|
||||
// they'd see one banner per close even though support is ongoing.
|
||||
if remaining == 0 {
|
||||
std::thread::spawn(move || show_session_ended(&peer_id, &name));
|
||||
} else {
|
||||
trace(&format!(
|
||||
"remove_connection: {remaining} approved session(s) still open; suppressing banner"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user