From 5a65d452443ff224558e7f9bb70ce45c55a210fa Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 3 May 2026 09:53:56 +0800 Subject: [PATCH] fix(terminal): comments Signed-off-by: fufesou --- flutter/lib/common.dart | 4 ++++ flutter/lib/desktop/pages/terminal_tab_page.dart | 2 ++ 2 files changed, 6 insertions(+) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index e99d5d226..366a7b6ba 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -718,6 +718,10 @@ closeConnection({String? id}) { final controller = Get.find(); if (controller.tabType == DesktopTabType.terminal && controller.onCloseWindow != null) { + // Terminal windows are scoped to one peer. The optional id passed to + // closeConnection() is that peer id, not a terminal tab key + // (${peerId}_${terminalId}). Closing from terminal dialogs should close + // the peer's whole terminal window, including all terminal tabs. unawaited(controller.onCloseWindow!().catchError((e, _) { debugPrint('[closeConnection] Failed to close terminal window: $e'); })); diff --git a/flutter/lib/desktop/pages/terminal_tab_page.dart b/flutter/lib/desktop/pages/terminal_tab_page.dart index eed0a8423..63289e94d 100644 --- a/flutter/lib/desktop/pages/terminal_tab_page.dart +++ b/flutter/lib/desktop/pages/terminal_tab_page.dart @@ -145,6 +145,8 @@ class _TerminalTabPageState extends State { _windowClosing = true; final tabKeys = tabController.state.value.tabs.map((t) => t.key).toList(); // Remove all UI tabs immediately (same instant behavior as the old tabController.clear()) + // Keep the cleanup target lookup below synchronous before its first await: + // it relies on the current frame still retaining each TerminalPage's FFI/model. tabController.clear(); // Run session cleanup in parallel with bounded timeout (closeTerminal() has internal 3s timeout). // Skip tabs already being closed by a concurrent _closeTab() to avoid duplicate FFI calls.