Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion project_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func buildProjectWeb(port string) {
err = open("http://localhost:" + port + "/")
if err != nil {
fmt.Println("failed to open browser", err)
fmt.Println("please open browser manually: http://localhost:" + port + "/")
}

quit := make(chan os.Signal, 1)
Expand All @@ -268,8 +269,24 @@ func open(url string) error {
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
if !wslCheck() {
cmd = "xdg-open"
}
}
args = append(args, url)
if cmd == "" {
fmt.Println("please open browser manually: " + url)
return nil
}
return exec.Command(cmd, args...).Start()
}

func wslCheck() bool {
content, err := os.ReadFile("/proc/version")
if err != nil {
return false
}
osVersion := strings.ToLower(string(content))
fmt.Printf("OS Version: %s", osVersion)
return strings.Contains(osVersion, "microsoft") && strings.Contains(osVersion, "wsl")
}