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.

feat(wallpaper): one wallpaper per theme, swapped by the mode toggle

rubenluetke10-beepbc3a5f6bc50b
diff --git a/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts b/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts
index b4a901b278..dff8beabf4 100644
--- a/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts
@@ -36,8 +36,13 @@ export function useApplyWallpaper(): (item: WallpaperEntry | null) => void {
// The bundled original has a grid tile of its own, but adopting it is
// the same act as clearing the choice: one stored state for one picture,
// so the tile and the "Default" button can never disagree.
- select(item && !item.isDefault ? item.id : null);
- setPreference(item?.theme ?? DEFAULT_WALLPAPER_THEME);
+ //
+ // The pick is filed under the theme the picture was AUTHORED for — the
+ // same theme the app is about to switch into. Each mode keeps its own
+ // picture, so a later manual theme toggle brings the right one back.
+ const theme = item?.theme ?? DEFAULT_WALLPAPER_THEME;
+ select(item && !item.isDefault ? item.id : null, theme);
+ setPreference(theme);
},
[select, setPreference],
);
diff --git a/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.test.tsx b/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.test.tsx
index 5266386b30..630ff793ed 100644
--- a/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.test.tsx
+++ b/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.test.tsx
@@ -41,7 +41,9 @@ function Probe() {
beforeEach(() => {
pending = [];
window.localStorage.clear();
- useWallpaperStore.setState({ selectedId: null });
+ // No ThemeProvider in these tests and no `dark` class on <html>, so the
+ // hook resolves the light slot; the picks below are filed there.
+ useWallpaperStore.setState({ selections: { light: null, dark: null } });
vi.stubGlobal("Image", TestImage);
});
@@ -60,7 +62,7 @@ describe("useDesktopWallpaper", () => {
it("keeps the old picture on screen until the new one has loaded", async () => {
render(<Probe />);
- act(() => useWallpaperStore.getState().select("03-anime-neon-01"));
+ act(() => useWallpaperStore.getState().select("03-anime-neon-01", "light"));
// Requested, but not yet painted — the shell must not go blank meanwhile.
expect(pending[0]?.src).toBe("/api/wallpapers/03-anime-neon-01/full");
@@ -76,7 +78,9 @@ describe("useDesktopWallpaper", () => {
});
it("falls back to the bundled wallpaper when the library is missing", async () => {
- useWallpaperStore.setState({ selectedId: "03-anime-neon-01" });
+ useWallpaperStore.setState({
+ selections: { light: "03-anime-neon-01", dark: null },
+ });
render(<Probe />);
act(() => pending[0]?.onerror?.(new Event("error") as never));
diff --git a/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.ts b/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.ts
index c89b6981aa..b0648563be 100644
--- a/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useDesktopWallpaper.ts
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import jarvisDesktopWallpaper from "@/assets/jarvis-desktop-wallpaper.webp";
+import { useThemeValue } from "@/hooks/useTheme";
import { useWallpaperStore, wallpaperFullUrl } from "@/store/wallpaper";
/** The artwork that ships inside the bundle — the default and the fallback. */
@@ -21,7 +22,9 @@ export const DEFAULT_WALLPAPER_URL = jarvisDesktopWallpaper;
* not there.
*/
export function useDesktopWallpaper(): string {
- const selectedId = useWallpaperStore((state) => state.selectedId);
+ // The pick is per theme: toggling the mode swaps in that mode's picture.
+ const theme = useThemeValue();
+ const selectedId = useWallpaperStore((state) => state.selections[theme]);
const [url, setUrl] = useState(DEFAULT_WALLPAPER_URL);
useEffect(() => {
diff --git a/jarvis/ui/web/frontend/src/store/wallpaper.ts b/jarvis/ui/web/frontend/src/store/wallpaper.ts
index 9d1eaa7b8b..81b494cb5f 100644
--- a/jarvis/ui/web/frontend/src/store/wallpaper.ts
+++ b/jarvis/ui/web/frontend/src/store/wallpaper.ts
@@ -1,7 +1,16 @@
import { create } from "zustand";
+import type { Theme } from "@/hooks/useTheme";
+
/**
- * Which desktop wallpaper the app is wearing.
+ * Which desktop wallpaper the app is wearing — one choice PER THEME.
+ *
+ * Every catalog picture is authored for one of the two modes (a daylight
+ * terrace for light, a moonlit ocean for dark), and picking one switches the
+ * app into that mode (`useApplyWallpaper`). A single shared slot therefore
+ * could not survive a manual theme toggle: the bright picture stayed behind
+ * dark chrome and read as a mistake. Each mode keeps its own pick instead,
+ * and toggling the theme brings that mode's picture back with it.
*
* The bundled artwork stays the default and the fallback: an empty selection
* means "the one that ships with the app", so a fresh profile, a cleared
@@ -13,7 +22,14 @@ import { create } from "zustand";
* one store every window of the app — including the detached solo windows —
* already shares.
*/
-const STORAGE_KEY = "jarvis.wallpaper.v1";
+const THEME_KEYS: Record<Theme, string> = {
+ light: "jarvis.wallpaper.light.v1",
+ 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. */
+const LEGACY_KEY = "jarvis.wallpaper.v1";
/** Where a chosen wallpaper's full-size file is served from. */
export function wallpaperFullUrl(id: string): string {
@@ -25,10 +41,12 @@ export function wallpaperThumbUrl(id: string): string {
return `/api/wallpapers/${encodeURIComponent(id)}/thumb`;
}
-function readStoredId(): string | null {
+function readStoredId(theme: Theme): string | null {
try {
- const stored = window.localStorage.getItem(STORAGE_KEY);
- return stored && stored.trim() ? stored : null;
+ 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;
} catch {
// Private mode, or storage disabled by policy — the default is a fine
// answer, and a wallpaper is not worth failing a mount over.
@@ -36,27 +54,36 @@ function readStoredId(): string | null {
}
}
+function readSelections(): Record<Theme, string | null> {
+ if (typeof window === "undefined") return { light: null, dark: null };
+ return { light: readStoredId("light"), dark: readStoredId("dark") };
+}
+
interface WallpaperStore {
- /** The chosen wallpaper's id, or null for the bundled default. */
- selectedId: string | null;
- /** Persist a choice. Pass null to go back to the bundled default. */
- select: (id: string | null) => void;
- /** Adopt a choice made in another window. Does not write back. */
- adopt: (id: string | null) => void;
+ /** Each theme's chosen wallpaper id, or null for the bundled default. */
+ selections: Record<Theme, string | null>;
+ /** Persist a choice for one theme. Pass null to go back to the default. */
+ select: (id: string | null, theme: Theme) => void;
+ /** Adopt choices made in another window. Does not write back. */
+ adopt: () => void;
}
export const useWallpaperStore = create<WallpaperStore>((set) => ({
- selectedId: typeof window === "undefined" ? null : readStoredId(),
- select: (id) => {
+ selections: readSelections(),
+ select: (id, theme) => {
try {
- if (id) window.localStorage.setItem(STORAGE_KEY, id);
- else window.localStorage.removeItem(STORAGE_KEY);
+ 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 */
}
- set({ selectedId: id });
+ set({ selections: readSelections() });
},
- adopt: (id) => set({ selectedId: id }),
+ adopt: () => set({ selections: readSelections() }),
}));
/**
@@ -68,9 +95,10 @@ export const useWallpaperStore = create<WallpaperStore>((set) => ({
*/
export function installWallpaperSync(): () => void {
if (typeof window === "undefined") return () => {};
+ const watched = new Set<string>([LEGACY_KEY, THEME_KEYS.light, THEME_KEYS.dark]);
const onStorage = (event: StorageEvent) => {
- if (event.key !== null && event.key !== STORAGE_KEY) return;
- useWallpaperStore.getState().adopt(readStoredId());
+ if (event.key !== null && !watched.has(event.key)) return;
+ useWallpaperStore.getState().adopt();
};
window.addEventListener("storage", onStorage);
return () => window.removeEventListener("storage", onStorage);
diff --git a/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx b/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
index defa98a76f..5f640d2798 100644
--- a/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
@@ -78,7 +78,7 @@ function requestedSources(): string[] {
beforeEach(() => {
window.localStorage.clear();
- useWallpaperStore.setState({ selectedId: null });
+ useWallpaperStore.setState({ selections: { light: null, dark: null } });
document.documentElement.classList.add("dark");
});
@@ -133,13 +133,13 @@ describe("WallpaperView", () => {
it("adopting the original clears the stored choice rather than storing an id", async () => {
renderView();
- act(() => useWallpaperStore.getState().select("03-anime-neon-01"));
+ act(() => useWallpaperStore.getState().select("03-anime-neon-01", "dark"));
fireEvent.click(await screen.findByAltText("The Original"));
fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
await waitFor(() => {
- expect(useWallpaperStore.getState().selectedId).toBeNull();
+ expect(useWallpaperStore.getState().selections.dark).toBeNull();
});
expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
expect(isDark()).toBe(true);
@@ -161,11 +161,11 @@ describe("WallpaperView", () => {
fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
await waitFor(() => {
- expect(useWallpaperStore.getState().selectedId).toBe(
+ expect(useWallpaperStore.getState().selections.light).toBe(
"01-cinematic-photoreal-02",
);
});
- expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBe(
+ expect(window.localStorage.getItem("jarvis.wallpaper.light.v1")).toBe(
"01-cinematic-photoreal-02",
);
});
@@ -205,16 +205,16 @@ describe("WallpaperView", () => {
fireEvent.click(await screen.findByRole("button", { name: /Default/ }));
await waitFor(() => expect(isDark()).toBe(true));
- expect(useWallpaperStore.getState().selectedId).toBeNull();
+ expect(useWallpaperStore.getState().selections.dark).toBeNull();
});
it("returns to the bundled default", async () => {
renderView();
- act(() => useWallpaperStore.getState().select("03-anime-neon-01"));
+ act(() => useWallpaperStore.getState().select("03-anime-neon-01", "dark"));
fireEvent.click(await screen.findByRole("button", { name: /Default/ }));
- expect(useWallpaperStore.getState().selectedId).toBeNull();
+ expect(useWallpaperStore.getState().selections.dark).toBeNull();
expect(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
});
diff --git a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
index 89b14201c6..ef2b0c37af 100644
--- a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
+++ b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
@@ -21,6 +21,7 @@ import {
type WallpaperEntry,
} from "@/hooks/useWallpaperCatalog";
import { useApplyWallpaper } from "@/hooks/useApplyWallpaper";
+import { useThemeValue } from "@/hooks/useTheme";
import { useWallpaperStore } from "@/store/wallpaper";
import { cn } from "@/lib/utils";
@@ -248,7 +249,11 @@ function WallpaperPreview({
*/
export function WallpaperView() {
const { data, isLoading } = useWallpaperCatalog();
- const selectedId = useWallpaperStore((state) => state.selectedId);
+ // Each theme keeps its own pick; the grid marks the one worn by the mode
+ // the app is in right now (adopting a tile switches mode WITH the picture,
+ // so the check mark always lands on what is actually on screen).
+ const activeTheme = useThemeValue();
+ const selectedId = useWallpaperStore((state) => state.selections[activeTheme]);
const apply = useApplyWallpaper();
const [theme, setTheme] = useState<ThemeFilter>("all");