From cbe4645bc6111efe7b6c2ae2cce4d3e9a0fd1acc Mon Sep 17 00:00:00 2001 From: Syngnat Date: Wed, 3 Jun 2026 20:22:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(store):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=80=E5=A4=A7=E5=8C=96=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=9C=AA=E5=8F=8A=E6=97=B6=E6=8C=81=E4=B9=85=E5=8C=96=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 startupFullscreen 增加即时持久化补写 - 避免用户修改设置后立即退出导致下次启动仍按旧窗口状态恢复 - 补充回归测试覆盖立即重启场景 --- frontend/package.json.md5 | 2 +- frontend/src/store.test.ts | 13 +++++++++++++ frontend/src/store.ts | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index bed8925..7396e24 100755 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -0295a42fd931778d85157816d79d29e5 \ No newline at end of file +d0464f9da25e9356e61652e638c99ffe \ No newline at end of file diff --git a/frontend/src/store.test.ts b/frontend/src/store.test.ts index 20cd84d..f4323a2 100644 --- a/frontend/src/store.test.ts +++ b/frontend/src/store.test.ts @@ -1062,6 +1062,19 @@ describe('store appearance persistence', () => { }); }); + it('persists startup fullscreen immediately so next launch does not miss maximize preference', async () => { + const { useStore } = await importStore(); + + useStore.getState().setStartupFullscreen(true); + + const persisted = JSON.parse(storage.getItem('lite-db-storage') || '{}'); + expect(persisted.state.startupFullscreen).toBe(true); + + vi.resetModules(); + const reloaded = await importStore(); + expect(reloaded.useStore.getState().startupFullscreen).toBe(true); + }); + it('falls back to Enter when persisted AI chat send shortcut is invalid', async () => { storage.setItem('lite-db-storage', JSON.stringify({ state: { diff --git a/frontend/src/store.ts b/frontend/src/store.ts index 328210b..8d9c59c 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -225,6 +225,36 @@ const createDebouncedPersistStorage = ( }; }; +const writePersistedStatePatch = ( + patch: Record, +): void => { + if (typeof localStorage === "undefined") { + return; + } + try { + const payload = localStorage.getItem(PERSIST_STORAGE_KEY); + const raw = + payload && payload.trim() !== "" + ? (JSON.parse(payload) as Record) + : {}; + const state = unwrapPersistedAppState(raw); + localStorage.setItem( + PERSIST_STORAGE_KEY, + JSON.stringify({ + ...raw, + state: { + ...state, + ...patch, + }, + version: + typeof raw.version === "number" ? raw.version : PERSIST_VERSION, + }), + ); + } catch { + // ignore + } +}; + const resolveOceanBaseProtocol = ( raw: Record, normalizedConnectionParams: string, @@ -2654,7 +2684,11 @@ export const useStore = create()( })), setUiScale: (scale) => set({ uiScale: sanitizeUiScale(scale) }), setFontSize: (size) => set({ fontSize: sanitizeFontSize(size) }), - setStartupFullscreen: (enabled) => set({ startupFullscreen: !!enabled }), + setStartupFullscreen: (enabled) => { + const nextValue = !!enabled; + set({ startupFullscreen: nextValue }); + writePersistedStatePatch({ startupFullscreen: nextValue }); + }, setGlobalProxy: (proxy) => set((state) => ({ globalProxy: sanitizeGlobalProxy({ ...state.globalProxy, ...proxy }),