v / vlib / os
Raw file | 22 loc (19 sloc) | 643 bytes | Latest commit hash 017ace6ea
1module os
2
3import dl
4
5type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int)
6
7// open_uri opens a given uri.
8pub fn open_uri(uri string) ! {
9 mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
10 if vopen_uri_cmd != '' {
11 result := execute('${vopen_uri_cmd} "${uri}"')
12 if result.exit_code != 0 {
13 return error('unable to open url: ${result.output}')
14 }
15 return
16 }
17 handle := dl.open_opt('shell32', dl.rtld_now)!
18 // https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
19 func := ShellExecuteWin(dl.sym_opt(handle, 'ShellExecuteW')!)
20 func(C.NULL, 'open'.to_wide(), uri.to_wide(), C.NULL, C.NULL, C.SW_SHOWNORMAL)
21 dl.close(handle)
22}