diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 6949127f..db9a704a 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -7,12 +7,10 @@ jobs: checks: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: WillAbides/setup-go-faster@v1.13.0 with: - persist-credentials: false - - uses: WillAbides/setup-go-faster@v1.7.0 - with: - go-version: '1.17.x' + go-version: '1.19' - name: Get dependencies run: | @@ -20,7 +18,7 @@ jobs: go install golang.org/x/tools/cmd/goimports@latest go install github.com/fzipp/gocyclo/cmd/gocyclo@latest go install golang.org/x/lint/golint@latest - go install honnef.co/go/tools/cmd/staticcheck@v0.2.2 + go install honnef.co/go/tools/cmd/staticcheck@v0.4.6 - name: Cleanup repository run: rm -rf vendor/ @@ -38,4 +36,5 @@ jobs: run: golint -set_exit_status $(go list -tags ci ./...) - name: Staticcheck - run: staticcheck -go 1.17 ./... + run: staticcheck -go 1.19 ./... + diff --git a/go.mod b/go.mod index 27683bbb..6ca0c28c 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/FyshOS/backgrounds v0.0.0-20230616202904-0a8b6ebaa184 github.com/Knetic/govaluate v3.0.0+incompatible github.com/disintegration/imaging v1.6.2 - github.com/fyne-io/image v0.0.0-20221020213044-f609c6a24345 + github.com/fyne-io/image v0.0.0-20221020213044-f609c6a24345 // indirect github.com/godbus/dbus/v5 v5.1.0 github.com/jackmordaunt/icns v1.0.1-0.20200413110149-9e181b441ab2 github.com/mafik/pulseaudio v0.0.0-20200511091429-8449222912dd diff --git a/internal/icon/fdo.go b/internal/icon/fdo.go index 8f0a2d25..4d18e55c 100644 --- a/internal/icon/fdo.go +++ b/internal/icon/fdo.go @@ -2,7 +2,7 @@ package icon // import "fyshos.com/fynedesk/internal/icon" import ( "bufio" - "io/ioutil" + "io/fs" "math" "os" "os/exec" @@ -26,7 +26,7 @@ var ( "Office", "Science", "Settings", "System", "Utility"} ) -//fdoApplicationData is a structure that contains information about .desktop files +// fdoApplicationData is a structure that contains information about .desktop files type fdoApplicationData struct { name string // Application name iconName string // Icon name @@ -38,12 +38,12 @@ type fdoApplicationData struct { iconCache fyne.Resource } -//Name returns the name associated with an fdo app +// Name returns the name associated with an fdo app func (data *fdoApplicationData) Name() string { return data.name } -//Categories returns a list of the categories this icon has configured +// Categories returns a list of the categories this icon has configured func (data *fdoApplicationData) Categories() []string { return data.categories } @@ -52,12 +52,12 @@ func (data *fdoApplicationData) Hidden() bool { return data.hide } -//IconName returns the name of the icon that an fdo app wishes to use +// IconName returns the name of the icon that an fdo app wishes to use func (data *fdoApplicationData) IconName() string { return data.iconName } -//IconPath returns the path of the icon that an fdo app wishes to use +// IconPath returns the path of the icon that an fdo app wishes to use func (data *fdoApplicationData) Icon(theme string, size int) fyne.Resource { if data.iconCache != nil { return data.iconCache @@ -75,7 +75,7 @@ func (data *fdoApplicationData) Icon(theme string, size int) fyne.Resource { return data.iconCache } -//extractArgs sanitises argument parameters from an Exec configuration +// extractArgs sanitises argument parameters from an Exec configuration func extractArgs(args []string) []string { var ret []string for _, arg := range args { @@ -88,7 +88,7 @@ func extractArgs(args []string) []string { return ret } -//Run executes the command for this fdo app +// Run executes the command for this fdo app func (data *fdoApplicationData) Run(env []string) error { vars := os.Environ() vars = append(vars, env...) @@ -126,7 +126,7 @@ func (data fdoApplicationData) mainCategory() string { } func loadIcon(path string) fyne.Resource { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { fyne.LogError("Failed to load image", err) return nil @@ -135,7 +135,7 @@ func loadIcon(path string) fyne.Resource { return fyne.NewStaticResource(filepath.Base(path), data) } -//fdoLookupXdgDataDirs returns a string slice of all XDG_DATA_DIRS +// fdoLookupXdgDataDirs returns a string slice of all XDG_DATA_DIRS func fdoLookupXdgDataDirs() []string { dataLocation := os.Getenv("XDG_DATA_DIRS") locationLookup := strings.Split(dataLocation, ":") @@ -156,7 +156,7 @@ func fdoForEachApplicationFile(f func(data fynedesk.AppData) bool) { locationLookup := fdoLookupXdgDataDirs() for _, dataDir := range locationLookup { testLocation := filepath.Join(dataDir, "applications") - files, err := ioutil.ReadDir(testLocation) + files, err := os.ReadDir(testLocation) if err != nil { continue } @@ -177,7 +177,7 @@ func fdoForEachApplicationFile(f func(data fynedesk.AppData) bool) { } } -//lookupApplicationByMetadata looks up an application by comparing the requested name to the contents of .desktop files +// lookupApplicationByMetadata looks up an application by comparing the requested name to the contents of .desktop files func (f *fdoIconProvider) lookupApplicationByMetadata(appName string) fynedesk.AppData { var returnIcon fynedesk.AppData f.cache.forEachCachedApplication(func(_ string, icon fynedesk.AppData) bool { @@ -190,7 +190,7 @@ func (f *fdoIconProvider) lookupApplicationByMetadata(appName string) fynedesk.A return returnIcon } -//lookupApplication looks up an application by name and returns an fdoApplicationData struct +// lookupApplication looks up an application by name and returns an fdoApplicationData struct func (f *fdoIconProvider) lookupApplication(appName string) fynedesk.AppData { if appName == "" { return nil @@ -213,7 +213,7 @@ func (f *fdoIconProvider) lookupApplication(appName string) fynedesk.AppData { return f.lookupApplicationByMetadata(appName) } -func fdoClosestSizeIcon(files []os.FileInfo, iconSize int, format string, baseDir string, joiner string, iconName string) string { +func fdoClosestSizeIcon(files []fs.DirEntry, iconSize int, format string, baseDir string, joiner string, iconName string) string { var sizes []int for _, f := range files { if format == "32x32" { @@ -272,7 +272,7 @@ func fdoClosestSizeIcon(files []os.FileInfo, iconSize int, format string, baseDi } func lookupAnyIconSizeInThemeDir(dir string, joiner string, iconName string, iconSize int) string { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return "" } @@ -287,7 +287,7 @@ func lookupAnyIconSizeInThemeDir(dir string, joiner string, iconName string, ico } directory := filepath.Join(dir, joiner) - files, err = ioutil.ReadDir(directory) + files, err = os.ReadDir(directory) if err != nil { return "" } @@ -388,7 +388,7 @@ func FdoLookupIconPathInTheme(iconSize string, dir string, parentDir string, ico return "" } -//FdoLookupIconPath will take the name of an icon and find a matching image file +// FdoLookupIconPath will take the name of an icon and find a matching image file func FdoLookupIconPath(theme string, size int, iconName string) string { locationLookup := fdoLookupXdgDataDirs() iconTheme := theme @@ -426,7 +426,7 @@ func fdoLookupAvailableThemes() []string { var themes []string locationLookup := fdoLookupXdgDataDirs() for _, dataDir := range locationLookup { - files, err := ioutil.ReadDir(filepath.Join(dataDir, "icons")) + files, err := os.ReadDir(filepath.Join(dataDir, "icons")) if err != nil { continue } @@ -442,7 +442,7 @@ func fdoLookupAvailableThemes() []string { return themes } -//newFdoIconData creates and returns a struct that contains needed fields from a .desktop file +// newFdoIconData creates and returns a struct that contains needed fields from a .desktop file func newFdoIconData(desktopPath string) fynedesk.AppData { file, err := os.Open(desktopPath) if err != nil { @@ -495,7 +495,7 @@ type fdoIconProvider struct { cache *appCache } -//AvailableApps returns all of the available applications in a AppData slice +// AvailableApps returns all of the available applications in a AppData slice func (f *fdoIconProvider) AvailableApps() []fynedesk.AppData { var icons []fynedesk.AppData fdoForEachApplicationFile(func(icon fynedesk.AppData) bool { @@ -508,17 +508,17 @@ func (f *fdoIconProvider) AvailableApps() []fynedesk.AppData { return icons } -//AvailableThemes returns all available icon themes in a string slice +// AvailableThemes returns all available icon themes in a string slice func (f *fdoIconProvider) AvailableThemes() []string { return fdoLookupAvailableThemes() } -//FindAppFromName matches an icon name to a location and returns an AppData interface +// FindAppFromName matches an icon name to a location and returns an AppData interface func (f *fdoIconProvider) FindAppFromName(appName string) fynedesk.AppData { return f.lookupApplication(appName) } -//FindAppsMatching returns a list of icons that match a partial name of an app and returns an AppData slice +// FindAppsMatching returns a list of icons that match a partial name of an app and returns an AppData slice func (f *fdoIconProvider) FindAppsMatching(appName string) []fynedesk.AppData { var icons []fynedesk.AppData f.cache.forEachCachedApplication(func(_ string, icon fynedesk.AppData) bool { @@ -536,7 +536,7 @@ func (f *fdoIconProvider) FindAppsMatching(appName string) []fynedesk.AppData { return icons } -//FindAppFromWinInfo matches window information to an icon location and returns an AppData interface +// FindAppFromWinInfo matches window information to an icon location and returns an AppData interface func (f *fdoIconProvider) FindAppFromWinInfo(win fynedesk.Window) fynedesk.AppData { app := f.lookupApplication(win.Properties().Command()) if app != nil { diff --git a/internal/icon/fdo_test.go b/internal/icon/fdo_test.go index 2e3c608d..f785bd3f 100644 --- a/internal/icon/fdo_test.go +++ b/internal/icon/fdo_test.go @@ -2,7 +2,6 @@ package icon import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -36,21 +35,21 @@ func setTestEnv(t *testing.T) { } } -//applications/app1.desktop and icons/default_theme/apps/32x32/app1.png +// applications/app1.desktop and icons/default_theme/apps/32x32/app1.png func TestFdoLookupDefaultTheme(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app1") assert.Equal(t, true, exists(data)) } -//applications/com.fyne.app.desktop and icons/default_theme/apps/scalable/app2.svg +// applications/com.fyne.app.desktop and icons/default_theme/apps/scalable/app2.svg func TestFdoFileNameMisMatchAndScalable(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app2") assert.Equal(t, true, exists(data)) } -//check the category from app1 +// check the category from app1 func TestFdoIconCategory(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app1") @@ -61,12 +60,12 @@ func TestFdoIconCategory(t *testing.T) { assert.Equal(t, "Utility", data.(*fdoApplicationData).mainCategory()) } -//applications/app3.desktop and applications/app3.png +// applications/app3.desktop and applications/app3.png func TestFdoIconNameIsPath(t *testing.T) { setTestEnv(t) dataLocation := os.Getenv("XDG_DATA_DIRS") output := fmt.Sprintf("[Desktop Entry]\nName=App3\nExec=app3\nIcon=%s\n", filepath.Join(dataLocation, "icons", "app3.png")) - err := ioutil.WriteFile(filepath.Join(dataLocation, "applications", "app3.desktop"), []byte(output), 0644) + err := os.WriteFile(filepath.Join(dataLocation, "applications", "app3.desktop"), []byte(output), 0644) if err != nil { fyne.LogError("Could not create desktop for Icon Name path example", err) t.FailNow() @@ -75,56 +74,56 @@ func TestFdoIconNameIsPath(t *testing.T) { assert.Equal(t, true, exists(data)) } -//check NoDisplay from app4 +// check NoDisplay from app4 func TestFdoIconHide(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app4") assert.Equal(t, true, data.Hidden()) } -//applications/app4.desktop and pixmaps/app4.png +// applications/app4.desktop and pixmaps/app4.png func TestFdoIconInPixmaps(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app4") assert.Equal(t, true, exists(data)) } -//applications/app5.desktop and icons/hicolor/32x32/apps/app5.png +// applications/app5.desktop and icons/hicolor/32x32/apps/app5.png func TestFdoIconHicolorFallback(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app5") assert.Equal(t, true, exists(data)) } -//applications/app6.desktop and icons/hicolor/scalable/apps/app6.svg +// applications/app6.desktop and icons/hicolor/scalable/apps/app6.svg func TestFdoIconHicolorFallbackScalable(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app6") assert.Equal(t, true, exists(data)) } -//applications/app7.desktop and icons/default_theme/apps/16x16/app7.png +// applications/app7.desktop and icons/default_theme/apps/16x16/app7.png func TestFdoLookupDefaultThemeDifferentSize(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app7") assert.Equal(t, true, exists(data)) } -//applications/app8.desktop and icons/third_theme/apps/32/app8.png +// applications/app8.desktop and icons/third_theme/apps/32/app8.png func TestFdoLookupAnyThemeFallback(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app8") assert.Equal(t, true, exists(data)) } -//applications/xterm.desktop and icons/third_theme/emblems/16x16/app9.png +// applications/xterm.desktop and icons/third_theme/emblems/16x16/app9.png func TestFdoLookupIconNotInApps(t *testing.T) { setTestEnv(t) data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("xterm") assert.Equal(t, true, exists(data)) } -//missing - not able to match +// missing - not able to match func TestFdoLookupMissing(t *testing.T) { setTestEnv(t) provider := NewFDOIconProvider() diff --git a/internal/icon/macos.go b/internal/icon/macos.go index 7403bd6b..99ef8c15 100644 --- a/internal/icon/macos.go +++ b/internal/icon/macos.go @@ -4,7 +4,6 @@ import ( "bytes" _ "image/jpeg" // support JPEG images "image/png" // PNG support is required as we use it directly - "io/ioutil" "os" "os/exec" "path/filepath" @@ -110,7 +109,7 @@ type macOSAppProvider struct { func (m *macOSAppProvider) forEachApplication(f func(name, path, category string) bool) { for _, root := range m.rootDirs { category := filepath.Base(root) - files, err := ioutil.ReadDir(root) + files, err := os.ReadDir(root) if err != nil { fyne.LogError("Could not read applications directory "+root, err) return diff --git a/internal/ui/baricon.go b/internal/ui/baricon.go index 29b11dde..7e3aa818 100644 --- a/internal/ui/baricon.go +++ b/internal/ui/baricon.go @@ -82,7 +82,7 @@ type barIcon struct { windowData *appWindow // The window data associated with this icon (if it is a task window) } -//Tapped means barIcon has been clicked +// Tapped means barIcon has been clicked func (bi *barIcon) Tapped(*fyne.PointEvent) { bi.onTapped() } @@ -112,7 +112,7 @@ func removeFromBar(icon fynedesk.AppData) { settings.(*deskSettings).setLauncherIcons(icons) } -//TappedSecondary means barIcon has been clicked by a secondary binding +// TappedSecondary means barIcon has been clicked by a secondary binding func (bi *barIcon) TappedSecondary(*fyne.PointEvent) { app := bi.appData if app == nil && bi.windowData != nil { diff --git a/internal/ui/barlayout.go b/internal/ui/barlayout.go index 6e7fdd10..63d9d953 100644 --- a/internal/ui/barlayout.go +++ b/internal/ui/barlayout.go @@ -18,7 +18,7 @@ const ( separatorWidth = 2 ) -//barLayout returns a layout used for zooming linear groups of icons +// barLayout returns a layout used for zooming linear groups of icons type barLayout struct { bar *bar @@ -26,12 +26,12 @@ type barLayout struct { mousePosition fyne.Position // Current coordinates of the mouse cursor } -//setPointerInside tells the barLayout that the mouse is inside of the Layout. +// setPointerInside tells the barLayout that the mouse is inside of the Layout. func (bl *barLayout) setPointerInside(inside bool) { bl.mouseInside = inside } -//setPointerPosition tells the barLayout that the mouse position has been updated. +// setPointerPosition tells the barLayout that the mouse position has been updated. func (bl *barLayout) setPointerPosition(position fyne.Position) { bl.mousePosition = position } diff --git a/modules/status/battery_other.go b/modules/status/battery_other.go index 20f1d738..0089bd40 100644 --- a/modules/status/battery_other.go +++ b/modules/status/battery_other.go @@ -4,7 +4,6 @@ package status import ( - "io/ioutil" "os" "strconv" "strings" @@ -13,7 +12,7 @@ import ( ) func (b *battery) powered() (bool, error) { - status, err := ioutil.ReadFile("/sys/class/power_supply/BAT0/status") + status, err := os.ReadFile("/sys/class/power_supply/BAT0/status") if err != nil { return true, err // assume power if no battery info } @@ -23,11 +22,11 @@ func (b *battery) powered() (bool, error) { func (b *battery) value() (float64, error) { nowFile, fullFile := pickChargeOrEnergy() - fullStr, err1 := ioutil.ReadFile(fullFile) + fullStr, err1 := os.ReadFile(fullFile) if os.IsNotExist(err1) { return 0, err1 // return quietly if the file was not present (desktop?) } - nowStr, err2 := ioutil.ReadFile(nowFile) + nowStr, err2 := os.ReadFile(nowFile) if err1 != nil || err2 != nil { fyne.LogError("Error reading battery info", err1) return 0, err1