feat: persist maximize state so Restore button shows after reopen
This commit is contained in:
1 parent
a6d02322f3
commit
f885be7266
2 files changed
+23
-6
No files matched your search
+10
-5
@@ -42,7 +42,7 @@ export default function () {
|
||||
const PLACEMENT_KEY = 'figma-ai-plugin:placement'
|
||||
type Placement =
|
||||
| { mode: 'dock'; position: DockPosition }
|
||||
| { mode: 'free'; x: number; y: number; w: number; h: number }
|
||||
| { mode: 'free'; x: number; y: number; w: number; h: number; maximized?: boolean }
|
||||
let saveTimer: ReturnType<typeof setTimeout> | null = null
|
||||
function savePlacement (p: Placement) {
|
||||
try {
|
||||
@@ -56,7 +56,7 @@ export default function () {
|
||||
// Persist the CURRENT window as a free placement (real canvas-space x/y + size).
|
||||
// Used by maximize and corner docks, which must remember the EXACT size/position
|
||||
// rather than re-deriving it from a dock formula (which would reset the size).
|
||||
function saveFreeFromCurrent () {
|
||||
function saveFreeFromCurrent (maximized?: boolean) {
|
||||
try {
|
||||
const pos = (figma.ui as any).getPosition()
|
||||
savePlacement({
|
||||
@@ -64,7 +64,8 @@ export default function () {
|
||||
x: Math.round(pos.canvasSpace.x),
|
||||
y: Math.round(pos.canvasSpace.y),
|
||||
w: lastSize.width,
|
||||
h: lastSize.height
|
||||
h: lastSize.height,
|
||||
maximized: maximized === true
|
||||
})
|
||||
} catch (e) { /* getPosition unavailable — skip */ }
|
||||
}
|
||||
@@ -379,10 +380,10 @@ export default function () {
|
||||
|
||||
// UI asks to persist the CURRENT window as a free placement (used by Maximize,
|
||||
// which is not a held dock — it must remember the exact size+position across restart).
|
||||
on('SAVE_FREE', function () {
|
||||
on('SAVE_FREE', function (payload?: { maximized?: boolean }) {
|
||||
dockedPosition = null // maximize is not held; clear any stale dock state
|
||||
lastBoundsKey = ''
|
||||
saveFreeFromCurrent()
|
||||
saveFreeFromCurrent(payload != null ? payload.maximized === true : false)
|
||||
})
|
||||
|
||||
// Останавливаем поллинг при закрытии плагина, чтобы не висел в памяти.
|
||||
@@ -514,6 +515,10 @@ export default function () {
|
||||
figma.ui.resize(saved.w, saved.h)
|
||||
figma.ui.reposition(saved.x, saved.y)
|
||||
lastSize = { width: saved.w, height: saved.h }
|
||||
// If it was maximized, tell UI to show the Restore button on next open.
|
||||
if (saved.maximized === true) {
|
||||
emit('SET_MAXIMIZED', { maximized: true })
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (e) { /* storage unavailable → default center below */ }
|
||||
|
||||
Reference in new issue
Block a user