Skip to content

Settings API

Andy Williams edited this page Aug 23, 2019 · 20 revisions

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.

App.UniqueID

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.

App.Preferences

A key value store of primitive preferences for an application. All basic types can be stored with simple typed APIs.

GetString(key string):string

Access a user configuration string that was stored previously.

SetString(key string, value string)

Allows an application to store a user configuration string for later access.

Additional types to add...

Additional typed versions (like GetFloat or SetBool) should be added to avoid conversions.

Interface and complex types (to be discussed)

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.

Get(key string, value interface{})

Access a complex type that was stored previously - the developer must pass in the struct to be filled.

Set(key string, value interface{})

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.

App.SecurePreferences

A proposed extension would allow encrypted storage of application secret preferences.

App.Documents

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

Create a new (empty) document with a simple string identifier (like filename).

Load

Load an existing document from it's identifier. Will error if the document does not exist.

Remove

Delete a named document from the storage.

List

Return a list of available documents for the given application.

App.Cache

The correct location to cache documents or assets that you don't want to keep in memory.

Save

Create a new cache entry with specified name and content.

Load

Get the content of a named cache entry.

Remove

Clear the content of a named cache entry.


Merged for 1.2

The items in this section have been implemented

fyne.Settings

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.

Theme

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.

AddChangeListener

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.

Welcome to the Fyne wiki.

Project documentation

Getting involved

Platform details

Clone this wiki locally