refact: active terminal on conn the same remote (#12392)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-07-23 22:44:05 +08:00
committed by GitHub
parent f2473974b8
commit b4e13706bd
2 changed files with 23 additions and 1 deletions

View File

@@ -177,6 +177,18 @@ class _TerminalTabPageState extends State<TerminalTabPage> {
tabController.clear(); tabController.clear();
} else if (call.method == kWindowActionRebuild) { } else if (call.method == kWindowActionRebuild) {
reloadCurrentWindow(); reloadCurrentWindow();
} else if (call.method == kWindowEventActiveSession) {
if (tabController.state.value.tabs.isEmpty) {
return false;
}
final currentTab = tabController.state.value.selectedTabInfo;
assert(call.arguments is String,
"Expected String arguments for kWindowEventActiveSession, got ${call.arguments.runtimeType}");
if (currentTab.key.startsWith(call.arguments)) {
windowOnTop(windowId());
return true;
}
return false;
} }
}); });
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {

View File

@@ -354,6 +354,16 @@ class RustDeskMultiWindowManager {
bool? forceRelay, bool? forceRelay,
String? connToken, String? connToken,
}) async { }) async {
// Iterate through terminal windows in reverse order to prioritize
// the most recently added or used windows, as they are more likely
// to have an active session.
for (final windowId in _terminalWindows.reversed) {
if (await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventActiveSession, remoteId)) {
return MultiWindowCallResult(windowId, null);
}
}
// Terminal windows should always create new windows, not reuse // Terminal windows should always create new windows, not reuse
// This avoids the MissingPluginException when trying to invoke // This avoids the MissingPluginException when trying to invoke
// new_terminal on an inactive window // new_terminal on an inactive window