-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Settings API
To provide a clean and consistent API for settings and storage we need to be clear about what is application local (user preferences) vs global (system settings). Also some things can be set by environment variables to override settings.
To support managing documents and files across multiple platforms we cannot simply pass around file paths for the generic io
handling. On some platforms files use a URI instead of path. Some platforms also require that we call privileged API to read the data, so we should wrap them and handle this automatically.
type FileReader interface {
io.ReadCloser
Name() string
URI() string
}
type FileWriter interface {
io.WriteCloser
}
The fyne.FileReader
type will be returned by the dialog.ShowOpenFile()
callback and the file.FileWriter
will be returned by the callback of dialog.ShowSaveFile()
.
Usage of the reader and writer streams will handle permissions etc automatically but must be Close()d after use.
In addition to this a developer may wish to re-open an existing file reference (for example, storing an accessed file in a "recent" list. To do this the developer will use the file identifier (from previously calling FileReader.URI()
), and then pass that to the following function:
'''go func OpenFileFromURI(uri string) FileReader func SaveFileFromURI(uri string) FileWriter '''
In addition the documents section described below will use this type so that the storage behind the scenes can be appropriate to the operating system.
A place where an application can store user documents - within the standard user documents directory. This will usually be a simple filesystem abstraction but may vary across different platforms.
Create a new (empty) document with a simple string identifier (like filename). The document must not exist with this name when calling - an error will be thrown if one exists.
Open an existing document from its identifier. Will error if the document does not exist.
Save to an existing document from its identifier. Will error if the document does not exist.
Delete a named document from the storage.
Return a list of available document names for the given application.
The following items are proposed as additions to the existing Preferences API.
We should support complex types as well - the underlying struct must support JSON marshalling - exported types will be persisted and the Go language tags for json can be used to configure how it is stored.
Access a complex type that was stored previously - the developer must pass in the struct to be filled.
Store a complex type, any struct with exported values can be persisted in this manner. It will use the builtin JSON encoding to store the values.
A proposed extension would allow encrypted storage of application secret preferences.
The correct location to cache documents or assets that you don't want to keep in memory.
Create a new cache entry with specified name and content.
Get the content of a named cache entry.
Clear the content of a named cache entry.
The items in this section have been implemented
The settings API for fyne provides information about global values. These can be configured by the user of a system. Some of these values can be overridden by the application.
The user can set their preferred theme that will apply to applications if they don't override.
It can be overridden by the user with FYNE_THEME
.
It can also be set by the application if the developer wants to use a custom theme.
An application can listen to changes in global settings. This will occur if a user changes their settings like by using the fyne_settings helper.
For the sections below about app storage we will require a App.UniqueID which will have to be set through a new constructor or directly on the app instance. Global settings can function without this addition. This could be added without breaking the existing API and helpful errors can indicate when storage functions are used without an appropriate identifier set.
A key value store of primitive preferences for an application. All basic types can be stored with simple typed APIs.
Access a user configuration string that was stored previously.
Allows an application to store a user configuration string for later access.
Additional typed versions (like GetFloat or SetBool) should be added to avoid conversions.