Skip to content

Commit

Permalink
Simplify JSON code for Windows and ignore EOF
Browse files Browse the repository at this point in the history
This could happen as settings file writes, but we get another event on completion.

Fixes #1165
  • Loading branch information
andydotxyz committed Jul 21, 2020
1 parent 91bd741 commit ea960bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
3 changes: 2 additions & 1 deletion app/settings.go
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"io"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (s *settings) apply() {

func (s *settings) load() {
err := s.loadFromFile(s.schema.StoragePath())
if err != nil {
if err != nil && err != io.EOF { // we can get an EOF in windows settings writes
fyne.LogError("Settings load error:", err)
}

Expand Down
14 changes: 4 additions & 10 deletions cmd/fyne_settings/settings/appearance.go
Expand Up @@ -2,6 +2,7 @@ package settings

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -105,17 +106,10 @@ func (s *Settings) saveToFile(path string) error {
return err
}

file, err := os.Create(path)
data, err := json.Marshal(&s.fyneSettings)
if err != nil {
if !os.IsExist(err) {
return err
}
file, err = os.Open(path) // #nosec
if err != nil {
return err
}
return err
}
encode := json.NewEncoder(file)

return encode.Encode(&s.fyneSettings)
return ioutil.WriteFile(path, data, 0644)
}

0 comments on commit ea960bd

Please sign in to comment.