diff --git a/src/common/android.cpp b/src/common/android.cpp index 50f5387e8..6cdcc2192 100644 --- a/src/common/android.cpp +++ b/src/common/android.cpp @@ -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(); diff --git a/src/common/android.h b/src/common/android.h index 2cf94943f..6cced7625 100644 --- a/src/common/android.h +++ b/src/common/android.h @@ -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); diff --git a/src/common/ios.h b/src/common/ios.h index 7e6e0685b..554e70c9b 100644 --- a/src/common/ios.h +++ b/src/common/ios.h @@ -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. **/ diff --git a/src/common/ios.mm b/src/common/ios.mm index a1f8109da..f48e9a5a9 100644 --- a/src/common/ios.mm +++ b/src/common/ios.mm @@ -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 diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index cee7674c9..0f974b619 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -22,35 +22,10 @@ #include "common/config.h" #include "System.h" -#if defined(LOVE_MACOS) -#include -#elif defined(LOVE_IOS) +#if defined(LOVE_IOS) #include "common/ios.h" -#elif defined(LOVE_LINUX) || defined(LOVE_ANDROID) -#include -#include -#include -#elif defined(LOVE_WINDOWS) -#include "common/utf8.h" -#include -#include -#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() -#define LOVE_HAS_POSIX_SPAWN -#endif -#endif - -#ifdef LOVE_HAS_POSIX_SPAWN -#include -#else -#include -#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(argv), environ) != 0) - return false; -#else - pid = fork(); - if (pid == 0) - { - execvp("xdg-open", const_cast(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 diff --git a/src/modules/system/System.h b/src/modules/system/System.h index 7a7ed764e..28eba22fb 100644 --- a/src/modules/system/System.h +++ b/src/modules/system/System.h @@ -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. diff --git a/src/modules/system/sdl/System.cpp b/src/modules/system/sdl/System.cpp index e23a5d364..633c0c7fc 100644 --- a/src/modules/system/sdl/System.cpp +++ b/src/modules/system/sdl/System.cpp @@ -26,6 +26,7 @@ #include #include #include +#include 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 System::getPreferredLocales() const { std::vector result; diff --git a/src/modules/system/sdl/System.h b/src/modules/system/sdl/System.h index 883016dbb..e09cef678 100644 --- a/src/modules/system/sdl/System.h +++ b/src/modules/system/sdl/System.h @@ -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 getPreferredLocales() const override; private: