Settings and persistent storage
Declare settings for manifest-defined preferences and storage for plugin-private JSON data. These serve different purposes.
Define preferences
Section titled “Define preferences”Add a setting to your manifest’s settings array:
{ "key": "greeting", "title": "Greeting", "kind": "string", "defaultValue": "Hello"}FluxPlugs renders the setting in its native Settings page and validates updates against its declared type.
const greeting = await api.settings.get<string>("greeting");const starts = (await api.storage.get<number>("starts")) ?? 0;await api.storage.set("starts", starts + 1);api.logger.info("Plugin started", { greeting, starts: starts + 1 });The generic TypeScript parameter describes the expected value; it is not runtime validation for arbitrary stored data. Validate structured storage before using it, especially after upgrades.
Secret settings
Section titled “Secret settings”Add secret: true to a string setting, such as an API key, to mask it on screen and store it encrypted:
{ "key": "apiKey", "title": "API key", "kind": "string", "defaultValue": "", "secret": true}FluxPlugs Settings shows it as a password field with autocomplete off. Only string settings can be secret; any other kind fails with invalid_setting_definition.
Once saved, the value is never shown again. The field stays empty with “Saved. Type to replace it”: typing a new value replaces it, leaving the field empty keeps it, and a Clear button removes it. A caption under the field says how the value is kept on this system; see protection levels.
The value is stored encrypted in plugins.json in FluxPlugs’ user data, where the system has a keystore; without one it is stored as typed, and FluxPlugs says so at the top of its Plugins page. Values saved in plain text by earlier versions are encrypted when FluxPlugs starts. Your plugin still reads the plain value with settings.get like any other setting. Never log it, and keep it out of notices, since ui.notify messages are also written to the console.
Store secrets
Section titled “Store secrets”A secret your plugin asks for itself, such as a key for a service the user picks on your settings page, goes in storage secrets. They need only the storage capability; this api-example also uses ui to ask for the key with a password field:
let key = await api.storage.getSecret("service-key");if (key === undefined) { const values = await api.ui.openDialog( { title: "Service key", description: "Paste the API key from your account page.", submitLabel: "Save", sections: [ { title: "Key", controls: [ { key: "key", label: "API key", kind: "password", maxLength: 4096 }, ], }, ], }, (values) => typeof values.key === "string" && values.key.trim() ? undefined : "Enter a key", ); if (values && typeof values.key === "string") { key = values.key.trim(); const { protection } = await api.storage.setSecret("service-key", key); if (protection !== "os") await api.ui.notify( "The key is saved, but this system has no keystore to encrypt it.", ); }}- getSecret(key) resolves to the value, or
undefinedwhen it isn’t set or can’t be decrypted any more, for example after the user moved their profile to another computer. Ask for it again in that case. - setSecret(key, value) saves 1 to 4096 characters with no line breaks or other control characters; anything else fails with invalid_secret. A plugin may keep 32 secrets; a new key beyond that fails with storage_quota_exceeded. It resolves with
{ protection }, the same level secretProtection() reports. - deleteSecret(key) removes one.
Secrets live in their own file, plugin-secrets/<id>.json in FluxPlugs’ user data, apart from ordinary storage. They are removed with the plugin, while ordinary storage stays. Changing a secret never restarts the plugin.
Protection levels
Section titled “Protection levels”FluxPlugs encrypts secret settings and stored secrets with Electron’s safeStorage. storage.secretProtection() says how well that works on this system:
| Level | Meaning |
|---|---|
os |
Encrypted with the system keystore: DPAPI on Windows, the Keychain on macOS, the Secret Service or KWallet on Linux |
basic |
Linux without a keyring: Electron’s built-in key. It hides the text, but anyone with the user’s files can read it |
none |
No keystore is available, and the value is stored unencrypted |
Tell the user when the level isn’t os, so they can decide whether to store a key. FluxPlugs also shows a notice at the top of its Plugins page on such systems.
Choose the right persistence
Section titled “Choose the right persistence”Settings are boolean, string, or finite number values. Their defaults must match their type. Storage accepts bounded JSON values and provides get, set, and delete, plus the secret methods above for strings that need encrypting; it is not browser localStorage or executable code storage.
Read current settings on each start because setting changes restart the plugin.
Updates and removal
Section titled “Updates and removal”Keep IDs and compatible setting keys stable. Reimport retains compatible values, uses defaults for new settings, and removes obsolete ones. Separate plugin storage survives updates and uninstall; settings, stored secrets and trust do not survive uninstall.
If your storage structure changes, add a version field, validate old values, and migrate without deleting unrelated data. Catch storage errors and show an actionable message rather than continuing with a partially saved change.
FluxPlugs is an independent project, not affiliated with or endorsed by Fluxer.