2021-09-09 10:48:53 +03:00
|
|
|
module os
|
|
|
|
|
|
|
|
import dl
|
|
|
|
|
|
|
|
type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int)
|
|
|
|
|
2022-10-16 09:28:57 +03:00
|
|
|
pub fn open_uri(uri string) ! {
|
2021-10-06 06:29:32 +03:00
|
|
|
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
|
|
|
|
if vopen_uri_cmd != '' {
|
|
|
|
result := execute('$vopen_uri_cmd "$uri"')
|
|
|
|
if result.exit_code != 0 {
|
|
|
|
return error('unable to open url: $result.output')
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2022-10-16 09:28:57 +03:00
|
|
|
handle := dl.open_opt('shell32', dl.rtld_now)!
|
2021-09-09 10:48:53 +03:00
|
|
|
// https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
|
2022-10-16 09:28:57 +03:00
|
|
|
func := ShellExecuteWin(dl.sym_opt(handle, 'ShellExecuteW')!)
|
2021-09-09 10:48:53 +03:00
|
|
|
func(C.NULL, 'open'.to_wide(), uri.to_wide(), C.NULL, C.NULL, C.SW_SHOWNORMAL)
|
|
|
|
dl.close(handle)
|
|
|
|
}
|