Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 18, 2024
2 parents 46aed46 + 1d1c5cb commit 1257b86
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 57 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: WillAbides/[email protected]
with:
persist-credentials: false
- uses: WillAbides/[email protected]
with:
go-version: '1.17.x'
go-version: '1.19'

- name: Get dependencies
run: |
sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev
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/
Expand All @@ -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 ./...

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions internal/icon/fdo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package icon // import "fyshos.com/fynedesk/internal/icon"

import (
"bufio"
"io/ioutil"
"io/fs"
"math"
"os"
"os/exec"
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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...)
Expand Down Expand Up @@ -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
Expand All @@ -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, ":")
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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" {
Expand Down Expand Up @@ -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 ""
}
Expand All @@ -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 ""
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
27 changes: 13 additions & 14 deletions internal/icon/fdo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package icon

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions internal/icon/macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/baricon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 1257b86

Please sign in to comment.