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): a mode never wears the other mode's picture

rubenluetke10-beep8e418e5d1355
diff --git a/jarvis/ui/web/frontend/src/hooks/useTheme.tsx b/jarvis/ui/web/frontend/src/hooks/useTheme.tsx
index f7c6039b15..a3b7eb64b2 100644
--- a/jarvis/ui/web/frontend/src/hooks/useTheme.tsx
+++ b/jarvis/ui/web/frontend/src/hooks/useTheme.tsx
@@ -51,6 +51,18 @@ export function resolveTheme(preference: ThemePreference): Theme {
return preference === "system" ? systemTheme() : preference;
}
+/**
+ * The theme the app is about to paint, answered synchronously from the cache.
+ *
+ * For code that needs the answer at module-init time, before the provider (or
+ * even React) exists — e.g. the wallpaper store filing a stored pick under the
+ * mode it belongs to. Reads the same cache the boot script uses, so the three
+ * readers of `jarvis.theme` cannot disagree about what the first frame wears.
+ */
+export function cachedTheme(): Theme {
+ return resolveTheme(readCachedPreference());
+}
+
/**
* The cached preference, read synchronously.
*
diff --git a/jarvis/ui/web/frontend/src/store/wallpaper.test.ts b/jarvis/ui/web/frontend/src/store/wallpaper.test.ts
new file mode 100644
index 0000000000..ce06ba5c8d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/store/wallpaper.test.ts
@@ -0,0 +1,46 @@
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { useWallpaperStore } from "@/store/wallpaper";
+
+/**
+ * The pre-per-theme slot must be migrated, never read live.
+ *
+ * Read as a live fallback it leaked one mode's picture into the other: a dark
+ * pick stored before the per-theme split kept showing behind light chrome for
+ * as long as light mode had no pick of its own. `adopt()` runs the same
+ * migration the store runs on load, which is what lets a test drive it after
+ * the module has long been imported.
+ */
+describe("legacy single-slot migration", () => {
+ beforeEach(() => {
+ window.localStorage.clear();
+ useWallpaperStore.setState({ selections: { light: null, dark: null } });
+ });
+
+ it("files the old pick under the cached theme and retires the slot", () => {
+ window.localStorage.setItem("jarvis.theme", "dark");
+ window.localStorage.setItem("jarvis.wallpaper.v1", "05-noir-03");
+
+ useWallpaperStore.getState().adopt();
+
+ const { selections } = useWallpaperStore.getState();
+ expect(selections.dark).toBe("05-noir-03");
+ // The leak this replaces: light mode must NOT inherit the dark pick.
+ expect(selections.light).toBeNull();
+ expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
+ expect(window.localStorage.getItem("jarvis.wallpaper.dark.v1")).toBe(
+ "05-noir-03",
+ );
+ });
+
+ it("never overwrites a mode's own pick", () => {
+ window.localStorage.setItem("jarvis.theme", "light");
+ window.localStorage.setItem("jarvis.wallpaper.light.v1", "chosen-light");
+ window.localStorage.setItem("jarvis.wallpaper.v1", "older-pick");
+
+ useWallpaperStore.getState().adopt();
+
+ expect(useWallpaperStore.getState().selections.light).toBe("chosen-light");
+ expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/store/wallpaper.ts b/jarvis/ui/web/frontend/src/store/wallpaper.ts
index e03d0af719..f4004df46a 100644
--- a/jarvis/ui/web/frontend/src/store/wallpaper.ts
+++ b/jarvis/ui/web/frontend/src/store/wallpaper.ts
@@ -1,6 +1,6 @@
import { create } from "zustand";
-import type { Theme } from "@/hooks/useTheme";
+import { cachedTheme, type Theme } from "@/hooks/useTheme";
/**
* Which desktop wallpaper the app is wearing — one choice PER THEME.
@@ -27,10 +27,40 @@ const THEME_KEYS: Record<Theme, string> = {
dark: "jarvis.wallpaper.dark.v1",
};
-/** The pre-per-theme slot. Kept readable as the fallback for a mode that has
- * no pick of its own yet, so an existing profile keeps its picture. */
+/** The single pre-per-theme slot. Migrated on load, never read live. */
const LEGACY_KEY = "jarvis.wallpaper.v1";
+/**
+ * One-time move of the pre-per-theme pick into a per-theme slot.
+ *
+ * The old slot used to be read as a live fallback for BOTH modes, and that is
+ * how a night scene ended up behind light chrome: whichever mode had no pick
+ * of its own inherited the other mode's picture, forever. A wallpaper belongs
+ * to exactly one mode, so the fallback is gone and the stored pick is filed
+ * once, under the mode it was authored for.
+ *
+ * The single-slot world switched the interface into every adopted picture's
+ * mode and persisted that switch, so the cached theme at the moment this first
+ * runs is the best witness for which mode the old pick belongs to. Worst case
+ * it is filed under the wrong one and the next pick overwrites it — a one-time
+ * cost, where the live fallback was a standing one.
+ */
+function migrateLegacySelection(): void {
+ if (typeof window === "undefined") return;
+ try {
+ const legacy = window.localStorage.getItem(LEGACY_KEY);
+ if (legacy && legacy.trim()) {
+ const slot = THEME_KEYS[cachedTheme()];
+ if (!window.localStorage.getItem(slot)) {
+ window.localStorage.setItem(slot, legacy);
+ }
+ }
+ window.localStorage.removeItem(LEGACY_KEY);
+ } catch {
+ /* storage blocked — then there is no stored pick to migrate either */
+ }
+}
+
/**
* The shortlist of wallpapers worth coming back to.
*
@@ -76,9 +106,7 @@ export function wallpaperThumbUrl(id: string): string {
function readStoredId(theme: Theme): string | null {
try {
const own = window.localStorage.getItem(THEME_KEYS[theme]);
- if (own && own.trim()) return own;
- const legacy = window.localStorage.getItem(LEGACY_KEY);
- return legacy && legacy.trim() ? legacy : null;
+ return own && own.trim() ? own : null;
} catch {
// Private mode, or storage disabled by policy — the default is a fine
// answer, and a wallpaper is not worth failing a mount over.
@@ -88,6 +116,7 @@ function readStoredId(theme: Theme): string | null {
function readSelections(): Record<Theme, string | null> {
if (typeof window === "undefined") return { light: null, dark: null };
+ migrateLegacySelection();
return { light: readStoredId("light"), dark: readStoredId("dark") };
}
@@ -140,10 +169,6 @@ export const useWallpaperStore = create<WallpaperStore>((set, get) => ({
try {
if (id) window.localStorage.setItem(THEME_KEYS[theme], id);
else window.localStorage.removeItem(THEME_KEYS[theme]);
- // The legacy slot must not outvote an explicit "back to default": it is
- // only a fallback for modes that never chose, so an empty per-theme pick
- // needs the legacy value gone or it would resurrect the old picture.
- if (!id) window.localStorage.removeItem(LEGACY_KEY);
} catch {
/* the choice still applies to this window, it just will not survive */
}