Skip to content

Commit

Permalink
Merge branch 'develop' into feature/desktopfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 5, 2024
2 parents 66404e8 + 55ee4d9 commit 9021568
Show file tree
Hide file tree
Showing 24 changed files with 377 additions and 223 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/platform_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: ['1.17', '1.20']
go-version: ['1.19', '1.21']
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: WillAbides/setup-go-faster@v1.7.0
- uses: WillAbides/setup-go-faster@v1.13.0
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -41,4 +41,4 @@ jobs:
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
if: ${{ runner.os == 'Linux' && matrix.go-version == '1.17' }}
if: ${{ runner.os == 'Linux' && matrix.go-version == '1.19' }}
10 changes: 5 additions & 5 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: WillAbides/setup-go-faster@v1.7.0
- uses: WillAbides/setup-go-faster@v1.13.0
with:
go-version: '1.17.x'
go-version: '1.21.x'

- 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 +38,4 @@ jobs:
run: golint -set_exit_status $(go list -tags ci ./...)

- name: Staticcheck
run: staticcheck -go 1.17 ./...
run: staticcheck -go 1.19 ./...
56 changes: 27 additions & 29 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 @@ -13,8 +13,6 @@ import (
"fyne.io/fyne/v2"

"fyshos.com/fynedesk"
wmTheme "fyshos.com/fynedesk/theme"

_ "github.com/fyne-io/image/xpm" // load XPM icons to supported image format
)

Expand All @@ -26,7 +24,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 +36,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 +50,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 @@ -67,15 +65,15 @@ func (data *fdoApplicationData) Icon(theme string, size int) fyne.Resource {
if path == "" {
path = FdoLookupIconPath(theme, size, data.iconName)
if path == "" {
return wmTheme.BrokenImageIcon
return nil
}
}

data.iconCache = loadIcon(path)
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 +86,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 +124,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 +133,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 +154,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 +175,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 +188,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 +211,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 +270,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 +285,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 @@ -362,8 +360,8 @@ func FdoLookupIconPathInTheme(iconSize string, dir string, parentDir string, ico
}
if len(inheritedThemes) > 0 {
for _, theme := range inheritedThemes {
dir = filepath.Join(parentDir, "icons", theme)
iconPath := FdoLookupIconPathInTheme(iconSize, dir, parentDir, iconName)
childDir := filepath.Join(parentDir, "icons", theme)
iconPath := FdoLookupIconPathInTheme(iconSize, childDir, parentDir, iconName)
if iconPath != "" {
return iconPath
}
Expand All @@ -388,7 +386,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 +424,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 +440,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 +493,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 +506,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 +534,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
Loading

0 comments on commit 9021568

Please sign in to comment.