App Preferences

Overview

The App Preferences API is accessible through the io.prefs object.

See the JavaScript App Preferences example on GitHub.

Get

To retrieve the stored app preferences for the current app, use the get() method:

const prefs = await io.prefs.get();

This method resolves with an AppPreferences object with the following properties:

Property Type Description
app string The name of the app with which are associated the stored preferences.
data object The stored app preferences.
lastUpdate string Timestamp of the last update of the app preferences.

To retrieve the stored app preferences for a specific app, pass an app name to the get() method:

const appName = "clientlist";
const prefs = await io.prefs.get(appName));

To retrieve the stored app preferences for all apps of the current user, use the getAll() method:

const prefs = await io.prefs.getAll();

// The returned object has an `all` property which contains a list of `AppPreferences` objects.
prefs.all.forEach(console.log);

Set

To set the preferences for the current app, use the set() method:

const prefs = { fontSize: 18 };

await io.prefs.set(prefs);

The set() method replaces entirely the stored app preferences. All existing properties of the AppPreferences object associated with the app will be removed and replaced with the ones of the argument provided to the set() method.

To set the preferences for a specific app, pass an options object as a second argument to the set() method and specify the name of the app:

const prefs = { fontSize: 18 };
const options = { app: "clientlist" };

await io.prefs.set(prefs, options);

Update

To update the preferences for the current app, use the udpate() method:

const prefs = { fontSize: 18 };

await io.prefs.update(prefs);

The update() method modifies only the properties provided in the update object. All other existing properties of the AppPreferences object associated with the app will remain intact.

To update the preferences for a specific app, pass an options object as a second argument to the update() method and specify the name of the app:

const prefs = { fontSize: 18 };
const options = { app: "clientlist" };

await io.prefs.update(prefs, options);

Clear

To remove the stored app preferences for the current app, use the clear() method:

await io.prefs.clear();

To remove the stored app preferences for a specific app, pass an app name to the clear() method:

const appName = "clientlist";

await io.prefs.clear(appName);

To remove the stored app preferences for all apps of the current user, use the clearAll() method:

await io.prefs.clearAll();

Reference

For a complete list of the available App Preferences API methods and properties, see the App Preferences API Reference Documentation.