Skip to content

Commit

Permalink
update custom browser logic to handle custom cases for google chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
meyerjrr committed Sep 18, 2024
1 parent 1568c38 commit 77b2a2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/assume/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func GetCliApp() *cli.App {
if err != nil {
return err
}

if !hasSetup {
browserName, err := browser.HandleBrowserWizard(c)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func Load() (*Config, error) {
_, err = toml.NewDecoder(file).Decode(&c)
if err != nil {
// if there is an error just reset the file
return &c, nil
return nil, err
}
return &c, nil
}
Expand Down
24 changes: 23 additions & 1 deletion pkg/launcher/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package launcher
import (
"errors"
"fmt"
"regexp"
"strings"
"text/template"

Expand Down Expand Up @@ -52,10 +53,31 @@ func (l Custom) LaunchCommand(url string, profile string) ([]string, error) {
return nil, fmt.Errorf("executing command template (check that your browser launch template is valid in your Granted config): %w", err)
}

commandParts := strings.Fields(renderedCommand.String())
commandParts := splitCommand(renderedCommand.String())
return commandParts, nil
}

// splits each component of the command. Anything within quotes will be handled as one component of the command
// eg open -a "Google Chrome" <URL> returns ["open", "-a", "Google Chrome", "<URL>"]
func splitCommand(command string) []string {

re := regexp.MustCompile(`"([^"]+)"|(\S+)`)
matches := re.FindAllStringSubmatch(command, -1)

var result []string
for _, match := range matches {

if match[1] != "" {
result = append(result, match[1])
} else {

result = append(result, match[2])
}
}

return result
}

func (l Custom) UseForkProcess() bool { return l.ForkProcess }

var ErrLaunchTemplateNotConfigured = errors.New("launch template is not configured")
Expand Down

0 comments on commit 77b2a2a

Please sign in to comment.