Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(wallpaper): the catalog corrects what the boot migration guessed

rubenluetke10-beepcab23de1eca6
diff --git a/jarvis/ui/web/frontend/src/store/wallpaper.test.ts b/jarvis/ui/web/frontend/src/store/wallpaper.test.ts
index ce06ba5c8d..fa89b96303 100644
--- a/jarvis/ui/web/frontend/src/store/wallpaper.test.ts
+++ b/jarvis/ui/web/frontend/src/store/wallpaper.test.ts
@@ -44,3 +44,67 @@ describe("legacy single-slot migration", () => {
expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
});
});
+
+/**
+ * The catalog-backed correction pass.
+ *
+ * The boot migration can only guess a mode from the theme cache; `reconcile`
+ * is handed the real answer per picture and moves anything the guess misfiled.
+ */
+describe("reconcile", () => {
+ beforeEach(() => {
+ window.localStorage.clear();
+ useWallpaperStore.setState({ selections: { light: null, dark: null } });
+ });
+
+ const themes: Record<string, "light" | "dark"> = {
+ "05-noir-03": "dark",
+ "07-terrace-01": "light",
+ };
+ const themeOf = (id: string) => themes[id] ?? null;
+
+ it("moves a dark picture out of the light slot and into its own", () => {
+ window.localStorage.setItem("jarvis.wallpaper.light.v1", "05-noir-03");
+
+ useWallpaperStore.getState().reconcile(themeOf);
+
+ const { selections } = useWallpaperStore.getState();
+ expect(selections.light).toBeNull();
+ expect(selections.dark).toBe("05-noir-03");
+ });
+
+ it("drops a misfiled pick when its own mode has already chosen", () => {
+ window.localStorage.setItem("jarvis.wallpaper.light.v1", "05-noir-03");
+ window.localStorage.setItem("jarvis.wallpaper.dark.v1", "already-dark");
+
+ useWallpaperStore.getState().reconcile(themeOf);
+
+ const { selections } = useWallpaperStore.getState();
+ // A mode showing its default is right; one wearing the other mode's
+ // picture is the bug — so the misfiled pick goes, not the chosen one.
+ expect(selections.light).toBeNull();
+ expect(selections.dark).toBe("already-dark");
+ });
+
+ it("leaves ids the catalog cannot answer for exactly where they are", () => {
+ window.localStorage.setItem("jarvis.wallpaper.light.v1", "u0123456789abcdef");
+
+ useWallpaperStore.getState().reconcile(themeOf);
+
+ // An upload still loading must not be thrown away for being unknown.
+ expect(useWallpaperStore.getState().selections.light).toBe(
+ "u0123456789abcdef",
+ );
+ });
+
+ it("keeps a correctly filed pick untouched", () => {
+ window.localStorage.setItem("jarvis.wallpaper.light.v1", "07-terrace-01");
+ window.localStorage.setItem("jarvis.wallpaper.dark.v1", "05-noir-03");
+
+ useWallpaperStore.getState().reconcile(themeOf);
+
+ const { selections } = useWallpaperStore.getState();
+ expect(selections.light).toBe("07-terrace-01");
+ expect(selections.dark).toBe("05-noir-03");
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/store/wallpaper.ts b/jarvis/ui/web/frontend/src/store/wallpaper.ts
index f4004df46a..d892b37774 100644
--- a/jarvis/ui/web/frontend/src/store/wallpaper.ts
+++ b/jarvis/ui/web/frontend/src/store/wallpaper.ts
@@ -160,6 +160,18 @@ interface WallpaperStore {
toggleFavorite: (id: string) => void;
/** Adopt choices made in another window. Does not write back. */
adopt: () => void;
+ /**
+ * Re-file every stored pick under the mode its picture was authored for.
+ *
+ * The load-time migration above can only GUESS at the legacy pick's mode
+ * (from the theme cache), and a wrong guess would park a night scene in the
+ * light slot — the very leak all of this exists to end. This is the
+ * correction pass, run by whoever holds the catalog and can therefore
+ * answer for real: `themeOf` returns the mode a picture was authored for,
+ * or null for an id it does not know (an upload still loading, a library
+ * not installed) — unknown ids are left exactly where they are.
+ */
+ reconcile: (themeOf: (id: string) => Theme | null) => void;
}
export const useWallpaperStore = create<WallpaperStore>((set, get) => ({
@@ -213,6 +225,27 @@ export const useWallpaperStore = create<WallpaperStore>((set, get) => ({
set({ favorites: next });
},
adopt: () => set({ selections: readSelections(), favorites: readFavorites() }),
+ reconcile: (themeOf) => {
+ try {
+ for (const slot of ["light", "dark"] as Theme[]) {
+ const id = window.localStorage.getItem(THEME_KEYS[slot]);
+ if (!id || !id.trim()) continue;
+ const authored = themeOf(id);
+ if (authored === null || authored === slot) continue;
+ // Misfiled: hand the pick to its own mode when that mode has not
+ // chosen for itself, and clear the wrong slot either way — a mode
+ // showing its default is right; one wearing the other mode's picture
+ // is the bug.
+ if (!window.localStorage.getItem(THEME_KEYS[authored])) {
+ window.localStorage.setItem(THEME_KEYS[authored], id);
+ }
+ window.localStorage.removeItem(THEME_KEYS[slot]);
+ }
+ } catch {
+ /* storage blocked — nothing stored means nothing misfiled */
+ }
+ set({ selections: readSelections() });
+ },
}));
/**
diff --git a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
index 2c4e5bd34f..e63b9fbefd 100644
--- a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
+++ b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
@@ -398,6 +398,7 @@ export function WallpaperView() {
const favorites = useWallpaperStore((state) => state.favorites);
const toggleFavorite = useWallpaperStore((state) => state.toggleFavorite);
const forget = useWallpaperStore((state) => state.forget);
+ const reconcile = useWallpaperStore((state) => state.reconcile);
const apply = useApplyWallpaper();
const [theme, setTheme] = useState<ThemeFilter>("all");
@@ -421,6 +422,16 @@ export function WallpaperView() {
return bundled ? [bundled, ...ownEntries, ...rest] : [...ownEntries, ...catalog];
}, [data?.items, ownEntries]);
+ // This view is the one place that knows which mode every picture was
+ // authored for, so it is where a misfiled pick — the boot migration's wrong
+ // guess about the pre-per-theme slot, or any older cross-mode leak — is put
+ // back under its own mode (see `reconcile`). Idempotent, so re-running as
+ // uploads trickle in costs nothing.
+ useEffect(() => {
+ if (!data) return;
+ reconcile((id) => items.find((item) => item.id === id)?.theme ?? null);
+ }, [data, items, reconcile]);
+
const styles = useMemo(() => {
const known = data?.styles ?? [];
if (!ownEntries.length) return known;