From 525f6ed3353345241dae164702fcd39b885364b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 23:08:06 -0400 Subject: [PATCH] fix(window-state): log corruption instead of silent reset to default geometry --- src/main/window-state.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/window-state.ts b/src/main/window-state.ts index 56b65aec..eb20489b 100644 --- a/src/main/window-state.ts +++ b/src/main/window-state.ts @@ -1,4 +1,4 @@ -import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname } from "node:path"; import type { BrowserWindow, Rectangle } from "electron"; @@ -15,12 +15,20 @@ const DEFAULT_BOUNDS: Rectangle = { }; function safeParseState(filePath: string): StoredWindowState | null { + // First-run: file absent is normal, not corruption. Return null silently. + if (!existsSync(filePath)) return null; try { const raw = readFileSync(filePath, "utf8"); const parsed = JSON.parse(raw) as Partial; - if (!parsed.bounds || typeof parsed.bounds !== "object") return null; + if (!parsed.bounds || typeof parsed.bounds !== "object") { + + console.warn(`[window-state] ${filePath} is missing bounds; using default geometry.`); + return null; + } const { width, height, x, y } = parsed.bounds as Partial; if (typeof width !== "number" || !Number.isFinite(width) || typeof height !== "number" || !Number.isFinite(height)) { + + console.warn(`[window-state] ${filePath} has non-numeric bounds; using default geometry.`); return null; } return { @@ -32,7 +40,10 @@ function safeParseState(filePath: string): StoredWindowState | null { }, maximized: parsed.maximized === true, }; - } catch { + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + + console.warn(`[window-state] ${filePath} unreadable (${message}); using default geometry.`); return null; } }