enforce browsers.nim only handles URLs [backport] (#15045)
This commit is contained in:
parent
ec65bfae3a
commit
925dd92e07
1 changed files with 10 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ import strutils
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
import winlean
|
import winlean
|
||||||
|
from os import absolutePath
|
||||||
else:
|
else:
|
||||||
import os, osproc
|
import os, osproc
|
||||||
|
|
||||||
|
|
@ -26,16 +27,21 @@ const osOpenCmd* =
|
||||||
## Alias for the operating system specific *"open"* command,
|
## Alias for the operating system specific *"open"* command,
|
||||||
## ``"open"`` on OSX, MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc.
|
## ``"open"`` on OSX, MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc.
|
||||||
|
|
||||||
|
proc prepare(s: string): string =
|
||||||
|
if s.contains("://"):
|
||||||
|
result = s
|
||||||
|
else:
|
||||||
|
result = "file://" & absolutePath(s)
|
||||||
|
|
||||||
template openDefaultBrowserImpl(url: string) =
|
proc openDefaultBrowserImpl(url: string) =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var o = newWideCString(osOpenCmd)
|
var o = newWideCString(osOpenCmd)
|
||||||
var u = newWideCString(url)
|
var u = newWideCString(prepare url)
|
||||||
discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
|
discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
|
||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
discard execShellCmd(osOpenCmd & " " & quoteShell(url))
|
discard execShellCmd(osOpenCmd & " " & quoteShell(prepare url))
|
||||||
else:
|
else:
|
||||||
var u = quoteShell(url)
|
var u = quoteShell(prepare url)
|
||||||
if execShellCmd(osOpenCmd & " " & u) == 0: return
|
if execShellCmd(osOpenCmd & " " & u) == 0: return
|
||||||
for b in getEnv("BROWSER").string.split(PathSep):
|
for b in getEnv("BROWSER").string.split(PathSep):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue