fix(webui): migrate brand logos to default on

This commit is contained in:
Xubin Ren
2026-09-02 16:25:07 +08:00
parent a3e043cf6f
commit 6b07c91aa2
2 changed files with 19 additions and 4 deletions
+13 -3
View File
@@ -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<LocalPreferences> & {
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<LocalPreferences>;
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.
}
+6 -1
View File
@@ -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);
});