Skip to content

Commit

Permalink
Add Vivaldi browser support (#797)
Browse files Browse the repository at this point in the history
* Add support for Vivaldi browser

* add windows/linux

* tweak windows path

* add linux path search
  • Loading branch information
jpts authored Nov 11, 2024
1 parent 062ec34 commit eeccfba
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/assume/assume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions pkg/browser/browsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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":
Expand Down
7 changes: 6 additions & 1 deletion pkg/browser/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions pkg/granted/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions pkg/launcher/chrome_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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":
Expand All @@ -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":
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions scripts/assume
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -148,15 +148,15 @@ 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:-}" \
AWS_SESSION_TOKEN="${GRANTED_3:-}" \
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.
Expand Down

0 comments on commit eeccfba

Please sign in to comment.