-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsers.go
116 lines (95 loc) · 2.37 KB
/
browsers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package browser
import (
"runtime"
)
// Preferred opens the url in the user's prefered browser.
func Preferred(c Config) (cmd string, args []string) {
switch runtime.GOOS {
case "windows":
return "cmd", []string{"/c", "start", c.URL}
case "darwin":
return "open", []string{c.URL}
default: // "linux", "freebsd", "openbsd", "netbsd", ...
return "xdg-open", []string{c.URL}
}
}
func chrome() (cmd string, args []string) {
switch runtime.GOOS {
case "windows":
return "cmd", []string{"/c", "start", "chrome"}
case "darwin":
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", nil
default:
return "google-chrome", nil
}
}
// Chrome opens chrome using cfg.
func Chrome(cfg Config) (cmd string, args []string) {
cmd, args = chrome()
if cfg.AsApp {
cfg.URL = "--app=" + cfg.URL
}
args = append(args, cfg.URL)
if cfg.Private {
args = append(args, "--incognito")
}
return cmd, args
}
func firefox() (cmd string, args []string) {
switch runtime.GOOS {
case "windows":
return "cmd", []string{"/c", "start", "firefox"}
case "darwin":
return "/Applications/Firefox.app/Contents/MacOS/Firefox", nil
default:
return "firefox", nil
}
}
// Firefox opens firefox using cfg.
func Firefox(c Config) (cmd string, args []string) {
cmd, args = firefox()
if c.AsApp {
args = append(args, "--kiosk") // just a maximized window
}
if c.Private {
args = append(args, "-private-window") // this sometimes works
}
args = append(args, c.URL)
return cmd, args
}
func edge() (cmd string, args []string) {
switch runtime.GOOS {
case "windows":
return "cmd", []string{"/c", "start", "msedge"}
case "darwin":
return "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", nil
default:
return "microsoft-edge", nil
}
}
// Edge opens edge using cfg.
func Edge(c Config) (cmd string, args []string) {
cmd, args = edge()
if c.AsApp {
c.URL = "--app=" + c.URL
}
args = append(args, c.URL)
if c.Private {
args = append(args, "--incognito")
}
return cmd, args
}
/*
// Safari opens the URL in Safari.
func (c Config) Safari(url string) error {
if runtime.GOOS != "darwin" {
return errors.New("safari not available in " + runtime.GOOS)
}
// Safari does not have a cmd line interface.
return c.start("open", "-a", "Safari", url)
}
// Safari opens the URL in Safari.
func Safari(url string) error {
return DefaultCfg.Safari(url)
}
*/