Skip to content

Commit

Permalink
Fix deprecated usage
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 3, 2024
1 parent 61ec176 commit 55ee4d9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
14 changes: 7 additions & 7 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 Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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 ""
}
Expand All @@ -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 ""
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 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 @@ -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()
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 @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down
7 changes: 3 additions & 4 deletions modules/status/battery_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package status

import (
"io/ioutil"
"os"
"strconv"
"strings"
Expand All @@ -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
}
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions modules/systray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"image"
"image/color"
"image/png"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 55ee4d9

Please sign in to comment.