Don't run "kde-open" and "gnome-open" under Unix (#6426)

This commit is contained in:
konqoro 2017-11-19 04:29:26 +02:00 • committed by Andreas Rumpf
commit aac94e0ab5

View file

@ -21,24 +21,18 @@ proc openDefaultBrowser*(url: string) =
## opens `url` with the user's default browser. This does not block. ## opens `url` with the user's default browser. This does not block.
## ##
## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open`` ## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open``
## command is used. Under Unix, it is checked if ``gnome-open`` exists and ## command is used. Under Unix, it is checked if ``xdg-open`` exists and
## used if it does. Next attempt is ``kde-open``, then ``xdg-open``. ## used if it does. Otherwise the environment variable ``BROWSER`` is
## Otherwise the environment variable ``BROWSER`` is used to determine the ## used to determine the default browser to use.
## default browser to use.
when defined(windows): when defined(windows):
when useWinUnicode:
var o = newWideCString("open") var o = newWideCString("open")
var u = newWideCString(url) var u = newWideCString(url)
discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL) discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
else:
discard shellExecuteA(0'i32, "open", url, nil, nil, SW_SHOWNORMAL)
elif defined(macosx): elif defined(macosx):
discard execShellCmd("open " & quoteShell(url)) discard execShellCmd("open " & quoteShell(url))
else: else:
const attempts = ["gnome-open ", "kde-open ", "xdg-open "]
var u = quoteShell(url) var u = quoteShell(url)
for a in items(attempts): if execShellCmd("xdg-open " & u) == 0: return
if execShellCmd(a & u) == 0: return
for b in getEnv("BROWSER").string.split(PathSep): for b in getEnv("BROWSER").string.split(PathSep):
try: try:
# we use ``startProcess`` here because we don't want to block! # we use ``startProcess`` here because we don't want to block!