Rules-based browser launcher for TUI + GNOME. switchyard.aly.codes
tui gome bowser go
0

Configure Feed

Select the types of activity you want to include in your feed.

cmd/sw: move ListDesktopActions to browserscan package

Aly Raffauf (Jul 5, 2026, 10:50 PM EDT) a4d0dc02 3bc82478

+40 -43
+2 -1
cmd/sw/model.go
··· 10 10 tea "charm.land/bubbletea/v2" 11 11 "charm.land/lipgloss/v2" 12 12 "github.com/alyraffauf/switchyard/internal/browser" 13 + "github.com/alyraffauf/switchyard/internal/browserscan" 13 14 "github.com/alyraffauf/switchyard/internal/host" 14 15 ) 15 16 ··· 138 139 if !ok { 139 140 return m, nil, true 140 141 } 141 - actions := browser.ListDesktopActions(selected.id) 142 + actions := browserscan.ListDesktopActions(selected.id) 142 143 if len(actions) == 0 { 143 144 return m, nil, true 144 145 }
+1 -23
internal/browser/actions.go
··· 2 2 3 3 package browser 4 4 5 - import ( 6 - "github.com/alyraffauf/goxdgdesktop/desktopfile" 7 - "github.com/alyraffauf/goxdgdesktop/xdg" 8 - ) 5 + import "github.com/alyraffauf/goxdgdesktop/desktopfile" 9 6 10 7 // Action is a desktop-entry action, e.g. "new-private-window". 11 8 type Action = desktopfile.Action 12 - 13 - // ListDesktopActions returns the actions declared in appID's desktop entry. 14 - // It returns nil when the desktop file is missing or cannot be parsed. 15 - func ListDesktopActions(appID string) []Action { 16 - if appID == "" { 17 - return nil 18 - } 19 - 20 - desktopFilePath := xdg.FindDesktopFile(appID) 21 - if desktopFilePath == "" { 22 - return nil 23 - } 24 - 25 - file, err := desktopfile.Read(desktopFilePath) 26 - if err != nil { 27 - return nil 28 - } 29 - return LocalizedActions(file) 30 - }
+5 -6
internal/browser/locale.go internal/browserscan/locale.go
··· 1 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 2 3 - package browser 3 + package browserscan 4 4 5 5 import ( 6 6 "os" 7 7 "strings" 8 8 9 9 "github.com/alyraffauf/goxdgdesktop/desktopfile" 10 + "github.com/alyraffauf/switchyard/internal/browser" 10 11 ) 11 12 12 - // LocalizedString resolves key for the current Desktop Entry locale. 13 - func LocalizedString(file *desktopfile.File, section, key string) string { 13 + func localizedString(file *desktopfile.File, section, key string) string { 14 14 for _, candidate := range localeKeyCandidates(key) { 15 15 if value, ok := file.Get(section, candidate); ok && value != "" { 16 16 return value ··· 19 19 return "" 20 20 } 21 21 22 - // LocalizedActions resolves each action name for the current locale. 23 - func LocalizedActions(file *desktopfile.File) []Action { 22 + func localizedActions(file *desktopfile.File) []browser.Action { 24 23 actions := file.Actions() 25 24 for i := range actions { 26 25 section := desktopfile.ActionSectionStart + actions[i].ID 27 - if name := LocalizedString(file, section, "Name"); name != "" { 26 + if name := localizedString(file, section, "Name"); name != "" { 28 27 actions[i].Name = name 29 28 } 30 29 }
+4 -11
internal/browser/locale_test.go internal/browserscan/locale_test.go
··· 1 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 2 3 - package browser 3 + package browserscan 4 4 5 5 import ( 6 6 "testing" ··· 21 21 Exec=browser --new-window %u 22 22 ` 23 23 24 - func clearLocaleEnv(t *testing.T) { 25 - t.Helper() 26 - for _, env := range []string{"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG"} { 27 - t.Setenv(env, "") 28 - } 29 - } 30 - 31 24 func TestLocalizedStringFallback(t *testing.T) { 32 25 file := desktopfile.Parse([]byte(localeEntry)) 33 26 ··· 48 41 if tt.lang != "" { 49 42 t.Setenv("LANG", tt.lang) 50 43 } 51 - if got := LocalizedString(file, desktopfile.EntrySection, "Name"); got != tt.want { 44 + if got := localizedString(file, desktopfile.EntrySection, "Name"); got != tt.want { 52 45 t.Errorf("got %q, want %q", got, tt.want) 53 46 } 54 47 }) ··· 61 54 t.Setenv("LANGUAGE", "de:fr") 62 55 63 56 file := desktopfile.Parse([]byte(localeEntry)) 64 - if got := LocalizedString(file, desktopfile.EntrySection, "Name"); got != "Navigateur Web" { 57 + if got := localizedString(file, desktopfile.EntrySection, "Name"); got != "Navigateur Web" { 65 58 t.Errorf("got %q, want %q", got, "Navigateur Web") 66 59 } 67 60 } ··· 71 64 t.Setenv("LANG", "fr_FR.UTF-8") 72 65 73 66 file := desktopfile.Parse([]byte(localeEntry)) 74 - actions := LocalizedActions(file) 67 + actions := localizedActions(file) 75 68 if len(actions) != 1 { 76 69 t.Fatalf("got %d actions, want 1", len(actions)) 77 70 }
+26
internal/browserscan/actions.go
··· 1 + // SPDX-License-Identifier: GPL-3.0-or-later 2 + 3 + package browserscan 4 + 5 + import ( 6 + "github.com/alyraffauf/goxdgdesktop/desktopfile" 7 + "github.com/alyraffauf/goxdgdesktop/xdg" 8 + "github.com/alyraffauf/switchyard/internal/browser" 9 + ) 10 + 11 + func ListDesktopActions(appID string) []browser.Action { 12 + if appID == "" { 13 + return nil 14 + } 15 + 16 + desktopFilePath := xdg.FindDesktopFile(appID) 17 + if desktopFilePath == "" { 18 + return nil 19 + } 20 + 21 + file, err := desktopfile.Read(desktopFilePath) 22 + if err != nil { 23 + return nil 24 + } 25 + return localizedActions(file) 26 + }
+2 -2
internal/browserscan/browserscan.go
··· 105 105 106 106 return browser.Browser{ 107 107 ID: id, 108 - Name: browser.LocalizedString(file, desktopfile.EntrySection, "Name"), 108 + Name: localizedString(file, desktopfile.EntrySection, "Name"), 109 109 Icon: icon, 110 110 Exec: exec, 111 - Actions: browser.LocalizedActions(file), 111 + Actions: localizedActions(file), 112 112 }, true 113 113 } 114 114