Skip to content

Commit 8844072

Browse files
authored
add support for firefox based zen browser (#930)
1 parent 27cd591 commit 8844072

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

pkg/assume/assume.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func AssumeCommand(c *cli.Context) error {
344344
return err
345345
}
346346

347-
if cfg.DefaultBrowser == browser.FirefoxKey || cfg.DefaultBrowser == browser.WaterfoxKey || cfg.DefaultBrowser == browser.FirefoxStdoutKey || cfg.DefaultBrowser == browser.FirefoxDevEditionKey || cfg.DefaultBrowser == browser.FirefoxNightlyKey {
347+
if cfg.DefaultBrowser == browser.FirefoxKey || cfg.DefaultBrowser == browser.WaterfoxKey || cfg.DefaultBrowser == browser.FirefoxStdoutKey || cfg.DefaultBrowser == browser.FirefoxDevEditionKey || cfg.DefaultBrowser == browser.FirefoxNightlyKey || cfg.DefaultBrowser == browser.ZenKey {
348348
// transform the URL into the Firefox Tab Container format.
349349
consoleURL = fmt.Sprintf("ext+granted-containers:name=%s&url=%s&color=%s&icon=%s", containerProfile, url.QueryEscape(consoleURL), profile.CustomGrantedProperty("color"), profile.CustomGrantedProperty("icon"))
350350
}
@@ -376,6 +376,10 @@ func AssumeCommand(c *cli.Context) error {
376376
l = launcher.Safari{}
377377
case browser.ArcKey:
378378
l = launcher.Arc{}
379+
case browser.ZenKey:
380+
l = launcher.Zen{
381+
ExecutablePath: browserPath,
382+
}
379383
case browser.FirefoxDevEditionKey:
380384
l = launcher.FirefoxDevEdition{
381385
ExecutablePath: browserPath,

pkg/browser/browsers.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
StdoutKey string = "STDOUT"
1919
FirefoxStdoutKey string = "FIREFOX_STDOUT"
2020
ArcKey string = "ARC"
21+
ZenKey string = "ZEN"
2122
FirefoxDevEditionKey string = "FIREFOX_DEV"
2223
FirefoxNightlyKey string = "FIREFOX_NIGHTLY"
2324
CustomKey string = "CUSTOM"
@@ -65,6 +66,10 @@ var SafariPathMac = []string{"/Applications/Safari.app/Contents/MacOS/Safari"}
6566

6667
var ArcPathMac = []string{"/Applications/Arc.app/Contents/MacOS/Arc"}
6768

69+
var ZenPathMac = []string{"/Applications/Zen Browser.app/Contents/MacOS/zen"}
70+
var ZenPathLinux = []string{`/usr/bin/zen-browser`, `/opt/zen-browser/zen`}
71+
var ZenPathWindows = []string{`\Program Files\Zen Browser\zen.exe`}
72+
6873
func ChromePathDefaults() ([]string, error) {
6974
// check linuxpath for binary install
7075
path, err := exec.LookPath("google-chrome-stable")
@@ -250,3 +255,20 @@ func ArcPathDefaults() ([]string, error) {
250255
return nil, errors.New("os not supported")
251256
}
252257
}
258+
259+
func ZenPathDefaults() ([]string, error) {
260+
path, err := exec.LookPath("zen-browser")
261+
if err == nil {
262+
return []string{path}, nil
263+
}
264+
switch runtime.GOOS {
265+
case "windows":
266+
return ZenPathWindows, nil
267+
case "darwin":
268+
return ZenPathMac, nil
269+
case "linux":
270+
return ZenPathLinux, nil
271+
default:
272+
return nil, errors.New("os not supported")
273+
}
274+
}

pkg/browser/detect.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func HandleManualBrowserSelection() (string, error) {
5050
withStdio := survey.WithStdio(os.Stdin, os.Stderr, os.Stderr)
5151
in := survey.Select{
5252
Message: "Select one of the browsers from the list",
53-
Options: []string{"Chrome", "Brave", "Edge", "Vivaldi", "Firefox", "Waterfox", "Chromium", "Safari", "Stdout", "FirefoxStdout", "Firefox Developer Edition", "Firefox Nightly", "Arc", "Custom"},
53+
Options: []string{"Chrome", "Brave", "Edge", "Vivaldi", "Firefox", "Waterfox", "Chromium", "Safari", "Stdout", "FirefoxStdout", "Firefox Developer Edition", "Firefox Nightly", "Arc", "Zen", "Custom"},
5454
}
5555
var selection string
5656
clio.NewLine()
@@ -139,6 +139,9 @@ func GetBrowserKey(b string) string {
139139
if strings.Contains(strings.ToLower(b), "arc") {
140140
return ArcKey
141141
}
142+
if strings.Contains(strings.ToLower(b), "zen") {
143+
return ZenKey
144+
}
142145
if strings.Contains(strings.ToLower(b), "custom") {
143146
return CustomKey
144147
}
@@ -169,6 +172,8 @@ func DetectInstallation(browserKey string) (string, bool) {
169172
bPath, _ = SafariPathDefaults()
170173
case ArcKey:
171174
bPath, _ = ArcPathDefaults()
175+
case ZenKey:
176+
bPath, _ = ZenPathDefaults()
172177
case FirefoxDevEditionKey:
173178
bPath, _ = FirefoxDevPathDefaults()
174179
case FirefoxNightlyKey:
@@ -261,7 +266,7 @@ func ConfigureBrowserSelection(browserName string, path string) error {
261266
browserPath = customBrowserPath
262267
}
263268

264-
if browserKey == FirefoxKey || browserKey == WaterfoxKey || browserKey == FirefoxDevEditionKey || browserKey == FirefoxNightlyKey {
269+
if browserKey == FirefoxKey || browserKey == WaterfoxKey || browserKey == FirefoxDevEditionKey || browserKey == FirefoxNightlyKey || browserKey == ZenKey {
265270
err := RunFirefoxExtensionPrompts(browserPath, browserName)
266271
if err != nil {
267272
return err

pkg/granted/console.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var ConsoleCommand = cli.Command{
5454
if err != nil {
5555
return err
5656
}
57-
if c.Bool("firefox") || cfg.DefaultBrowser == browser.FirefoxKey || cfg.DefaultBrowser == browser.FirefoxStdoutKey {
57+
if c.Bool("firefox") || cfg.DefaultBrowser == browser.FirefoxKey || cfg.DefaultBrowser == browser.FirefoxStdoutKey || cfg.DefaultBrowser == browser.ZenKey {
5858
// transform the URL into the Firefox Tab Container format.
5959
consoleURL = fmt.Sprintf("ext+granted-containers:name=%s&url=%s&color=%s&icon=%s", c.String("container-name"), url.QueryEscape(consoleURL), c.String("color"), c.String("icon"))
6060
}
@@ -97,6 +97,10 @@ var ConsoleCommand = cli.Command{
9797
l = launcher.Firefox{
9898
ExecutablePath: cfg.CustomBrowserPath,
9999
}
100+
case browser.ZenKey:
101+
l = launcher.Zen{
102+
ExecutablePath: cfg.CustomBrowserPath,
103+
}
100104
case browser.SafariKey:
101105
l = launcher.Safari{}
102106
case browser.CustomKey:

pkg/launcher/zen.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package launcher
2+
3+
type Zen struct {
4+
ExecutablePath string
5+
}
6+
7+
func (l Zen) LaunchCommand(url string, profile string) ([]string, error) {
8+
return []string{
9+
l.ExecutablePath,
10+
"--new-tab",
11+
url,
12+
}, nil
13+
}
14+
15+
func (l Zen) UseForkProcess() bool { return true }

0 commit comments

Comments
 (0)