From 38ba66d943181ff0de49e37884e45822a94b12f1 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Wed, 2 Sep 2026 12:06:05 +0800 Subject: [PATCH] fix(webui): migrate brand logos to default on --- webui/src/lib/local-preferences.ts | 16 +++++++++++++--- webui/src/tests/local-preferences.test.ts | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/webui/src/lib/local-preferences.ts b/webui/src/lib/local-preferences.ts index 5405b1c0a..d8d4f93dd 100644 --- a/webui/src/lib/local-preferences.ts +++ b/webui/src/lib/local-preferences.ts @@ -13,6 +13,11 @@ export interface LocalPreferences { export const LOCAL_PREFS_STORAGE_KEY = "nanobot-webui.settings-preferences"; export const LOCAL_PREFS_CHANGED_EVENT = "nanobot-webui.local-preferences-changed"; +const LOCAL_PREFS_SCHEMA_VERSION = 1; + +type PersistedLocalPreferences = Partial & { + schemaVersion?: number; +}; export const DEFAULT_LOCAL_PREFS: LocalPreferences = { density: "comfortable", @@ -31,12 +36,14 @@ export function readLocalPreferences(): LocalPreferences { try { const raw = window.localStorage.getItem(LOCAL_PREFS_STORAGE_KEY); if (!raw) return DEFAULT_LOCAL_PREFS; - const parsed = JSON.parse(raw) as Partial; + const parsed = JSON.parse(raw) as PersistedLocalPreferences; return { density: parsed.density === "compact" ? "compact" : "comfortable", activityMode: parsed.activityMode === "expanded" ? "expanded" : "auto", codeWrap: parsed.codeWrap !== false, - brandLogos: parsed.brandLogos !== false, + brandLogos: parsed.schemaVersion === LOCAL_PREFS_SCHEMA_VERSION + ? parsed.brandLogos !== false + : true, browserNotifications: parsed.browserNotifications === true, fileEditDisplayMode: normalizeFileEditDisplayMode(parsed.fileEditDisplayMode), }; @@ -47,7 +54,10 @@ export function readLocalPreferences(): LocalPreferences { export function writeLocalPreferences(preferences: LocalPreferences): void { try { - window.localStorage.setItem(LOCAL_PREFS_STORAGE_KEY, JSON.stringify(preferences)); + window.localStorage.setItem(LOCAL_PREFS_STORAGE_KEY, JSON.stringify({ + schemaVersion: LOCAL_PREFS_SCHEMA_VERSION, + ...preferences, + })); } catch { // Browser-only preferences should never block settings. } diff --git a/webui/src/tests/local-preferences.test.ts b/webui/src/tests/local-preferences.test.ts index 6e17e672c..cafea7d45 100644 --- a/webui/src/tests/local-preferences.test.ts +++ b/webui/src/tests/local-preferences.test.ts @@ -10,7 +10,7 @@ import { describe("local preferences", () => { beforeEach(() => localStorage.clear()); - it("shows third-party brand logos by default while preserving an explicit opt-out", () => { + it("enables third-party brand logos by default and migrates the previous default", () => { expect(DEFAULT_LOCAL_PREFS.brandLogos).toBe(true); expect(readLocalPreferences().brandLogos).toBe(true); @@ -18,6 +18,11 @@ describe("local preferences", () => { LOCAL_PREFS_STORAGE_KEY, JSON.stringify({ brandLogos: false }), ); + expect(readLocalPreferences().brandLogos).toBe(true); + }); + + it("preserves a brand logo opt-out after the default-on migration", () => { + writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, brandLogos: false }); expect(readLocalPreferences().brandLogos).toBe(false); });