1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/os/open_uri_default.c.v
ghosttk fae26197b9
os: add exo-open to the list of tried launchers in os.open_uri/1 (#14884)
Add 'exo-open' for xfce4 desktop environment.
2022-06-29 11:59:25 +03:00

31 lines
856 B
V

module os
pub fn open_uri(uri string) ? {
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
if vopen_uri_cmd == '' {
$if macos {
vopen_uri_cmd = 'open'
} $else $if freebsd || openbsd {
vopen_uri_cmd = 'xdg-open'
} $else $if linux {
providers := ['xdg-open', 'x-www-browser', 'www-browser', 'wslview', 'exo-open']
// There are multiple possible providers to open a browser on linux
// One of them is xdg-open, another is x-www-browser, then there's www-browser, etc.
// Look for one that exists and run it
for provider in providers {
if exists_in_system_path(provider) {
vopen_uri_cmd = provider
break
}
}
}
}
if vopen_uri_cmd == '' {
return error('unsupported platform')
}
result := execute('$vopen_uri_cmd "$uri"')
if result.exit_code != 0 {
return error('unable to open url: $result.output')
}
}