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 18, 2024
1 parent e1e753b commit 1d1c5cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
14 changes: 7 additions & 7 deletions internal/icon/fdo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"bytes"
"image/png"
"io/ioutil"
"io/fs"
"math"
"os"
"os/exec"
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 Down Expand Up @@ -169,7 +169,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 @@ -226,7 +226,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 @@ -285,7 +285,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 @@ -300,7 +300,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 @@ -438,7 +438,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 @@ -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
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

0 comments on commit 1d1c5cb

Please sign in to comment.