mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add core.open_url() to main menu API (#8592)
This commit is contained in:
parent
c1ce4be756
commit
a9c3a42323
10 changed files with 98 additions and 96 deletions
|
@ -33,22 +33,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <wincrypt.h>
|
||||
#include <algorithm>
|
||||
#include <shlwapi.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#if !defined(__ANDROID__)
|
||||
#include <spawn.h>
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__hpux)
|
||||
#define _PSTAT64
|
||||
#include <sys/pstat.h>
|
||||
#endif
|
||||
#if defined(__ANDROID__)
|
||||
#include "porting_android.h"
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "filesys.h"
|
||||
#include "log.h"
|
||||
#include "util/string.h"
|
||||
#include "settings.h"
|
||||
#include <list>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
@ -697,6 +703,28 @@ int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...)
|
|||
return c;
|
||||
}
|
||||
|
||||
bool openURL(const std::string &url)
|
||||
{
|
||||
if ((url.substr(0, 7) != "http://" && url.substr(0, 8) != "https://") ||
|
||||
url.find_first_of("\r\n") != std::string::npos) {
|
||||
errorstream << "Invalid url: " << url << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (intptr_t)ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL) > 32;
|
||||
#elif defined(__ANDROID__)
|
||||
openURLAndroid(url);
|
||||
return true;
|
||||
#elif defined(__APPLE__)
|
||||
const char *argv[] = {"open", url.c_str(), NULL};
|
||||
return posix_spawnp(NULL, "open", NULL, NULL, (char**)argv, environ) == 0;
|
||||
#else
|
||||
const char *argv[] = {"xdg-open", url.c_str(), NULL};
|
||||
return posix_spawnp(NULL, "xdg-open", NULL, NULL, (char**)argv, environ) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load performance counter frequency only once at startup
|
||||
#ifdef _WIN32
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue