Skip to content

Commit

Permalink
Give cloud a chance to set up and/or fail
Browse files Browse the repository at this point in the history
Also ensure we set up cleanly and inform settings change
  • Loading branch information
andydotxyz committed Jul 16, 2021
1 parent 7711f68 commit f9f068c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,23 @@ func (a *fyneApp) Run() {
}

func (a *fyneApp) SetCloudProvider(p fyne.CloudProvider) {
a.cloud = p
if p == nil {
a.cloud = nil
return
}

go a.transitionCloud(p)
}

var listeners []func()
if a.prefs != nil { // we need to restore these on the new instance
listeners = a.prefs.ChangeListeners()
func (a *fyneApp) transitionCloud(p fyne.CloudProvider) {
err := p.Setup()
if err != nil {
fyne.LogError("Failed to set up cloud provider "+ p.ProviderName(), err)
return
}
a.cloud = p

listeners := a.prefs.ChangeListeners()
if pp, ok := p.(fyne.CloudProviderPreferences); ok {
a.prefs = pp.CloudPreferences(a)
} else {
Expand All @@ -93,6 +103,9 @@ func (a *fyneApp) SetCloudProvider(p fyne.CloudProvider) {
a.prefs.AddChangeListener(l)
l() // assume that preferences have changed because we replaced the provider
}

// after transition ensure settings listener is fired
a.settings.apply()
}

func (a *fyneApp) Quit() {
Expand Down
3 changes: 3 additions & 0 deletions app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func newPreferences(app *fyneApp) *preferences {
}

p.AddChangeListener(func() {
if p != app.prefs {
return
}
p.prefLock.RLock()
shouldIgnoreChange := p.ignoreChange
p.prefLock.RUnlock()
Expand Down
3 changes: 3 additions & 0 deletions cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type CloudProvider interface {
ProviderIcon() Resource
// ProviderName returns the name of this cloud provider, usually the name of the service it uses.
ProviderName() string
// Setup is called when this provider is being used for the first time.
// Returning an error will exit the cloud setup process, though it can be retried.
Setup() error
}

// CloudProviderPreferences interface defines the functionality that a cloud provider will include if it is capable
Expand Down

0 comments on commit f9f068c

Please sign in to comment.