diff options
| author | Adam <[email protected]> | 2026-02-10 07:47:05 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-10 07:47:05 -0600 |
| commit | 1e03a55acdb1e80b747d0604d698f4cbef97ace1 (patch) | |
| tree | fe82b7eae2e9f043b182d81b787d4a0b3be3afed /packages/desktop/src | |
| parent | 65c966928393a2a7b03af267e8d3279d3370440c (diff) | |
| download | opencode-1e03a55acdb1e80b747d0604d698f4cbef97ace1.tar.gz opencode-1e03a55acdb1e80b747d0604d698f4cbef97ace1.zip | |
fix(app): persist defensiveness (#12973)
Diffstat (limited to 'packages/desktop/src')
| -rw-r--r-- | packages/desktop/src/i18n/index.ts | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/packages/desktop/src/i18n/index.ts b/packages/desktop/src/i18n/index.ts index 376769e28..7b1ebfe69 100644 --- a/packages/desktop/src/i18n/index.ts +++ b/packages/desktop/src/i18n/index.ts @@ -116,6 +116,15 @@ function parseRecord(value: unknown) { return value as Record<string, unknown> } +function parseStored(value: unknown) { + if (typeof value !== "string") return value + try { + return JSON.parse(value) as unknown + } catch { + return value + } +} + function pickLocale(value: unknown): Locale | null { const direct = parseLocale(value) if (direct) return direct @@ -169,7 +178,7 @@ export function initI18n(): Promise<Locale> { if (!store) return state.locale const raw = await store.get("language").catch(() => null) - const value = typeof raw === "string" ? JSON.parse(raw) : raw + const value = parseStored(raw) const next = pickLocale(value) ?? state.locale state.locale = next |
