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): pin the bundled original as the first tile

rubenluetke10-beepc1ebdfcacc8e
diff --git a/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts b/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts
new file mode 100644
index 0000000000..b4a901b278
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/hooks/useApplyWallpaper.ts
@@ -0,0 +1,44 @@
+import { useCallback } from "react";
+
+import { useTheme, type Theme } from "@/hooks/useTheme";
+import type { WallpaperEntry } from "@/hooks/useWallpaperCatalog";
+import { useWallpaperStore } from "@/store/wallpaper";
+
+/**
+ * The theme the bundled artwork belongs to.
+ *
+ * It is a night scene — a moonlit woodblock ocean — so returning to the default
+ * wallpaper returns to dark mode. This also happens to be the app's own default
+ * preference, which is why a fresh profile is consistent from the first paint.
+ */
+export const DEFAULT_WALLPAPER_THEME: Theme = "dark";
+
+/**
+ * Adopt a wallpaper, and take the interface theme with it.
+ *
+ * Light and dark mode here are not an independent setting the user has to keep
+ * in sync by hand: the wallpaper IS the app's ground, and every one of the five
+ * hundred is authored for one of the two. A bright daylight scene under dark
+ * chrome reads as a mistake, so choosing the picture chooses the mode.
+ *
+ * Both halves persist through the machinery that already owns them — the
+ * wallpaper through localStorage, the theme through the appearance endpoint —
+ * so nothing here invents a second source of truth. The theme switcher in
+ * Settings keeps working afterwards; it is the next wallpaper, not this one,
+ * that overrides a manual change.
+ */
+export function useApplyWallpaper(): (item: WallpaperEntry | null) => void {
+ const select = useWallpaperStore((state) => state.select);
+ const { setPreference } = useTheme();
+
+ return useCallback(
+ (item: WallpaperEntry | null) => {
+ // 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);
+ },
+ [select, setPreference],
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/hooks/useWallpaperCatalog.ts b/jarvis/ui/web/frontend/src/hooks/useWallpaperCatalog.ts
index d1b20f6aec..6654e22e65 100644
--- a/jarvis/ui/web/frontend/src/hooks/useWallpaperCatalog.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useWallpaperCatalog.ts
@@ -1,5 +1,8 @@
import { useQuery } from "@tanstack/react-query";
+import { DEFAULT_WALLPAPER_URL } from "@/hooks/useDesktopWallpaper";
+import { wallpaperFullUrl, wallpaperThumbUrl } from "@/store/wallpaper";
+
/** One wallpaper as the browse grid knows it — metadata only, no pixels. */
export interface WallpaperEntry {
id: string;
@@ -9,6 +12,12 @@ export interface WallpaperEntry {
/** Written-out style name for the filter chips, e.g. `Cinematic Anime Neon`. */
styleLabel: string;
theme: "light" | "dark";
+ /**
+ * True for the one wallpaper that ships inside the app rather than in the
+ * generated library. It is pinned to the front of the grid and its pixels
+ * come from the bundle, not from `/api/wallpapers`.
+ */
+ isDefault?: boolean;
}
export interface WallpaperStyle {
@@ -18,18 +27,59 @@ export interface WallpaperStyle {
}
export interface WallpaperCatalog {
- /** False when the generated library is not installed on this machine. */
+ /** Always true — the bundled original is a wallpaper the grid can show. */
available: boolean;
+ /** False when the generated 500-piece library is not installed here. */
+ libraryAvailable: boolean;
count: number;
styles: WallpaperStyle[];
items: WallpaperEntry[];
}
-const EMPTY_CATALOG: WallpaperCatalog = {
- available: false,
- count: 0,
- styles: [],
- items: [],
+/** The filter slug and chip label the bundled original lives under. */
+export const DEFAULT_WALLPAPER_STYLE = "original";
+
+/**
+ * The wallpaper the app ships with — the first one ever made for it, and the
+ * one it falls back to.
+ *
+ * It is assembled here instead of being copied into the generated library so
+ * that it is present unconditionally: the library is optional content under a
+ * git-ignored directory, this picture is part of the program. Its pixels come
+ * from the same bundled asset the shell already paints, so putting it in the
+ * grid costs no download at all.
+ */
+export const DEFAULT_WALLPAPER_ENTRY: WallpaperEntry = {
+ id: "original",
+ title: "The Original",
+ style: DEFAULT_WALLPAPER_STYLE,
+ styleLabel: "Original",
+ // A moonlit woodblock ocean — see useApplyWallpaper.DEFAULT_WALLPAPER_THEME,
+ // which has to agree with this or returning to the default would flip the
+ // interface to the wrong mode.
+ theme: "dark",
+ isDefault: true,
+};
+
+/** Where a grid tile's thumbnail comes from. */
+export function thumbUrlFor(item: WallpaperEntry): string {
+ return item.isDefault ? DEFAULT_WALLPAPER_URL : wallpaperThumbUrl(item.id);
+}
+
+/** Where a preview's full-size image comes from. */
+export function fullUrlFor(item: WallpaperEntry): string {
+ return item.isDefault ? DEFAULT_WALLPAPER_URL : wallpaperFullUrl(item.id);
+}
+
+/** The catalog as it looks before (or without) the generated library. */
+const BUNDLED_ONLY: WallpaperCatalog = {
+ available: true,
+ libraryAvailable: false,
+ count: 1,
+ styles: [
+ { slug: DEFAULT_WALLPAPER_STYLE, label: "Original", count: 1 },
+ ],
+ items: [DEFAULT_WALLPAPER_ENTRY],
};
/**
@@ -39,6 +89,10 @@ const EMPTY_CATALOG: WallpaperCatalog = {
* and it only changes when the library on disk is regenerated, so it is
* fetched once per session and kept — refetching it on every visit to the
* section would buy nothing.
+ *
+ * The bundled original is prepended to whatever the server returns, so the
+ * section has something to show even when the request fails or the library was
+ * never generated on this machine.
*/
export function useWallpaperCatalog() {
return useQuery<WallpaperCatalog>({
@@ -46,15 +100,26 @@ export function useWallpaperCatalog() {
staleTime: Infinity,
retry: 1,
queryFn: async () => {
- const response = await fetch("/api/wallpapers");
- if (!response.ok) throw new Error(`Wallpaper catalog failed: ${response.status}`);
- const data = (await response.json()) as Partial<WallpaperCatalog> | null;
- if (!data || !Array.isArray(data.items)) return EMPTY_CATALOG;
+ // A failure here is not an error state for the section: the bundled
+ // original is still a wallpaper, and showing it beats showing a stack
+ // trace because a backend was mid-restart.
+ const data = await fetch("/api/wallpapers")
+ .then((response) =>
+ response.ok
+ ? (response.json() as Promise<Partial<WallpaperCatalog> | null>)
+ : null,
+ )
+ .catch(() => null);
+ if (!data || !Array.isArray(data.items) || !data.items.length) {
+ return BUNDLED_ONLY;
+ }
+ const styles = Array.isArray(data.styles) ? data.styles : [];
return {
- available: Boolean(data.available),
- count: typeof data.count === "number" ? data.count : data.items.length,
- styles: Array.isArray(data.styles) ? data.styles : [],
- items: data.items,
+ available: true,
+ libraryAvailable: Boolean(data.available),
+ count: (typeof data.count === "number" ? data.count : data.items.length) + 1,
+ styles: [BUNDLED_ONLY.styles[0], ...styles],
+ items: [DEFAULT_WALLPAPER_ENTRY, ...data.items],
};
},
});
diff --git a/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx b/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
index b485e14fe0..defa98a76f 100644
--- a/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/WallpaperView.test.tsx
@@ -9,6 +9,7 @@ import {
} from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { ThemeProvider } from "@/hooks/useTheme";
import { WallpaperView } from "@/views/WallpaperView";
import { useWallpaperStore } from "@/store/wallpaper";
@@ -52,13 +53,22 @@ function renderView(catalog: unknown = CATALOG) {
const client = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
+ // A real ThemeProvider, not a stub: applying a wallpaper is supposed to move
+ // the theme, and the assertion for that is the class on <html>.
return render(
<QueryClientProvider client={client}>
- <WallpaperView />
+ <ThemeProvider>
+ <WallpaperView />
+ </ThemeProvider>
</QueryClientProvider>,
);
}
+/** True while the app is painted dark. */
+function isDark(): boolean {
+ return document.documentElement.classList.contains("dark");
+}
+
/** Every `<img>` the grid and preview have actually asked the browser for. */
function requestedSources(): string[] {
return Array.from(document.querySelectorAll("img")).map((img) =>
@@ -69,6 +79,7 @@ function requestedSources(): string[] {
beforeEach(() => {
window.localStorage.clear();
useWallpaperStore.setState({ selectedId: null });
+ document.documentElement.classList.add("dark");
});
afterEach(() => {
@@ -81,13 +92,59 @@ describe("WallpaperView", () => {
renderView();
await screen.findByAltText("Flooded Observatory");
- const sources = requestedSources();
+ // The bundled original rides along as a fourth tile, served from the app
+ // bundle rather than from /api/wallpapers.
+ const sources = requestedSources().filter((src) => src.includes("/api/"));
expect(sources).toHaveLength(3);
expect(sources.every((src) => src.endsWith("/thumb"))).toBe(true);
expect(sources.some((src) => src.endsWith("/full"))).toBe(false);
});
+ it("pins the original to the very first tile", async () => {
+ renderView();
+
+ await screen.findByAltText("Flooded Observatory");
+ const tiles = [...document.querySelectorAll('[data-testid="wallpaper-grid"] img')];
+
+ expect(tiles).toHaveLength(4);
+ expect(tiles[0].getAttribute("alt")).toBe("The Original");
+ expect(tiles[0].getAttribute("src")).not.toContain("/api/");
+ });
+
+ it("keeps the original first when sorting by style", async () => {
+ renderView();
+
+ fireEvent.click(await screen.findByRole("button", { name: "By style" }));
+
+ await waitFor(() => {
+ const first = document.querySelector('[data-testid="wallpaper-grid"] img');
+ expect(first?.getAttribute("alt")).toBe("The Original");
+ });
+ });
+
+ it("marks the original as in use while no choice is stored", async () => {
+ renderView();
+
+ fireEvent.click(await screen.findByAltText("The Original"));
+
+ expect(await screen.findByRole("button", { name: /In use/ })).toBeTruthy();
+ });
+
+ it("adopting the original clears the stored choice rather than storing an id", async () => {
+ renderView();
+ act(() => useWallpaperStore.getState().select("03-anime-neon-01"));
+
+ 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(window.localStorage.getItem("jarvis.wallpaper.v1")).toBeNull();
+ expect(isDark()).toBe(true);
+ });
+
it("downloads the full-size image only once a wallpaper is previewed", async () => {
renderView();
@@ -113,6 +170,44 @@ describe("WallpaperView", () => {
);
});
+ it("switches the interface to light with a light wallpaper", async () => {
+ renderView();
+
+ fireEvent.click(await screen.findByAltText("Morning Atrium"));
+ fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
+
+ await waitFor(() => expect(isDark()).toBe(false));
+ });
+
+ it("switches back to dark when a dark wallpaper is picked next", async () => {
+ renderView();
+
+ // Go light first, so the second pick is a real transition rather than a
+ // no-op against the app's dark default.
+ fireEvent.click(await screen.findByAltText("Morning Atrium"));
+ fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
+ await waitFor(() => expect(isDark()).toBe(false));
+
+ fireEvent.click(screen.getByRole("button", { name: "Close preview" }));
+ fireEvent.click(await screen.findByAltText("Neon Crossing"));
+ fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
+
+ await waitFor(() => expect(isDark()).toBe(true));
+ });
+
+ it("returns to dark along with the bundled default", async () => {
+ renderView();
+
+ fireEvent.click(await screen.findByAltText("Morning Atrium"));
+ fireEvent.click(await screen.findByRole("button", { name: "Use this wallpaper" }));
+ await waitFor(() => expect(isDark()).toBe(false));
+
+ fireEvent.click(await screen.findByRole("button", { name: /Default/ }));
+
+ await waitFor(() => expect(isDark()).toBe(true));
+ expect(useWallpaperStore.getState().selectedId).toBeNull();
+ });
+
it("returns to the bundled default", async () => {
renderView();
act(() => useWallpaperStore.getState().select("03-anime-neon-01"));
@@ -148,9 +243,24 @@ describe("WallpaperView", () => {
expect(requestedSources()).toEqual(before);
});
- it("explains itself instead of breaking when the library is absent", async () => {
+ it("still offers the original when the library is absent", async () => {
renderView({ available: false, count: 0, styles: [], items: [] });
- expect(await screen.findByText("No wallpaper library installed")).toBeTruthy();
+ expect(await screen.findByAltText("The Original")).toBeTruthy();
+ expect(screen.getByText(/No wallpaper library installed/)).toBeTruthy();
+ });
+
+ it("still offers the original when the catalog request fails", async () => {
+ vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("backend restarting")));
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ render(
+ <QueryClientProvider client={client}>
+ <ThemeProvider>
+ <WallpaperView />
+ </ThemeProvider>
+ </QueryClientProvider>,
+ );
+
+ expect(await screen.findByAltText("The Original")).toBeTruthy();
});
});
diff --git a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
index 70ee3befe0..89b14201c6 100644
--- a/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
+++ b/jarvis/ui/web/frontend/src/views/WallpaperView.tsx
@@ -15,14 +15,13 @@ import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import { ViewHeader } from "@/views/ChatsView";
import {
+ fullUrlFor,
+ thumbUrlFor,
useWallpaperCatalog,
type WallpaperEntry,
} from "@/hooks/useWallpaperCatalog";
-import {
- useWallpaperStore,
- wallpaperFullUrl,
- wallpaperThumbUrl,
-} from "@/store/wallpaper";
+import { useApplyWallpaper } from "@/hooks/useApplyWallpaper";
+import { useWallpaperStore } from "@/store/wallpaper";
import { cn } from "@/lib/utils";
type ThemeFilter = "all" | "light" | "dark";
@@ -104,9 +103,11 @@ function WallpaperTile({
)}
>
<img
- src={wallpaperThumbUrl(item.id)}
+ src={thumbUrlFor(item)}
alt={item.title}
- loading="lazy"
+ // The pinned original is the first thing on screen and the shell has
+ // already loaded it, so waiting for an intersection buys nothing.
+ loading={item.isDefault ? "eager" : "lazy"}
decoding="async"
width={480}
height={270}
@@ -207,7 +208,7 @@ function WallpaperPreview({
)}
<img
key={item.id}
- src={wallpaperFullUrl(item.id)}
+ src={fullUrlFor(item)}
alt={item.title}
onLoad={() => setLoaded(true)}
onError={() => setLoaded(true)}
@@ -241,14 +242,14 @@ function WallpaperPreview({
* The Wallpaper section: browse the generated library, preview one at full
* size, and adopt it as the app's ground.
*
- * Nothing here writes to the server. The choice is a local preference and the
- * bundled artwork is always one click away again, so trying a wallpaper is
- * meant to feel as reversible as it actually is.
+ * Adopting one also switches light/dark to match the artwork — see
+ * `useApplyWallpaper`. The bundled default is always one click away again, so
+ * trying a wallpaper is meant to feel as reversible as it actually is.
*/
export function WallpaperView() {
- const { data, isLoading, isError } = useWallpaperCatalog();
+ const { data, isLoading } = useWallpaperCatalog();
const selectedId = useWallpaperStore((state) => state.selectedId);
- const select = useWallpaperStore((state) => state.select);
+ const apply = useApplyWallpaper();
const [theme, setTheme] = useState<ThemeFilter>("all");
const [ordering, setOrdering] = useState<Ordering>("mixed");
@@ -265,6 +266,9 @@ export function WallpaperView() {
(style === null || item.style === style),
);
return filtered.sort((left, right) => {
+ // The bundled original outranks every ordering and every shuffle: it is
+ // the first wallpaper this app ever had, and it stays the first tile.
+ if (left.isDefault !== right.isDefault) return left.isDefault ? -1 : 1;
if (ordering === "style") {
const byStyle = left.style.localeCompare(right.style);
if (byStyle !== 0) return byStyle;
@@ -274,6 +278,11 @@ export function WallpaperView() {
});
}, [items, ordering, style, theme]);
+ // "No choice stored" and "the original is chosen" are the same state, so the
+ // pinned tile carries the check mark on a fresh profile.
+ const isApplied = (item: WallpaperEntry) =>
+ item.isDefault ? selectedId === null : item.id === selectedId;
+
const previewIndex = previewId
? visible.findIndex((item) => item.id === previewId)
: -1;
@@ -295,13 +304,13 @@ export function WallpaperView() {
icon={<ImageIcon className="h-4 w-4 text-primary" />}
title="Wallpaper"
subtitle={
- data?.available
- ? `${data.count} wallpapers · ${styles.length} styles · previews load on demand`
+ data
+ ? `${data.count} wallpapers · ${styles.length} styles · picking one sets light or dark to match`
: "The app's desktop background"
}
right={
selectedId ? (
- <Button size="sm" variant="outline" onClick={() => select(null)}>
+ <Button size="sm" variant="outline" onClick={() => apply(null)}>
<RotateCcw className="mr-1.5 h-3.5 w-3.5" />
Default
</Button>
@@ -321,31 +330,24 @@ export function WallpaperView() {
);
}
- if (isError || !data?.available) {
- return (
- <div className="flex h-full flex-col">
- {header}
- <div className="flex flex-1 items-center justify-center px-6">
- <div className="max-w-md text-center">
- <p className="text-sm font-medium">No wallpaper library installed</p>
- <p className="mt-1 text-xs text-muted-foreground">
- The generated collection lives in{" "}
- <code className="rounded bg-secondary/60 px-1 py-0.5">
- data/jarvis-wallpaper-gallery
- </code>
- , which is not part of the repository. The app keeps its built-in
- wallpaper until that folder is present.
- </p>
- </div>
- </div>
- </div>
- );
- }
-
return (
<div className="flex h-full flex-col">
{header}
+ {!data?.libraryAvailable && (
+ <p className="border-b border-border px-6 py-2.5 text-xs text-muted-foreground">
+ <span className="font-medium text-foreground">
+ No wallpaper library installed.
+ </span>{" "}
+ The generated collection lives in{" "}
+ <code className="rounded bg-secondary/60 px-1 py-0.5">
+ data/jarvis-wallpaper-gallery
+ </code>
+ , which is not part of the repository. Until it is there, the original
+ below is the whole choice.
+ </p>
+ )}
+
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 border-b border-border px-6 py-3">
<div className="flex items-center gap-1 rounded-lg border border-border p-0.5">
<SegmentButton active={theme === "all"} onClick={() => setTheme("all")}>
@@ -403,7 +405,7 @@ export function WallpaperView() {
<WallpaperTile
key={item.id}
item={item}
- active={item.id === selectedId}
+ active={isApplied(item)}
onOpen={() => setPreviewId(item.id)}
/>
))}
@@ -418,8 +420,8 @@ export function WallpaperView() {
{previewItem && (
<WallpaperPreview
item={previewItem}
- applied={previewItem.id === selectedId}
- onApply={() => select(previewItem.id)}
+ applied={isApplied(previewItem)}
+ onApply={() => apply(previewItem)}
onClose={() => setPreviewId(null)}
onStep={step}
/>