mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-28 04:17:23 +08:00
[fix] fix update button lag in release mode by using non-blocking URL opener.
This commit is contained in:
@@ -235,6 +235,7 @@ class Render {
|
|||||||
bool ConnectionStatusWindow(
|
bool ConnectionStatusWindow(
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
int ShowRecentConnections();
|
int ShowRecentConnections();
|
||||||
|
bool OpenUrl(const std::string& url);
|
||||||
void Hyperlink(const std::string& label, const std::string& url,
|
void Hyperlink(const std::string& label, const std::string& url,
|
||||||
const float window_width);
|
const float window_width);
|
||||||
int FileTransferWindow(std::shared_ptr<SubStreamWindowProperties>& props);
|
int FileTransferWindow(std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
|
|||||||
@@ -12,6 +12,40 @@
|
|||||||
|
|
||||||
namespace crossdesk {
|
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<size_t>(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,
|
void Render::Hyperlink(const std::string& label, const std::string& url,
|
||||||
const float window_width) {
|
const float window_width) {
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 0, 255, 255));
|
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::SetWindowFontScale(1.0f);
|
||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||||
#if defined(_WIN32)
|
OpenUrl(url);
|
||||||
int wide_len =
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, nullptr, 0);
|
|
||||||
if (wide_len > 0) {
|
|
||||||
std::wstring wide_url(static_cast<size_t>(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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
@@ -184,14 +183,7 @@ int Render::UpdateNotificationWindow() {
|
|||||||
localization::update[localization_language_index_].c_str())) {
|
localization::update[localization_language_index_].c_str())) {
|
||||||
// open download page
|
// open download page
|
||||||
std::string url = "https://crossdesk.cn";
|
std::string url = "https://crossdesk.cn";
|
||||||
#if defined(_WIN32)
|
OpenUrl(url);
|
||||||
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());
|
|
||||||
show_update_notification_window_ = false;
|
show_update_notification_window_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user