feat: store all settings in figma.globalStorage (offline, available in every file); migrate legacy clientStorage save; bump 0.1.24
This commit is contained in:
1 parent
f2e935dbd6
commit
ee40c896de
3 files changed
+23
-5
No files matched your search
+1
-1
@@ -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",
|
||||
|
||||
+21
-3
@@ -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', {})
|
||||
})
|
||||
|
||||
|
||||
+1
-1
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user