From ee40c896de03638e726a7c241140c3699ffcbe23 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 24 Sep 2026 15:25:58 +0200 Subject: [PATCH] feat: store all settings in figma.globalStorage (offline, available in every file); migrate legacy clientStorage save; bump 0.1.24 --- package.json | 2 +- src/main.ts | 24 +++++++++++++++++++++--- src/ui.tsx | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8c0f453..e301cde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "figma-ai-plugin", - "version": "0.1.23", + "version": "0.1.24", "private": true, "dependencies": { "@create-figma-plugin/ui": "^4.0.3", diff --git a/src/main.ts b/src/main.ts index 45e7995..7aadb44 100644 --- a/src/main.ts +++ b/src/main.ts @@ -563,15 +563,33 @@ export default function () { } }) - // Settings persistence RPC: clientStorage is only available here (main thread), not in the UI iframe. + // Settings persistence RPC: storage is only available here (main thread), not in the UI iframe. + // We use `figma.globalStorage` so settings live on the user's machine independent of any + // open file (works offline, available in every file). Fall back to `clientStorage` if the + // global namespace is unavailable, and migrate an old clientStorage save on first run. + const anyFigma = figma as any + const globalStore = (anyFigma.globalStorage && typeof anyFigma.globalStorage.getAsync === 'function') + ? anyFigma.globalStorage + : anyFigma.clientStorage + on('LOAD_SETTINGS', async function (payload: { key: string }) { let stored: any = null - try { stored = await figma.clientStorage.getAsync(payload.key) } catch (e) { stored = null } + try { stored = await globalStore.getAsync(payload.key) } catch (e) { stored = null } + // Migration: if nothing in global storage but an old clientStorage save exists, adopt it. + if (stored == null && globalStore !== anyFigma.clientStorage) { + try { + const legacy = await anyFigma.clientStorage.getAsync(payload.key) + if (legacy != null) { + stored = legacy + try { await globalStore.setAsync(payload.key, legacy) } catch (e) { /* ignore */ } + } + } catch (e) { /* ignore */ } + } emit('SETTINGS_LOADED', { settings: stored }) }) on('SAVE_SETTINGS', async function (payload: { key: string, settings: any }) { - try { await figma.clientStorage.setAsync(payload.key, payload.settings) } catch (e) { /* ignore */ } + try { await globalStore.setAsync(payload.key, payload.settings) } catch (e) { /* ignore */ } emit('SAVE_SETTINGS_DONE', {}) }) diff --git a/src/ui.tsx b/src/ui.tsx index 6fced8d..8c61cc4 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -30,7 +30,7 @@ const MIN_WINDOW_SIZE = { width: 320, height: 200 } // very high — actual clamp is done by main via clampWindowSize (bounds*zoom). // Full plugin version shown in the footer status bar. Keep in sync with package.json "version". -const PLUGIN_VERSION = '0.1.23' +const PLUGIN_VERSION = '0.1.24' const fieldStyle = { display: 'flex',