mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-22 07:37:29 +08:00
[feat] optimize hyperlink opening by replacing system start with CreateProcessW-based URL launch on Winodws
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
@@ -24,13 +28,34 @@ void Render::Hyperlink(const std::string& label, const std::string& url,
|
|||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||||
#if defined(_WIN32)
|
#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<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__)
|
#elif defined(__APPLE__)
|
||||||
std::string cmd = "open " + url;
|
std::string cmd = "open " + url;
|
||||||
#else
|
#else
|
||||||
std::string cmd = "xdg-open " + url;
|
std::string cmd = "xdg-open " + url;
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(_WIN32)
|
||||||
system(cmd.c_str()); // open browser
|
system(cmd.c_str()); // open browser
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user