love.system.openURL implementation uses SDL_OpenURL.

This commit is contained in:
Sasha Szpakowski
2025-01-18 18:19:05 -04:00
parent bff50070c6
commit 4e8291fd7e
8 changed files with 10 additions and 145 deletions
-5
View File
@@ -118,11 +118,6 @@ bool getSafeArea(int &top, int &left, int &bottom, int &right)
return safeArea != nullptr;
}
bool openURL(const std::string &url)
{
return SDL_OpenURL(url.c_str()) == 0;
}
void vibrate(double seconds)
{
JNIEnv *env = (JNIEnv*) SDL_GetAndroidJNIEnv();
-2
View File
@@ -50,8 +50,6 @@ double getScreenScale();
**/
bool getSafeArea(int &top, int &left, int &bottom, int &right);
bool openURL(const std::string &url);
void vibrate(double seconds);
bool directoryExists(const char *path);
-6
View File
@@ -42,12 +42,6 @@ namespace ios
**/
std::string getLoveInResources(bool &fused);
/**
* Opens the specified URL with the default program associated with the URL's
* scheme.
**/
bool openURL(const std::string &url);
/**
* Causes devices with vibration support to vibrate for about 0.5 seconds.
**/
-16
View File
@@ -364,22 +364,6 @@ std::string getLoveInResources(bool &fused)
return path;
}
bool openURL(const std::string &url)
{
bool success = false;
@autoreleasepool
{
UIApplication *app = [UIApplication sharedApplication];
NSURL *nsurl = [NSURL URLWithString:@(url.c_str())];
if ([app canOpenURL:nsurl])
success = [app openURL:nsurl];
}
return success;
}
void vibrate()
{
@autoreleasepool
+2 -115
View File
@@ -22,35 +22,10 @@
#include "common/config.h"
#include "System.h"
#if defined(LOVE_MACOS)
#include <CoreServices/CoreServices.h>
#elif defined(LOVE_IOS)
#if defined(LOVE_IOS)
#include "common/ios.h"
#elif defined(LOVE_LINUX) || defined(LOVE_ANDROID)
#include <signal.h>
#include <sys/wait.h>
#include <errno.h>
#elif defined(LOVE_WINDOWS)
#include "common/utf8.h"
#include <shlobj.h>
#include <shellapi.h>
#pragma comment(lib, "shell32.lib")
#endif
#if defined(LOVE_ANDROID)
#elif defined(LOVE_ANDROID)
#include "common/android.h"
#elif defined(LOVE_LINUX)
#ifdef __has_include
#if __has_include(<spawn.h>)
#define LOVE_HAS_POSIX_SPAWN
#endif
#endif
#ifdef LOVE_HAS_POSIX_SPAWN
#include <spawn.h>
#else
#include <unistd.h>
#endif
#endif
namespace love
@@ -82,94 +57,6 @@ const char *System::getOS()
#endif
}
#ifdef LOVE_HAS_POSIX_SPAWN
extern "C"
{
extern char **environ; // The environment, always available
}
#endif
bool System::openURL(const std::string &url) const
{
#if defined(LOVE_MACOS)
bool success = false;
CFURLRef cfurl = CFURLCreateWithBytes(nullptr,
(const UInt8 *) url.c_str(),
url.length(),
kCFStringEncodingUTF8,
nullptr);
success = LSOpenCFURLRef(cfurl, nullptr) == noErr;
CFRelease(cfurl);
return success;
#elif defined(LOVE_IOS)
return love::ios::openURL(url);
#elif defined(LOVE_ANDROID)
return love::android::openURL(url);
#elif defined(LOVE_LINUX)
pid_t pid;
const char *argv[] = {"xdg-open", url.c_str(), nullptr};
#ifdef LOVE_HAS_POSIX_SPAWN
// Note: at the moment this process inherits our file descriptors.
// Note: the below const_cast is really ugly as well.
if (posix_spawnp(&pid, "xdg-open", nullptr, nullptr, const_cast<char **>(argv), environ) != 0)
return false;
#else
pid = fork();
if (pid == 0)
{
execvp("xdg-open", const_cast<char **>(argv));
return false;
}
#endif
// Check if xdg-open already completed (or failed.)
int status = 0;
if (waitpid(pid, &status, WNOHANG) > 0)
return (status == 0);
else
// We can't tell what actually happens without waiting for
// the process to finish, which could take forever (literally).
return true;
#elif defined(LOVE_WINDOWS)
// Unicode-aware WinAPI functions don't accept UTF-8, so we need to convert.
std::wstring wurl = to_widestr(url);
HINSTANCE result = 0;
#if defined(LOVE_WINDOWS_UWP)
Platform::String^ urlString = ref new Platform::String(wurl.c_str());
auto uwpUri = ref new Windows::Foundation::Uri(urlString);
Windows::System::Launcher::LaunchUriAsync(uwpUri);
#else
result = ShellExecuteW(nullptr,
L"open",
wurl.c_str(),
nullptr,
nullptr,
SW_SHOW);
#endif
return (ptrdiff_t) result > 32;
#endif
}
void System::vibrate(double seconds) const
{
#ifdef LOVE_ANDROID
+1 -1
View File
@@ -94,7 +94,7 @@ public:
*
* @return Whether the URL was opened successfully.
**/
virtual bool openURL(const std::string &url) const;
virtual bool openURL(const std::string &url) const = 0;
/**
* Vibrates for the specified amount of seconds.
+6
View File
@@ -26,6 +26,7 @@
#include <SDL3/SDL_clipboard.h>
#include <SDL3/SDL_cpuinfo.h>
#include <SDL3/SDL_locale.h>
#include <SDL3/SDL_misc.h>
namespace love
{
@@ -87,6 +88,11 @@ love::system::System::PowerState System::getPowerInfo(int &seconds, int &percent
return state;
}
bool System::openURL(const std::string &url) const
{
return SDL_OpenURL(url.c_str());
}
std::vector<std::string> System::getPreferredLocales() const
{
std::vector<std::string> result;
+1
View File
@@ -48,6 +48,7 @@ public:
std::string getClipboardText() const override;
PowerState getPowerInfo(int &seconds, int &percent) const override;
bool openURL(const std::string &url) const override;
std::vector<std::string> getPreferredLocales() const override;
private: