From 263c5eefd34c6c07606a4ca868c8fbf60a247764 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 10 Mar 2026 10:39:05 +0800 Subject: [PATCH] [fix] fix update button lag in release mode by using non-blocking URL opener. --- src/gui/render.h | 1 + src/gui/windows/about_window.cpp | 64 ++++++++++--------- .../windows/update_notification_window.cpp | 10 +-- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/gui/render.h b/src/gui/render.h index f353f8c..4ab11f1 100644 --- a/src/gui/render.h +++ b/src/gui/render.h @@ -235,6 +235,7 @@ class Render { bool ConnectionStatusWindow( std::shared_ptr& props); int ShowRecentConnections(); + bool OpenUrl(const std::string& url); void Hyperlink(const std::string& label, const std::string& url, const float window_width); int FileTransferWindow(std::shared_ptr& props); diff --git a/src/gui/windows/about_window.cpp b/src/gui/windows/about_window.cpp index 0e71d40..a6313f6 100644 --- a/src/gui/windows/about_window.cpp +++ b/src/gui/windows/about_window.cpp @@ -12,6 +12,40 @@ namespace crossdesk { +bool Render::OpenUrl(const std::string& url) { +#if defined(_WIN32) + int wide_len = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, nullptr, 0); + if (wide_len <= 0) { + return false; + } + + 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)) { + return false; + } + + CloseHandle(process_info.hThread); + CloseHandle(process_info.hProcess); + return true; +#elif defined(__APPLE__) + std::string cmd = "open " + url; + return system(cmd.c_str()) == 0; +#else + std::string cmd = "xdg-open " + url; + return system(cmd.c_str()) == 0; +#endif +} + void Render::Hyperlink(const std::string& label, const std::string& url, const float window_width) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 0, 255, 255)); @@ -27,35 +61,7 @@ void Render::Hyperlink(const std::string& label, const std::string& url, ImGui::SetWindowFontScale(1.0f); ImGui::EndTooltip(); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { -#if defined(_WIN32) - 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 + OpenUrl(url); } } } diff --git a/src/gui/windows/update_notification_window.cpp b/src/gui/windows/update_notification_window.cpp index baabb06..9f1dffc 100644 --- a/src/gui/windows/update_notification_window.cpp +++ b/src/gui/windows/update_notification_window.cpp @@ -1,5 +1,4 @@ #include -#include #include #include "layout.h" @@ -184,14 +183,7 @@ int Render::UpdateNotificationWindow() { localization::update[localization_language_index_].c_str())) { // open download page std::string url = "https://crossdesk.cn"; -#if defined(_WIN32) - std::string cmd = "start " + url; -#elif defined(__APPLE__) - std::string cmd = "open " + url; -#else - std::string cmd = "xdg-open " + url; -#endif - system(cmd.c_str()); + OpenUrl(url); show_update_notification_window_ = false; }