|
@@ -2,9 +2,22 @@ package utils
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
|
|
+ "regexp"
|
|
|
"runtime"
|
|
"runtime"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+func checkIfWsl() bool {
|
|
|
|
|
+ out, err := exec.Command("uname", "-a").Output()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ // On some cases, uname on wsl outputs microsoft capitalized
|
|
|
|
|
+ if matched, err := regexp.Match(`microsoft|Microsoft`, out); err != nil {
|
|
|
|
|
+ return matched
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// OpenBrowser opens the specified URL in the default browser of the user.
|
|
// OpenBrowser opens the specified URL in the default browser of the user.
|
|
|
func OpenBrowser(url string) error {
|
|
func OpenBrowser(url string) error {
|
|
|
var cmd string
|
|
var cmd string
|
|
@@ -17,7 +30,11 @@ func OpenBrowser(url string) error {
|
|
|
case "darwin":
|
|
case "darwin":
|
|
|
cmd = "open"
|
|
cmd = "open"
|
|
|
default: // "linux", "freebsd", "openbsd", "netbsd"
|
|
default: // "linux", "freebsd", "openbsd", "netbsd"
|
|
|
- cmd = "xdg-open"
|
|
|
|
|
|
|
+ if checkIfWsl() {
|
|
|
|
|
+ cmd = "explorer.exe"
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cmd = "xdg-open"
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
args = append(args, url)
|
|
args = append(args, url)
|
|
|
return exec.Command(cmd, args...).Start()
|
|
return exec.Command(cmd, args...).Start()
|