| 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 | // 1 is SW_SHOWNORMAL, but it avoids including winuser.h, and in turn windows.h, which conflicts with raylib |
| 21 | func(C.NULL, 'open'.to_wide(), uri.to_wide(), C.NULL, C.NULL, 1) |
| 22 | dl.close(handle) |
| 23 | } |
| 24 | |