MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / OpenBrowser

Function OpenBrowser

cli/pkg/common/browser.go:30–53  ·  view source on GitHub ↗

打开浏览器(跨平台,支持windows、macos、linux)

(url string)

Source from the content-addressed store, hash-verified

28
29// 打开浏览器(跨平台,支持windows、macos、linux)
30func OpenBrowser(url string) (err error) {
31 switch runtime.GOOS {
32 case "linux":
33 output, err := exec.Command("ls -l /usr/share/xsessions/").CombinedOutput()
34 if err == nil {
35 SmartIDELog.Debug(string(output))
36 if !strings.Contains(string(output), "No such file or directory") { // 有图形化的界面,才打开
37 err = exec.Command("xdg-open", url).Start()
38 } else {
39 return errors.New("当前非桌面版!")
40 }
41 }
42
43 case "windows":
44 err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
45 case "darwin":
46 err = exec.Command("open", url).Start()
47 default:
48 err = fmt.Errorf("unsupported platform")
49 }
50
51 return err
52
53}

Callers

nothing calls this directly

Calls 3

CombinedOutputMethod · 0.80
DebugMethod · 0.80
StartMethod · 0.80

Tested by

no test coverage detected