Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: SDL_OpenURL() #1690

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

FEATURE: SDL_OpenURL() #1690

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.3
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2014-11-14 14:15:58 +0000, Alexey wrote:

Cross platform function that will open specified URL in default browser. Mailing list conversation can be found here http://lists.libsdl.org/pipermail/sdl-libsdl.org/2014-October/096773.html

On 2014-11-16 14:16:58 +0000, Alex wrote:

I agree we need this function. This is good idea.

On 2014-11-21 08:43:21 +0000, Eric wing wrote:

There are official APIs for opening a URL on Mac, iOS, Android, and Windows. I don't know about Linux except for the command line xdg-open.

Mac
NSURL the_url = [NSURL URLWithString:@"http://www.apple.com"];
[[NSWorkspace sharedWorkspace] openURL:the_url];

iOS
NSURL the_url = [NSURL URLWithString:@"http://www.apple.com"];
[[UIApplication sharedApplication] openURL:the_url];

Windows:
LONG r = ShellExecute(NULL, "open", "http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL);
(maybe that should be ShellExecuteA)

I forgot the details of Android, but you use Intents.
http://stackoverflow.com/questions/3004515/android-sending-an-intent-to-browser-to-open-specific-url
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Now please don't limit URLs to just http://. It is very common on Mac, iOS, and Android to use custom URLs to launch specific apps. Sometimes they are for popular protocols so people spontaneously conform their apps to URL schemes that get documented so their apps can handle them too, say like twitter:// (The OS may have an arbitration system if multiple apps handle the same URL scheme.)
http://wiki.akosma.com/IPhone_URL_Schemes

Particularly in mobile games, I've seen a lot of developers cross-promote their apps, where one app can launch another and maybe you win points or something for doing so.

The Mac and iOS code will just work for that case. I think Windows may work too. Android is a little more involved if I remember and you may have to add more cases, but I've totally forgotten the details of how it works.

Also, there is a counterpart system to this. It is also handy to know when you've been launched via OpenURL. And you need to be able to parse the URL string for information that was passed. For example, most text editors on the Mac respond to URL schemes (even MacVim) and you can tell it to open a specific file at a specific line number. Or in the cross-promotional example above, you want to know which app launched you. The receiving app needs a notification that OpenURL was invoked with a particular string. Also, keep in mind that the app may or may not have been already running when this even happened.

On 2015-02-06 15:27:48 +0000, Sylvain wrote:

Created attachment 2021
patch SDL_OpenURL : Android + Unix

Here's a first version of "SDL_OpenURL" function for Android and Unix.

It works with URLs, and probably with directories and files.

It would be nice if someone could add MacOSX, IOS, Windows, etc.

On 2015-02-07 07:56:16 +0000, Sylvain wrote:

Created attachment 2022
patch SDL_OpenURL : Android + Unix (v2)

Update the patch so that it uses "execl()", instead of "system()", to run "xdg-open url". The argument is then protected.

Not sure if it solves the problem mentioned by Gerry JJ of browser blocking/not_blocking.

On 2015-02-08 10:48:36 +0000, Sylvain wrote:

Created attachment 2025
patch SDL_OpenURL : Android + Unix + MacOSX + IOS (v3)

Add MacOSX, IOS part
Changed "fork" to "vfork"
Changed "exit" to "_exit"

Notice that IOS part is in "src/power" because there is no "filesystem" directory. I would have needed to modify the xcode project to have one.

On 2015-02-10 07:44:41 +0000, Sylvain wrote:

Created attachment 2027
patch SDL_OpenURL : Android + Unix + MacOSX + IOS + double-forking (v4)

As suggested, I have updated the patch to fork twice so the application cannot be blocked.

Notice that the return code does not say anything about the success/failure of xdg-open, but now, is about the success/failure of the launcher of xdg-open.

I have used "vfork()" since it is said to be more efficient for this very case.

On 2015-02-12 07:35:12 +0000, Sylvain wrote:

Created attachment 2032
patch SDL_OpenURL : Android + Unix + MacOSX + IOS + double-forking (v5)

Update fork/vfork : use first fork(), then vfork().
Instead of "execl", use "execlp".

On 2015-05-10 22:34:37 +0000, Daniel Gibson wrote:

I think one fork() is enough. Calling setsid() before execlp() should fix the zombie-problems (if not, try a pumpgun).

On 2015-05-11 15:57:52 +0000, Daniel Gibson wrote:

ok, nevermind, setsid() doesn't seem to work like I thought it does. so probably double-fork is the way to go, even though it seems hacky to me

On 2015-05-11 16:11:10 +0000, Sylvain wrote:

There was a detailled discussion on the mailing-list about the double-fork issue and SDL_OpenURL.
And this solution was adviced.

Indeed, the code is not really readable and a cleaner solution would be better.

I don't really know about "setsid()", but post to the mailing, I sure you'll get positive feedback about it.

On 2015-06-30 13:24:37 +0000, Vikas wrote:

Created attachment 2207
patch SDL_OpenURL : Windows platform

It works with URLs,directories,files and executable.
I have tested it with windowed as well as full screen mode.

In case of full screen mode, SDL window will be minimized and browser(default) will be launched. Later on SDL window can be restored to previous state(full screen) by (ALT+TAB) or clicking the SDL app from task bar

On 2015-12-10 07:29:54 +0000, Sylvain wrote:

I have tried the patch for windows on windows 10.

The patch looks correct according to documentation but it doesn't work on my side!

On Windows 10 / x64 : it fails with error code 31 which means that "open" action and "url" are not registered together. But they are, in the register.

On Windows 10 / arm (mobile) : it compiles but app fails to start because of missing .dll ... (it should be included automatically I think).

On 2015-12-14 18:42:37 +0000, Sylvain wrote:

On windows 10, a way to open a link is:

auto uri = ref new Windows::Foundation::Uri("http://www.libsdl.org");
Windows::System::Launcher::LaunchUriAsync(uri);

On 2020-10-01 12:49:52 +0000, Sylvain wrote:

For Android, added:
int SDL_AndroidOpenURL(const char *url);
( https://hg.libsdl.org/SDL/rev/0c20003a6df7 )

On 2020-10-07 07:09:01 +0000, Sylvain wrote:

let's close it since Ryan add all the back-end !

https://hg.libsdl.org/SDL/rev/7d7a72e4f9b6 and following commits .

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant