Merge OSX and Posix implementations of browse

They are identical except their usage of open vs. xdg-open
This commit is contained in:
MoonlightSentinel 2021-04-21 10:42:38 +02:00
parent 08927149cc
commit d186363752
No known key found for this signature in database
GPG key ID: 1A1A60AECDC956AB

View file

@ -4139,42 +4139,6 @@ version (Windows)
ShellExecuteW(null, "open", url.tempCStringW(), null, null, SW_SHOWNORMAL);
}
}
else version (OSX)
{
import core.stdc.stdio;
import core.stdc.string;
import core.sys.posix.unistd;
void browse(scope const(char)[] url) nothrow @nogc
{
const(char)*[5] args;
auto curl = url.tempCString();
const(char)* browser = core.stdc.stdlib.getenv("BROWSER");
if (browser)
{ browser = strdup(browser);
args[0] = browser;
args[1] = curl;
args[2] = null;
}
else
{
args[0] = "open".ptr;
args[1] = curl;
args[2] = null;
}
auto childpid = core.sys.posix.unistd.fork();
if (childpid == 0)
{
core.sys.posix.unistd.execvp(args[0], cast(char**) args.ptr);
perror(args[0]); // failed to execute
return;
}
if (browser)
free(cast(void*) browser);
}
}
else version (Posix)
{
import core.stdc.stdio;
@ -4191,8 +4155,17 @@ else version (Posix)
args[0] = browser;
}
else
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
args[0] = "xdg-open".ptr;
{
version (OSX)
{
args[0] = "open".ptr;
}
else
{
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
args[0] = "xdg-open".ptr;
}
}
const buffer = url.tempCString(); // Retain buffer until end of scope
args[1] = buffer;