* add URL support to Label element and XML parsing

* refactor Label URL handling to use getter method in setURL

* implement URL opening confirmation dialog and platform-specific URL handling

* fix: fixed build errors

* remove: delete test link label from worlds.xml

* refactor: remove URL handling from Label class and XML parsing

* refactor: clean up Label class by removing unnecessary whitespace and improving code readability

* refactor: remove unused URL member from Label class

* refactor: remove unused URL attribute from XML UI documentation and related code

* refactor: improve code readability by adding whitespace and formatting adjustments in Label class

* refactor: improve whitespace consistency in Label class and add URL opening functionality in libcore
This commit is contained in:
GHOST11111100
2025-09-26 21:39:12 +03:00
committed by GitHub
parent 21725921e1
commit 240abb939f
12 changed files with 75 additions and 4 deletions
+36 -1
View File
@@ -65,14 +65,31 @@ int platform::get_process_id() {
return GetCurrentProcessId();
}
bool platform::openURL(const std::string& url) {
if (url.empty()) return false;
// UTF-8 → UTF-16
int wlen = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, nullptr, 0);
if (wlen <= 0) return false;
std::wstring wurl(wlen, L'\0');
MultiByteToWideChar(CP_UTF8, 0, url.c_str(), -1, &wurl[0], wlen);
HINSTANCE result = ShellExecuteW(
nullptr, L"open", wurl.c_str(), nullptr, nullptr, SW_SHOWNORMAL
);
return reinterpret_cast<intptr_t>(result) > 32;
}
#else // _WIN32
#include <unistd.h>
#include <sys/wait.h>
#include "frontend/locale.hpp"
void platform::configure_encoding() {
}
std::string platform::detect_locale() {
const char* const programLocaleName = setlocale(LC_ALL, nullptr);
const char* const preferredLocaleName =
@@ -92,6 +109,24 @@ void platform::sleep(size_t millis) {
int platform::get_process_id() {
return getpid();
}
bool platform::openURL(const std::string& url) {
if (url.empty()) return false;
pid_t pid = fork();
if (pid == 0) {
#ifdef __APPLE__
execlp("open", "open", url.c_str(), (char*)nullptr);
#else
execlp("xdg-open", "xdg-open", url.c_str(), (char*)nullptr);
#endif
_exit(127);
} else if (pid > 0) {
int status = 0;
waitpid(pid, &status, 0);
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}
return false;
}
#endif // _WIN32
void platform::open_folder(const std::filesystem::path& folder) {