From 55ee4d9169de1accb8672abe252ff651afbc9e18 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 3 Jan 2024 17:53:17 +0000 Subject: [PATCH] Fix deprecated usage --- internal/icon/fdo.go | 14 +++++++------- internal/icon/fdo_test.go | 3 +-- internal/icon/macos.go | 3 +-- internal/ui/notifications.go | 2 +- internal/ui/switcher.go | 2 +- modules/status/battery_other.go | 7 +++---- modules/systray/main.go | 3 +-- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/internal/icon/fdo.go b/internal/icon/fdo.go index 2e7d3c34..66edeb49 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" @@ -124,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 @@ -154,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 } @@ -211,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" { @@ -270,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 "" } @@ -285,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 "" } @@ -424,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 } diff --git a/internal/icon/fdo_test.go b/internal/icon/fdo_test.go index 46a5c614..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" @@ -66,7 +65,7 @@ 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() diff --git a/internal/icon/macos.go b/internal/icon/macos.go index 9dcd0131..9202910a 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" @@ -109,7 +108,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/notifications.go b/internal/ui/notifications.go index a907ca75..e12f716d 100644 --- a/internal/ui/notifications.go +++ b/internal/ui/notifications.go @@ -23,7 +23,7 @@ type notification struct { func (n *notification) show(list *fyne.Container) { title := widget.NewLabel(n.message.Title) title.TextStyle = fyne.TextStyle{Bold: true} - title.Wrapping = fyne.TextTruncate + title.Truncation = fyne.TextTruncateEllipsis text := widget.NewLabel(n.message.Body) text.Wrapping = fyne.TextWrapWord n.renderer = container.NewVBox(title, text) diff --git a/internal/ui/switcher.go b/internal/ui/switcher.go index 637d3941..346ef16c 100644 --- a/internal/ui/switcher.go +++ b/internal/ui/switcher.go @@ -42,7 +42,7 @@ func (s *switchIcon) CreateRenderer() fyne.WidgetRenderer { bg.CornerRadius = theme.InputRadiusSize() img := canvas.NewImageFromResource(res) text := widget.NewLabelWithStyle(title, fyne.TextAlignCenter, fyne.TextStyle{}) - text.Wrapping = fyne.TextTruncate + text.Truncation = fyne.TextTruncateEllipsis return &switchIconRenderer{icon: s, bg: bg, img: img, text: text, objects: []fyne.CanvasObject{bg, img, text}} } 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 diff --git a/modules/systray/main.go b/modules/systray/main.go index 5552925b..08cf8f65 100644 --- a/modules/systray/main.go +++ b/modules/systray/main.go @@ -11,7 +11,6 @@ import ( "image" "image/color" "image/png" - "io/ioutil" "log" "os" "path/filepath" @@ -324,7 +323,7 @@ func (t *tray) updateIcon(i *node) { } else { fullPath = icon.FdoLookupIconPath("", 64, name) } - img, err := ioutil.ReadFile(fullPath) + img, err := os.ReadFile(fullPath) if err != nil { fyne.LogError("Failed to load status icon", err) i.ico.SetIcon(wmtheme.BrokenImageIcon)