Skip to content

Commit

Permalink
Replace empty interface with any type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 2, 2024
1 parent 78f2326 commit 215bb43
Show file tree
Hide file tree
Showing 51 changed files with 227 additions and 227 deletions.
2 changes: 1 addition & 1 deletion app/app_theme_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func defaultVariant() fyne.ThemeVariant {

func init() {
if matchMedia := js.Global().Call("matchMedia", "(prefers-color-scheme: dark)"); matchMedia.Truthy() {
matchMedia.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
matchMedia.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
fyne.CurrentApp().Settings().(*settings).setupTheme()
return nil
}))
Expand Down
8 changes: 4 additions & 4 deletions app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p *preferences) saveToFile(path string) error {
defer file.Close()
encode := json.NewEncoder(file)

p.InMemoryPreferences.ReadValues(func(values map[string]interface{}) {
p.InMemoryPreferences.ReadValues(func(values map[string]any) {
err = encode.Encode(&values)
})

Expand Down Expand Up @@ -120,7 +120,7 @@ func (p *preferences) loadFromFile(path string) (err error) {
p.loadingInProgress = true
p.prefLock.Unlock()

p.InMemoryPreferences.WriteValues(func(values map[string]interface{}) {
p.InMemoryPreferences.WriteValues(func(values map[string]any) {
err = decode.Decode(&values)
if err != nil {
return
Expand Down Expand Up @@ -170,9 +170,9 @@ func newPreferences(app *fyneApp) *preferences {
return p
}

func convertLists(values map[string]interface{}) {
func convertLists(values map[string]any) {
for k, v := range values {
if items, ok := v.([]interface{}); ok {
if items, ok := v.([]any); ok {
if len(items) == 0 {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions app/preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func loadPreferences(id string) *preferences {

func TestPreferences_Remove(t *testing.T) {
p := loadPreferences("dummy")
p.WriteValues(func(val map[string]interface{}) {
p.WriteValues(func(val map[string]any) {
val["keyString"] = "value"
val["keyInt"] = 4
})
Expand All @@ -34,7 +34,7 @@ func TestPreferences_Remove(t *testing.T) {

func TestPreferences_Save(t *testing.T) {
p := loadPreferences("dummy")
p.WriteValues(func(val map[string]interface{}) {
p.WriteValues(func(val map[string]any) {
val["keyString"] = "value"
val["keyStringList"] = []string{"1", "2", "3"}
val["keyInt"] = 4
Expand Down Expand Up @@ -68,15 +68,15 @@ func TestPreferences_Save(t *testing.T) {

func TestPreferences_Save_OverwriteFast(t *testing.T) {
p := loadPreferences("dummy2")
p.WriteValues(func(val map[string]interface{}) {
p.WriteValues(func(val map[string]any) {
val["key"] = "value"
})

path := filepath.Join(os.TempDir(), "fynePrefs2.json")
defer os.Remove(path)
p.saveToFile(path)

p.WriteValues(func(val map[string]interface{}) {
p.WriteValues(func(val map[string]any) {
val["key2"] = "value2"
})
p.saveToFile(path)
Expand Down
6 changes: 3 additions & 3 deletions app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type settings struct {
themeSpecified bool
variant fyne.ThemeVariant

changeListeners sync.Map // map[chan fyne.Settings]bool
watcher interface{} // normally *fsnotify.Watcher or nil - avoid import in this file
changeListeners sync.Map // map[chan fyne.Settings]bool
watcher any // normally *fsnotify.Watcher or nil - avoid import in this file

schema SettingsSchema
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *settings) AddChangeListener(listener chan fyne.Settings) {
}

func (s *settings) apply() {
s.changeListeners.Range(func(key, _ interface{}) bool {
s.changeListeners.Range(func(key, _ any) bool {
listener := key.(chan fyne.Settings)
select {
case listener <- s:
Expand Down
4 changes: 2 additions & 2 deletions app/settings_desktop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestWatchFile(t *testing.T) {
f.Close()
defer os.Remove(path)

called := make(chan interface{}, 1)
called := make(chan any, 1)
watchFile(path, func() {
called <- true
})
Expand All @@ -66,7 +66,7 @@ func TestFileWatcher_FileDeleted(t *testing.T) {
f.Close()
defer os.Remove(path)

called := make(chan interface{}, 1)
called := make(chan any, 1)
watcher := watchFile(path, func() {
called <- true
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/mock_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type expectedValue struct {
dir interface{}
dir any
env []string
osEnv bool
args []string
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (r *Releaser) validate() error {
return nil
}

func (r *Releaser) writeEntitlements(tmpl *template.Template, entitlementData interface{}) (cleanup func(), err error) {
func (r *Releaser) writeEntitlements(tmpl *template.Template, entitlementData any) (cleanup func(), err error) {
entitlementPath := filepath.Join(r.dir, "entitlements.plist")
entitlements, err := os.Create(entitlementPath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func extractPkgs(nm string, path string) (map[string]bool, error) {

var xout io.Writer = os.Stderr

func printcmd(format string, args ...interface{}) {
func printcmd(format string, args ...any) {
cmd := fmt.Sprintf(format+"\n", args...)
if tmpdir != "" {
cmd = strings.Replace(cmd, tmpdir, "$WORK", -1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/fyne_demo/tutorials/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
progress *widget.ProgressBar
fprogress *widget.ProgressBar
infProgress *widget.ProgressBarInfinite
endProgress chan interface{}
endProgress chan any
)

func makeAccordionTab(_ fyne.Window) fyne.CanvasObject {
Expand Down Expand Up @@ -377,7 +377,7 @@ func makeProgressTab(_ fyne.Window) fyne.CanvasObject {
}

infProgress = widget.NewProgressBarInfinite()
endProgress = make(chan interface{}, 1)
endProgress = make(chan any, 1)
startProgress()

return container.NewVBox(
Expand Down
28 changes: 14 additions & 14 deletions data/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ func (b *base) RemoveListener(l DataListener) {
}

func (b *base) trigger() {
b.listeners.Range(func(key, _ interface{}) bool {
b.listeners.Range(func(key, _ any) bool {
queueItem(key.(DataListener).DataChanged)
return true
})
}

// Untyped supports binding a interface{} value.
// Untyped supports binding a any value.
//
// Since: 2.1
type Untyped interface {
DataItem
Get() (interface{}, error)
Set(interface{}) error
Get() (any, error)
Set(any) error
}

// NewUntyped returns a bindable interface{} value that is managed internally.
// NewUntyped returns a bindable any value that is managed internally.
//
// Since: 2.1
func NewUntyped() Untyped {
var blank interface{} = nil
var blank any = nil
v := &blank
return &boundUntyped{val: reflect.ValueOf(v).Elem()}
}
Expand All @@ -104,14 +104,14 @@ type boundUntyped struct {
val reflect.Value
}

func (b *boundUntyped) Get() (interface{}, error) {
func (b *boundUntyped) Get() (any, error) {
b.lock.RLock()
defer b.lock.RUnlock()

return b.val.Interface(), nil
}

func (b *boundUntyped) Set(val interface{}) error {
func (b *boundUntyped) Set(val any) error {
b.lock.Lock()
defer b.lock.Unlock()
if b.val.Interface() == val {
Expand All @@ -124,27 +124,27 @@ func (b *boundUntyped) Set(val interface{}) error {
return nil
}

// ExternalUntyped supports binding a interface{} value to an external value.
// ExternalUntyped supports binding a any value to an external value.
//
// Since: 2.1
type ExternalUntyped interface {
Untyped
Reload() error
}

// BindUntyped returns a bindable interface{} value that is bound to an external type.
// BindUntyped returns a bindable any value that is bound to an external type.
// The parameter must be a pointer to the type you wish to bind.
//
// Since: 2.1
func BindUntyped(v interface{}) ExternalUntyped {
func BindUntyped(v any) ExternalUntyped {
t := reflect.TypeOf(v)
if t.Kind() != reflect.Ptr {
fyne.LogError("Invalid type passed to BindUntyped, must be a pointer", nil)
v = nil
}

if v == nil {
var blank interface{}
var blank any
v = &blank // never allow a nil value pointer
}

Expand All @@ -157,10 +157,10 @@ func BindUntyped(v interface{}) ExternalUntyped {
type boundExternalUntyped struct {
boundUntyped

old interface{}
old any
}

func (b *boundExternalUntyped) Set(val interface{}) error {
func (b *boundExternalUntyped) Set(val any) error {
b.lock.Lock()
defer b.lock.Unlock()
if b.old == val {
Expand Down
2 changes: 1 addition & 1 deletion data/binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func syncMapLen(m *sync.Map) (n int) {
m.Range(func(_, _ interface{}) bool {
m.Range(func(_, _ any) bool {
n++
return true
})
Expand Down
2 changes: 1 addition & 1 deletion data/binding/binditems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestBindFloat(t *testing.T) {
}

func TestBindUntyped(t *testing.T) {
var val interface{}
var val any
val = 0.5
f := BindUntyped(&val)
v, err := f.Get()
Expand Down
Loading

0 comments on commit 215bb43

Please sign in to comment.