mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-03 01:31:47 +03:00
fix(webui): migrate brand logos to default on
This commit is contained in:
@@ -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.
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user