-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Preferences don't all save when written in CloseIntercept
#3170
Comments
Is it possible this is some sort of app-close race condition? If you add a delay to the end of |
Adding |
OK thanks. Looks like we have to wait before returning if preferences are pending |
fyne.App.Run
CloseIntercept
I did some investigation into this today. It appears that this is actually due to the fact that the preferences have a 100ms debounce time to prevent rapid repeat saves (https://github.com/fyne-io/fyne/blob/master/app/preferences.go#L133 and https://github.com/fyne-io/fyne/blob/master/app/preferences.go#L28) Right now this is acting as saving before the debounce, and then saving again if there was a change during the debounce. My thought is that whatever is exiting the app isn't waiting for the time.Sleep finishes. The best solution imo is having the app do a ForceSave() right before exit. This new public method would ignore the debounce. If people agree I'll take a stab at getting this implemented this week. |
Maybe it's better to go with a flag like "ShutdownRequested" which set to true when closing application and check for it. And preferences saving should be done after close intercept function, IMO. |
I agree that baking that into public API isn't a smart move - but in addition it would be a breaking change so we can't do that (at least not before 3.0). Bear in mind also that we aim for a clean, intent based API - and Also saving Preference on shutdown does make sense, how best to do that may not be obvious but we can't do it by adding to the interface |
Yeah, given your API goals that is definitely not a good route. Looking at how the programs, I noticed that we already have an app level "cleanup" function. app.Stop() method calls Application controlling the quit:
A backwards compatible (and somewhat confusing) flow would involve some back and forth between the driver and app:
This means that no matter what, the app.Quit already runs. To prevent this from looping infinitely, we would use a shutdownRequested (or terminating) flag stored within the app that gets set the first time it runs. So something like this: func (a *fyneApp) Quit() {
if a.terminating { // make atomic, prevent circular logic
return
}
a.terminating = true
for _, window := range a.driver.AllWindows() {
window.Close()
}
a.driver.Quit()
a.settings.stopWatching()
a.prefs.flush() // we can now make non-public API calls.
atomic.StoreUint32(&a.running, 0)
} Its a bit round-about, but it definitely allows more flexibility. If I were to design 3.0, I'd propose that the only way to exit the application is app.Quit, and driver.Quit only executes driver specific functions. So the TriggerStarted and TriggerStopped lifecycle hooks would be called by the app, not the driver. Perhaps there is a way to do that now, but right now it feels to me like this circular Quit logic is the best. The only other solution I can think of would either involve public API changes, or adding a time.Sleep(110 * time.Millisecond) |
Force writing preferences to file when application stops (fixes #3170)
Thanks to @nullst this has been fixed on develop ready for v2.4.0 |
Checklist
Describe the bug
When using
fyne.App.Run()
to start an application, only first written preference is saved in Preferences store.How to reproduce
${XDG_CONFIG_HOME}/fyne/some.test/preferences.json
Screenshots
No response
Example code
Fyne version
2.2.3 and today's develop at b71c0f2
Go compiler version
1.18.4
Operating system
macOS
Operating system version
macOS 12.5
Additional Information
This problem does not appear when using
fyne.Window.ShowAndRun
.The text was updated successfully, but these errors were encountered: