Guide · Settings & storage

Settings & storage

Declare settings in the manifest; Petty generates a UI in Settings → Plugins. Read them from JS with petty.settings, which falls back to the manifest default when nothing is stored.

Declare in the manifest

"settings": [
  {
    "key": "pollInterval",
    "type": "number",
    "label": "Poll interval (seconds)",
    "description": "How often to check for updates",
    "default": 60,
    "min": 10,
    "max": 600,
    "step": 10
  },
  {
    "key": "style",
    "type": "enum",
    "label": "Notification style",
    "default": "compact",
    "options": [
      { "value": "compact", "label": "Compact" },
      { "value": "verbose", "label": "Verbose" }
    ]
  }
]

Setting types

TypeUI controlExtra fields
boolToggle switch
numberSteppermin, max, step
stringText field
enumDropdownoptions (required, array of {value, label})

Reading settings from JS

Use petty.settings.get(key). It returns the stored value, or the manifest default if nothing is stored, or null if neither exists.

var interval = petty.settings.get("pollInterval"); // 60 from manifest if unset
var style = petty.settings.get("style");           // "compact" if unset

Reacting to changes

Use petty.settings.onChange(key, callback) instead of filtering settings:changed manually. The callback receives the new value directly — not the {key, value} envelope.

petty.settings.onChange("pollInterval", function (newSecs) {
  petty.schedule.interval("poll", newSecs * 1000, poll);
});

Writing settings

Your plugin can update its own settings — useful for persisting state that surfaces in the UI. set dispatches a local settings:changed so your onChange handlers fire. Pass null to delete the stored override and revert to the manifest default.

petty.settings.set("lastSyncedAt", Date.now());
petty.settings.set("style", null); // revert to manifest default

settings vs. storage

Both APIs persist to UserDefaults under your plugin's namespace — they can't collide. The distinction is declarative intent:

UseWhen
petty.settingsValues declared in the manifest that users can edit in the Settings UI. Typed fallback to the manifest default.
petty.storageInternal state the user never sees — last-seen ids, cache timestamps, counters. No UI, no declared default.