From eeccfba2e1fbb936c0b1b9c10ef5342db0d84e03 Mon Sep 17 00:00:00 2001 From: James Cleverley-Prance Date: Mon, 11 Nov 2024 05:47:25 +0000 Subject: [PATCH] Add Vivaldi browser support (#797) * Add support for Vivaldi browser * add windows/linux * tweak windows path * add linux path search --- pkg/assume/assume.go | 2 +- pkg/browser/browsers.go | 23 +++++++++++++++++++++++ pkg/browser/detect.go | 7 ++++++- pkg/granted/console.go | 4 ++++ pkg/launcher/chrome_profile.go | 13 +++++++++++++ scripts/assume | 6 +++--- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pkg/assume/assume.go b/pkg/assume/assume.go index 0cb5da4f..a30c0b27 100644 --- a/pkg/assume/assume.go +++ b/pkg/assume/assume.go @@ -429,7 +429,7 @@ func AssumeCommand(c *cli.Context) error { var l Launcher switch cfg.DefaultBrowser { - case browser.ChromeKey, browser.BraveKey, browser.EdgeKey, browser.ChromiumKey: + case browser.ChromeKey, browser.BraveKey, browser.EdgeKey, browser.ChromiumKey, browser.VivaldiKey: l = launcher.ChromeProfile{ BrowserType: cfg.DefaultBrowser, ExecutablePath: browserPath, diff --git a/pkg/browser/browsers.go b/pkg/browser/browsers.go index 1c5b2299..60765162 100644 --- a/pkg/browser/browsers.go +++ b/pkg/browser/browsers.go @@ -21,6 +21,7 @@ const ( FirefoxDevEditionKey string = "FIREFOX_DEV" FirefoxNightlyKey string = "FIREFOX_NIGHTLY" CustomKey string = "CUSTOM" + VivaldiKey string = "VIVALDI" ) // A few default paths to check for the browser @@ -56,6 +57,10 @@ var ChromiumPathMac = []string{"/Applications/Chromium.app/Contents/MacOS/Chromi var ChromiumPathLinux = []string{`/usr/bin/chromium`, `/../../mnt/c/Program Files/Chromium/chromium.exe`} var ChromiumPathWindows = []string{`\Program Files\Chromium\chromium.exe`} +var VivaldiPathMac = []string{"/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"} +var VivaldiPathLinux = []string{`/usr/bin/vivaldi`, `/../../mnt/c/Program Files/Vivaldi/Application/vivaldi.exe`} +var VivaldiPathWindows = []string{`\Program Files\Vivaldi\Application\vivaldi.exe`} + var SafariPathMac = []string{"/Applications/Safari.app/Contents/MacOS/Safari"} var ArcPathMac = []string{"/Applications/Arc.app/Contents/MacOS/Arc"} @@ -210,6 +215,24 @@ func ChromiumPathDefaults() ([]string, error) { } } +func VivaldiPathDefaults() ([]string, error) { + // check linuxpath for binary install + path, err := exec.LookPath("vivaldi") + if err == nil { + return []string{path}, nil + } + switch runtime.GOOS { + case "windows": + return VivaldiPathWindows, nil + case "darwin": + return VivaldiPathMac, nil + case "linux": + return VivaldiPathLinux, nil + default: + return nil, errors.New("os not supported") + } +} + func SafariPathDefaults() ([]string, error) { switch runtime.GOOS { case "darwin": diff --git a/pkg/browser/detect.go b/pkg/browser/detect.go index a94b7cde..1dfa41ae 100644 --- a/pkg/browser/detect.go +++ b/pkg/browser/detect.go @@ -50,7 +50,7 @@ func HandleManualBrowserSelection() (string, error) { withStdio := survey.WithStdio(os.Stdin, os.Stderr, os.Stderr) in := survey.Select{ Message: "Select one of the browsers from the list", - Options: []string{"Chrome", "Brave", "Edge", "Firefox", "Waterfox", "Chromium", "Safari", "Stdout", "FirefoxStdout", "Firefox Developer Edition", "Firefox Nightly", "Arc", "Custom"}, + Options: []string{"Chrome", "Brave", "Edge", "Vivaldi", "Firefox", "Waterfox", "Chromium", "Safari", "Stdout", "FirefoxStdout", "Firefox Developer Edition", "Firefox Nightly", "Arc", "Custom"}, } var selection string clio.NewLine() @@ -130,6 +130,9 @@ func GetBrowserKey(b string) string { if strings.Contains(strings.ToLower(b), "chromium") { return ChromiumKey } + if strings.Contains(strings.ToLower(b), "vivaldi") { + return VivaldiKey + } if strings.Contains(strings.ToLower(b), "safari") { return SafariKey } @@ -160,6 +163,8 @@ func DetectInstallation(browserKey string) (string, bool) { bPath, _ = WaterfoxPathDefaults() case ChromiumKey: bPath, _ = ChromiumPathDefaults() + case VivaldiKey: + bPath, _ = VivaldiPathDefaults() case SafariKey: bPath, _ = SafariPathDefaults() case ArcKey: diff --git a/pkg/granted/console.go b/pkg/granted/console.go index 535788b5..b3f0fa50 100644 --- a/pkg/granted/console.go +++ b/pkg/granted/console.go @@ -89,6 +89,10 @@ var ConsoleCommand = cli.Command{ l = launcher.ChromeProfile{ ExecutablePath: cfg.CustomBrowserPath, } + case browser.VivaldiKey: + l = launcher.ChromeProfile{ + ExecutablePath: cfg.CustomBrowserPath, + } case browser.FirefoxKey: l = launcher.Firefox{ ExecutablePath: cfg.CustomBrowserPath, diff --git a/pkg/launcher/chrome_profile.go b/pkg/launcher/chrome_profile.go index 3065a092..11117109 100644 --- a/pkg/launcher/chrome_profile.go +++ b/pkg/launcher/chrome_profile.go @@ -51,6 +51,10 @@ var ChromiumPathMac = "Library/Application Support/Chromium/Local State" var ChromiumPathLinux = ".config/chromium/Local State" var ChromiumPathWindows = `AppData\Local\Chromium\User Data/Local State` +var VivaldiPathMac = "Library/Application Support/Vivaldi/Local State" +var VivaldiPathLinux = ".config/vivaldi/Local State" +var VivaldiPathWindows = `AppData\Local\Vivaldi\User Data/Local State` + // setProfileName attempts to rename an existing Chrome profile from 'Person 2', 'Person 3', etc // into the name of the AWS profile that we're launching. // @@ -197,6 +201,9 @@ func getLocalStatePath(browserType string) (stateFile string, err error) { case browser.ChromiumKey: stateFile = path.Join(stateFile, ChromiumPathWindows) + + case browser.VivaldiKey: + stateFile = path.Join(stateFile, VivaldiPathWindows) } case "darwin": @@ -212,6 +219,9 @@ func getLocalStatePath(browserType string) (stateFile string, err error) { case browser.ChromiumKey: stateFile = path.Join(stateFile, ChromiumPathMac) + + case browser.VivaldiKey: + stateFile = path.Join(stateFile, VivaldiPathMac) } case "linux": @@ -227,6 +237,9 @@ func getLocalStatePath(browserType string) (stateFile string, err error) { case browser.ChromiumKey: stateFile = path.Join(stateFile, ChromiumPathLinux) + + case browser.VivaldiKey: + stateFile = path.Join(stateFile, VivaldiPathLinux) } default: diff --git a/scripts/assume b/scripts/assume index 49632a5d..f91fe758 100755 --- a/scripts/assume +++ b/scripts/assume @@ -11,7 +11,7 @@ _this_type=$(type -- "${0##*/}" 2>&1) # In the case of zsh, the output will contain the word 'alias'. # shellcheck disable=SC3028 if [ "${_this_type#*not found}" != "$_this_type" ] || - [ "${_this_type#*alias}" != "$_this_type" ] || + [ "${_this_type#*alias}" != "$_this_type" ] || [ "${BASH_SOURCE:-$0}" != "${0}" ]; then GRANTED_RETURN_STATUS="true" export GRANTED_ALIAS_CONFIGURED="true" @@ -148,7 +148,7 @@ fi if [ "$GRANTED_FLAG" = "GrantedExec" ]; then # Set GRANTED_12 with a command to execute, for example, "bash -c 'some_command'" # Make sure to properly escape quotes if needed and pass arguments. - + # Set and export the AWS variables only for the duration of the 'sh -c' command AWS_ACCESS_KEY_ID="${GRANTED_1:-}" \ AWS_SECRET_ACCESS_KEY="${GRANTED_2:-}" \ @@ -156,7 +156,7 @@ if [ "$GRANTED_FLAG" = "GrantedExec" ]; then AWS_REGION="${GRANTED_5:-}" \ AWS_DEFAULT_REGION="${GRANTED_5:-}" \ sh -c "$GRANTED_12" - + # The variables will not affect the parent shell environment after the 'sh -c' command completes fi # The GrantedOutput flag should be followed by a newline, then the output.