Guides
Storage and settings
Keep data across restarts and offer settings to the user.
Storage
ctx.storage (or AdanotchKit.storage) is a key-value store of your extension's own that survives Adanotch restarts. Values are JSON, and reads and writes are synchronous.
const count = ctx.storage.get<number>("count") ?? 0;
ctx.storage.set("count", count + 1);
ctx.storage.set("history", [{ at: Date.now(), value: 42 }]);
ctx.storage.remove("draft");
ctx.storage.keys(); // ["count", "history"]
ctx.storage.clear();Prop
Type
- JSON only: a
Datebecomes a string;Map,Setand functions are lost. Store dates as milliseconds. - The limit is 512 KB per extension. If you keep a history, cap it:
history.slice(-500). - Storage belongs to the extension's
id. Removing the extension deletes its storage too. - Don't keep API keys here; secrets live in the Keychain.
Storage or a module variable
| Module variable | storage | |
|---|---|---|
| Speed | Fastest | Fast (in memory, written to disk in the background) |
| After a restart | Reset | Kept |
| Good for | The last 30 readings, caches | Counters, user preferences, the last good answer |
Settings
Declare the options the user can change in manifest.json; Adanotch draws the controls in Settings › Extensions itself.
"settings": [
{ "key": "showMemory", "type": "toggle", "label": "Show RAM", "default": true },
{ "key": "threshold", "type": "number", "label": "Warning threshold", "default": 80, "unit": "%" },
{ "key": "city", "type": "text", "label": "City", "default": "Istanbul" },
{ "key": "range", "type": "select", "label": "Range", "default": "day",
"options": [{ "value": "day", "label": "Day" }, { "value": "week", "label": "Week" }] },
{ "key": "token", "type": "secret", "label": "API key" }
]interface Settings {
showMemory: boolean;
threshold: number;
city: string;
range: "day" | "week";
}
AdanotchKit.activity<Settings>({
async onSettingsChange(ctx) {
// If the city changed, drop the old cache.
ctx.storage.remove("weather");
},
async update(ctx) {
if (ctx.settings.showMemory) { /* … */ }
},
});- Values arrive in
ctx.settings, which always holds the current ones. - When the user changes a value,
onSettingsChangeruns, thenupdate. - The
secrettype isn't inctx.settings; read it withawait AdanotchKit.secrets.get("token").
A setting or a control in the card
Use a setting for things that rarely change (a city, an API key, a threshold). For things that change often or should take effect at once, put a toggle, picker or slider in the card and keep the value in storage.