For the complete documentation index, see llms.txt. This page is also available as Markdown.

Settings

How plugins define, read, and update persisted settings in Nuclear.

Settings API for Plugins

Persist user preferences, secrets, and configuration with a single API. This guide shows how to define settings, read/write values, and react to changes.

Access settings via the API object (api.Settings.*) or the React hook described below.

Core concepts

  • Namespace: the app automatically prefixes setting IDs.

    • Core settings: core.<id>

    • Plugin settings: plugin.<pluginId>.<id>

    • In your plugin, pass only the bare id (e.g. theme), skip the prefix.

  • Types: boolean | number | string for built-in kinds. Custom widgets can store any JSON-serializable value (objects, arrays, null).

  • Defaults: used until the user sets a value; only user-chosen values are persisted.

  • Categories: free-form strings used to group settings in the UI.

  • Hidden: settings with hidden: true are stored but not shown in standard UI. This is used for settings that are controlled elsewhere, such as the volume slider.

  • Persistence: values are saved to disk via Tauri's Store plugin.

Usage

import type { NuclearPluginAPI } from '@nuclearplayer/plugin-sdk';

export default {
  async onLoad(api: NuclearPluginAPI) {
    await api.Settings.register([
      {
        id: 'theme',
        title: 'Theme',
        description: 'Choose your preferred theme',
        category: 'Appearance',
        kind: 'enum',
        options: [
          { value: 'system', label: 'System' },
          { value: 'light', label: 'Light' },
          { value: 'dark', label: 'Dark' },
        ],
        default: 'system',
      },
      {
        id: 'scrobbleEnabled',
        title: 'Enable scrobbling',
        category: 'Integrations',
        kind: 'boolean',
        default: false,
        widget: { type: 'toggle' },
      },
    ]);
  },
};

Setting definitions

Custom settings

For settings that need a richer UI than the built-in widgets (OAuth flows, multi-field forms, live previews), use kind: 'custom' with a registered React component.

The widgetId references a React component registered via api.Settings.registerWidget(). The component receives the current value, a setter, and the setting definition as props.

Widget IDs are namespaced by plugin ID automatically. Two plugins can both register a widget called 'auth' without conflict.

The CustomWidgetProps type:

SettingValue accepts any JSON-serializable value (strings, numbers, booleans, objects, arrays, null), so custom widgets can store structured data like { sessionKey: string, username: string }.

Categories

  • Any string. Use i18n strings, or sentence case, e.g. General, Appearance, Integrations.

Defaults and persistence

  • If the user hasn't set a value, get(id) resolves to the definition's default or undefined.

  • When a user sets a value, it's persisted to disk and takes precedence over default on the next run.

  • get(id) returns undefined if neither a user value nor a default exists.

End-to-end example

Reference

Last updated