From 17feabbcabe84869f7236ecf0db5d4b9904ad54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tayfur=20Y=C4=B1ld=C4=B1z?= Date: Sat, 26 Sep 2026 06:46:58 +0300 Subject: [PATCH] fix(windows): allow existing session to foreground (#16349) Signed-off-by: TayfurYldz <238304586+TayfurYldz@users.noreply.github.com> Co-authored-by: TayfurYldz <238304586+TayfurYldz@users.noreply.github.com> --- flutter/windows/runner/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flutter/windows/runner/main.cpp b/flutter/windows/runner/main.cpp index ea9152ec7..747d6f586 100644 --- a/flutter/windows/runner/main.cpp +++ b/flutter/windows/runner/main.cpp @@ -104,6 +104,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, } if (!allow_multiple_instances) { if (!command_line_arguments.empty()) { + // The process launched by the browser owns the foreground permission. + // Transfer it to the existing RustDesk process before dispatching the + // URI so that it can bring an existing session to the foreground. + DWORD pid = 0; + ::GetWindowThreadProcessId(hwnd, &pid); + if (pid != 0) { + ::AllowSetForegroundWindow(pid); + } // Dispatch command line arguments DispatchToUniLinksDesktop(hwnd); } else {