Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin using new APIs between Go 1.17 and 1.19 #4488

Merged
merged 22 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,11 @@ type App interface {
SetCloudProvider(CloudProvider) // configure cloud for this app
}

// app contains an App variable, but due to atomic.Value restrictions on
// interfaces we need to use an indirect type, i.e. appContainer.
var app atomic.Value // appContainer

// appContainer is a dummy container that holds an App instance. This
// struct exists to guarantee that atomic.Value can store objects with
// same type.
type appContainer struct {
current App
}
var app atomic.Pointer[App]

// SetCurrentApp is an internal function to set the app instance currently running.
func SetCurrentApp(current App) {
app.Store(appContainer{current})
app.Store(&current)
}

// CurrentApp returns the current application, for which there is only 1 per process.
Expand All @@ -104,7 +95,7 @@ func CurrentApp() App {
LogError("Attempt to access current Fyne app when none is started", nil)
return nil
}
return (val).(appContainer).current
return *val
}

// AppMetadata captures the build metadata for an application.
Expand Down
4 changes: 2 additions & 2 deletions app/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ void sendNotification(char *title, char *content);
import "C"
import (
"fmt"
"os/exec"
"strings"
"unsafe"

"fyne.io/fyne/v2"
"golang.org/x/sys/execabs"
)

func (a *fyneApp) SendNotification(n *fyne.Notification) {
Expand Down Expand Up @@ -53,7 +53,7 @@ func fallbackNotification(title, content string) {
template := `display notification "%s" with title "%s"`
script := fmt.Sprintf(template, escapeNotificationString(content), escapeNotificationString(title))

err := execabs.Command("osascript", "-e", script).Start()
err := exec.Command("osascript", "-e", script).Start()
if err != nil {
fyne.LogError("Failed to launch darwin notify script", err)
}
Expand Down
5 changes: 2 additions & 3 deletions app/app_desktop_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import "C"
import (
"net/url"
"os"
"os/exec"
"path/filepath"

"golang.org/x/sys/execabs"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
Expand Down Expand Up @@ -54,7 +53,7 @@ func rootConfigDir() string {
}

func (a *fyneApp) OpenURL(url *url.URL) error {
cmd := execabs.Command("open", url.String())
cmd := exec.Command("open", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
return cmd.Run()
}
Expand Down
6 changes: 3 additions & 3 deletions app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"

"golang.org/x/sys/execabs"
"golang.org/x/sys/windows/registry"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -62,7 +62,7 @@ func rootConfigDir() string {
}

func (a *fyneApp) OpenURL(url *url.URL) error {
cmd := execabs.Command("rundll32", "url.dll,FileProtocolHandler", url.String())
cmd := exec.Command("rundll32", "url.dll,FileProtocolHandler", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
return cmd.Run()
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func runScript(name, script string) {
defer os.Remove(tmpFilePath)

launch := "(Get-Content -Encoding UTF8 -Path " + tmpFilePath + " -Raw) | Invoke-Expression"
cmd := execabs.Command("PowerShell", "-ExecutionPolicy", "Bypass", launch)
cmd := exec.Command("PowerShell", "-ExecutionPolicy", "Bypass", launch)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
err = cmd.Run()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/app_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package app
import (
"net/url"
"os"
"os/exec"
"path/filepath"
"sync"

"github.com/godbus/dbus/v5"
"github.com/rymdport/portal/notification"
"github.com/rymdport/portal/openuri"
"golang.org/x/sys/execabs"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/build"
Expand All @@ -38,7 +38,7 @@ func (a *fyneApp) OpenURL(url *url.URL) error {
return err
}

cmd := execabs.Command("xdg-open", url.String())
cmd := exec.Command("xdg-open", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
return cmd.Start()
}
Expand Down
11 changes: 4 additions & 7 deletions data/binding/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type prefBound{{ .Name }} struct {
base
key string
p fyne.Preferences
cache atomic.Value // {{ .Type }}
cache atomic.Pointer[{{ .Type }}]
}

// BindPreference{{ .Name }} returns a bindable {{ .Type }} value that is managed by the application preferences.
Expand All @@ -148,7 +148,7 @@ func BindPreference{{ .Name }}(key string, p fyne.Preferences) {{ .Name }} {

func (b *prefBound{{ .Name }}) Get() ({{ .Type }}, error) {
cache := b.p.{{ .Name }}(b.key)
b.cache.Store(cache)
b.cache.Store(&cache)
return cache, nil
}

Expand All @@ -163,11 +163,8 @@ func (b *prefBound{{ .Name }}) Set(v {{ .Type }}) error {

func (b *prefBound{{ .Name }}) checkForChange() {
val := b.cache.Load()
if val != nil {
cache := val.({{ .Type }})
if b.p.{{ .Name }}(b.key) == cache {
return
}
if val != nil && b.p.{{ .Name }}(b.key) == *val {
return
}
b.trigger()
}
Expand Down
44 changes: 16 additions & 28 deletions data/binding/preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type prefBoundBool struct {
base
key string
p fyne.Preferences
cache atomic.Value // bool
cache atomic.Pointer[bool]
}

// BindPreferenceBool returns a bindable bool value that is managed by the application preferences.
Expand All @@ -41,7 +41,7 @@ func BindPreferenceBool(key string, p fyne.Preferences) Bool {

func (b *prefBoundBool) Get() (bool, error) {
cache := b.p.Bool(b.key)
b.cache.Store(cache)
b.cache.Store(&cache)
return cache, nil
}

Expand All @@ -56,11 +56,8 @@ func (b *prefBoundBool) Set(v bool) error {

func (b *prefBoundBool) checkForChange() {
val := b.cache.Load()
if val != nil {
cache := val.(bool)
if b.p.Bool(b.key) == cache {
return
}
if val != nil && b.p.Bool(b.key) == *val {
return
}
b.trigger()
}
Expand All @@ -73,7 +70,7 @@ type prefBoundFloat struct {
base
key string
p fyne.Preferences
cache atomic.Value // float64
cache atomic.Pointer[float64]
}

// BindPreferenceFloat returns a bindable float64 value that is managed by the application preferences.
Expand All @@ -99,7 +96,7 @@ func BindPreferenceFloat(key string, p fyne.Preferences) Float {

func (b *prefBoundFloat) Get() (float64, error) {
cache := b.p.Float(b.key)
b.cache.Store(cache)
b.cache.Store(&cache)
return cache, nil
}

Expand All @@ -114,11 +111,8 @@ func (b *prefBoundFloat) Set(v float64) error {

func (b *prefBoundFloat) checkForChange() {
val := b.cache.Load()
if val != nil {
cache := val.(float64)
if b.p.Float(b.key) == cache {
return
}
if val != nil && b.p.Float(b.key) == *val {
return
}
b.trigger()
}
Expand All @@ -131,7 +125,7 @@ type prefBoundInt struct {
base
key string
p fyne.Preferences
cache atomic.Value // int
cache atomic.Pointer[int]
}

// BindPreferenceInt returns a bindable int value that is managed by the application preferences.
Expand All @@ -157,7 +151,7 @@ func BindPreferenceInt(key string, p fyne.Preferences) Int {

func (b *prefBoundInt) Get() (int, error) {
cache := b.p.Int(b.key)
b.cache.Store(cache)
b.cache.Store(&cache)
return cache, nil
}

Expand All @@ -172,11 +166,8 @@ func (b *prefBoundInt) Set(v int) error {

func (b *prefBoundInt) checkForChange() {
val := b.cache.Load()
if val != nil {
cache := val.(int)
if b.p.Int(b.key) == cache {
return
}
if val != nil && b.p.Int(b.key) == *val {
return
}
b.trigger()
}
Expand All @@ -189,7 +180,7 @@ type prefBoundString struct {
base
key string
p fyne.Preferences
cache atomic.Value // string
cache atomic.Pointer[string]
}

// BindPreferenceString returns a bindable string value that is managed by the application preferences.
Expand All @@ -215,7 +206,7 @@ func BindPreferenceString(key string, p fyne.Preferences) String {

func (b *prefBoundString) Get() (string, error) {
cache := b.p.String(b.key)
b.cache.Store(cache)
b.cache.Store(&cache)
return cache, nil
}

Expand All @@ -230,11 +221,8 @@ func (b *prefBoundString) Set(v string) error {

func (b *prefBoundString) checkForChange() {
val := b.cache.Load()
if val != nil {
cache := val.(string)
if b.p.String(b.key) == cache {
return
}
if val != nil && b.p.String(b.key) == *val {
return
}
b.trigger()
}
Expand Down
8 changes: 4 additions & 4 deletions dialog/color_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (e *colorChannelEntry) MinSize() fyne.Size {

type userChangeEntry struct {
widget.Entry
userTyped uint32 // atomic, 0 == false, 1 == true
userTyped atomic.Bool
}

func newUserChangeEntry(text string) *userChangeEntry {
Expand All @@ -164,7 +164,7 @@ func newUserChangeEntry(text string) *userChangeEntry {

func (e *userChangeEntry) setOnChanged(onChanged func(s string)) {
e.Entry.OnChanged = func(text string) {
if !atomic.CompareAndSwapUint32(&e.userTyped, 1, 0) {
if !e.userTyped.CompareAndSwap(true, false) {
return
}
if onChanged != nil {
Expand All @@ -175,11 +175,11 @@ func (e *userChangeEntry) setOnChanged(onChanged func(s string)) {
}

func (e *userChangeEntry) TypedRune(r rune) {
atomic.StoreUint32(&e.userTyped, 1)
e.userTyped.Store(true)
e.Entry.TypedRune(r)
}

func (e *userChangeEntry) TypedKey(ev *fyne.KeyEvent) {
atomic.StoreUint32(&e.userTyped, 1)
e.userTyped.Store(true)
e.Entry.TypedKey(ev)
}
7 changes: 3 additions & 4 deletions dialog/file_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ package dialog
import (
"fmt"
"os"
"os/exec"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"

"golang.org/x/sys/execabs"
)

func getFavoriteLocation(homeURI fyne.URI, name, fallbackName string) (fyne.URI, error) {
cmdName := "xdg-user-dir"
if _, err := execabs.LookPath(cmdName); err != nil {
if _, err := exec.LookPath(cmdName); err != nil {
return storage.Child(homeURI, fallbackName) // no lookup possible
}

cmd := execabs.Command(cmdName, name)
cmd := exec.Command(cmdName, name)
loc, err := cmd.Output()
if err != nil {
return storage.Child(homeURI, fallbackName)
Expand Down
22 changes: 10 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module fyne.io/fyne/v2
go 1.19

require (
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e
fyne.io/systray v1.10.1-0.20231230205326-d160fd363db9
github.com/BurntSushi/toml v1.3.2
github.com/fogleman/gg v1.3.0
github.com/fredbi/uri v1.0.0
github.com/fredbi/uri v1.1.0
github.com/fsnotify/fsnotify v1.7.0
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe
github.com/fyne-io/glfw-js v0.0.0-20220517201726-bebc2019cd33
github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20231223183121-56fa3ac82ce7
Expand All @@ -28,11 +28,11 @@ require (
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.4.0
github.com/yuin/goldmark v1.5.5
golang.org/x/image v0.11.0
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda
golang.org/x/mod v0.12.0
golang.org/x/sys v0.13.0
golang.org/x/tools v0.12.0
golang.org/x/image v0.14.0
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a
golang.org/x/mod v0.14.0
golang.org/x/sys v0.15.0
golang.org/x/tools v0.16.1
)

require (
Expand All @@ -44,9 +44,7 @@ require (
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tevino/abool v1.2.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
Loading