1 | module os |
2 | |
3 | import dl |
4 | |
5 | type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int) |
6 | |
7 | // open_uri opens a given uri. |
8 | pub 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 | } |