From f7f1724bf1af9ed1a925092d6733f44ba9d12507 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 12 Feb 2026 16:22:57 +0800 Subject: [PATCH] [feat] optimize hyperlink opening by replacing system start with CreateProcessW-based URL launch on Winodws --- src/gui/windows/about_window.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gui/windows/about_window.cpp b/src/gui/windows/about_window.cpp index 7c4222e..5a4defd 100644 --- a/src/gui/windows/about_window.cpp +++ b/src/gui/windows/about_window.cpp @@ -1,6 +1,10 @@ #include #include +#if defined(_WIN32) +#include +#endif + #include "layout.h" #include "localization.h" #include "rd_log.h" @@ -24,13 +28,34 @@ void Render::Hyperlink(const std::string& label, const std::string& url, ImGui::EndTooltip(); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { #if defined(_WIN32) - std::string cmd = "start " + url; + int wide_len = + MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, nullptr, 0); + if (wide_len > 0) { + std::wstring wide_url(static_cast(wide_len), L'\0'); + MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, &wide_url[0], + wide_len); + if (!wide_url.empty() && wide_url.back() == L'\0') { + wide_url.pop_back(); + } + + std::wstring cmd = L"cmd.exe /c start \"\" \"" + wide_url + L"\""; + STARTUPINFOW startup_info = {sizeof(startup_info)}; + PROCESS_INFORMATION process_info = {}; + if (CreateProcessW(nullptr, &cmd[0], nullptr, nullptr, FALSE, + CREATE_NO_WINDOW, nullptr, nullptr, &startup_info, + &process_info)) { + CloseHandle(process_info.hThread); + CloseHandle(process_info.hProcess); + } + } #elif defined(__APPLE__) std::string cmd = "open " + url; #else std::string cmd = "xdg-open " + url; #endif +#if !defined(_WIN32) system(cmd.c_str()); // open browser +#endif } } }