Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions apps/finicky/src/browser/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,33 @@ func LaunchBrowser(config BrowserConfig, dryRun bool, openInBackgroundByDefault
return nil
}

// findBrowserInfo locates a browser in browsers.json by bundle ID, app name, or
// an app bundle path (e.g. "/Applications/Firefox.app"). For a path, the
// basename without the ".app" suffix is matched against the app name, so profile
// detection works for configs that specify the browser by path (appType
// "path"), not just by bundle ID or app name.
func findBrowserInfo(browsersJson []browserInfo, identifier string) *browserInfo {
base := identifier
if strings.HasSuffix(base, ".app") {
base = strings.TrimSuffix(filepath.Base(base), ".app")
}
for i := range browsersJson {
b := &browsersJson[i]
if b.ID == identifier || b.AppName == identifier || (base != "" && b.AppName == base) {
return b
}
}
return nil
}

func resolveBrowserProfileArgs(identifier string, profile string) ([]string, bool) {
var browsersJson []browserInfo
if err := json.Unmarshal(browsersJsonData, &browsersJson); err != nil {
slog.Info("Error parsing browsers.json", "error", err)
return nil, false
}

// Try to find matching browser by bundle ID
var matchedBrowser *browserInfo
for _, browser := range browsersJson {
if browser.ID == identifier || browser.AppName == identifier {
matchedBrowser = &browser
break
}
}

matchedBrowser := findBrowserInfo(browsersJson, identifier)
if matchedBrowser == nil {
return nil, false
}
Expand Down Expand Up @@ -347,14 +358,7 @@ func GetProfilesForBrowser(identifier string) []string {
return []string{}
}

var matchedBrowser *browserInfo
for i := range browsersJson {
if browsersJson[i].ID == identifier || browsersJson[i].AppName == identifier {
matchedBrowser = &browsersJson[i]
break
}
}

matchedBrowser := findBrowserInfo(browsersJson, identifier)
if matchedBrowser == nil {
return []string{}
}
Expand Down
46 changes: 46 additions & 0 deletions apps/finicky/src/browser/launcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package browser

import "testing"

func TestFindBrowserInfo(t *testing.T) {
browsers := []browserInfo{
{ConfigDirRelative: "Firefox", ID: "org.mozilla.firefox", AppName: "Firefox", Type: "Firefox"},
{ConfigDirRelative: "Firefox", ID: "org.mozilla.firefoxdeveloperedition", AppName: "Firefox Developer Edition", Type: "Firefox"},
{ConfigDirRelative: "zen", ID: "app.zen-browser.zen", AppName: "Zen", Type: "Firefox"},
{ConfigDirRelative: "Google/Chrome", ID: "com.google.Chrome", AppName: "Google Chrome", Type: "Chromium"},
}

cases := []struct {
name string
identifier string
wantID string // "" means expect no match
}{
{"by app name", "Firefox", "org.mozilla.firefox"},
{"by bundle id", "org.mozilla.firefox", "org.mozilla.firefox"},
{"by .app path", "/Applications/Firefox.app", "org.mozilla.firefox"},
{"by .app path with spaces", "/Applications/Firefox Developer Edition.app", "org.mozilla.firefoxdeveloperedition"},
{"zen by path", "/Applications/Zen.app", "app.zen-browser.zen"},
{"chromium by path", "/Applications/Google Chrome.app", "com.google.Chrome"},
{"unknown app name", "Safari", ""},
{"unknown path", "/Applications/Safari.app", ""},
{"path basename must not partial-match", "/Applications/Firefoxxx.app", ""},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := findBrowserInfo(browsers, c.identifier)
if c.wantID == "" {
if got != nil {
t.Fatalf("expected no match for %q, got %q", c.identifier, got.ID)
}
return
}
if got == nil {
t.Fatalf("expected match %q for %q, got nil", c.wantID, c.identifier)
}
if got.ID != c.wantID {
t.Fatalf("for %q: got %q, want %q", c.identifier, got.ID, c.wantID)
}
})
}
}
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ else
APP_NAME="Finicky.app"
# Rename arch build to plain Finicky.app
build_arch arm64
# Remove any stale bundle first; otherwise mv nests the new build inside it
# and (with set -e) aborts before installing, silently leaving the old app.
rm -rf apps/finicky/build/${APP_NAME}
mv apps/finicky/build/Finicky-arm64.app apps/finicky/build/${APP_NAME}
copy_assets ${APP_NAME}

Expand Down