Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(wallpaper): import keeps the recent image and refuses non-regular files

Enes Kirca9d32f6fa4709
diff --git a/CLAUDE.md b/CLAUDE.md
index a54c93cb7..1d9d1606e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -3819,11 +3819,12 @@ glass never sits over plain black; a wallpaper the user chose is never replaced.
URL is ~3 MB, so the shorthand resolved to nothing and the canvas stayed black. The class rule
supplies the colour underneath.
- **Images reach the page as data: URLs from core** (`core/wallpaper.ts`, `wallpaper:*` channels,
- registered by BOTH shells), so the CSP is untouched and no protocol was added. The renderer never
- names a path to read: a macOS still is named by its `mac:` id and re-resolved against a fresh scan
+ registered by BOTH shells), so the CSP is untouched and no protocol was added. `load` never
+ reads a renderer-named path: a macOS still is named by its `mac:` id and re-resolved against a fresh scan
of `/System/Library/Desktop Pictures` (read at runtime, NEVER bundled — they are Apple's), and an
imported image must be a hash-named DIRECT child of `<userData>/wallpapers/` (`cachedImagePath`,
- the whole jail). Chromium cannot decode HEIC, so macOS converts with `/usr/bin/sips` to a JPEG
+ the whole jail). `import` is the exception — it copies any image-named regular file the caller
+ names into that cache — which is no wider than the caller's own `fs:read`. Chromium cannot decode HEIC, so macOS converts with `/usr/bin/sips` to a JPEG
≤ 3840px — and `sips -Z` also UPSCALES (measured: 320px → 3840px), so it is passed only when the
image is larger. An import is copied untouched unless it must be converted (HEIC, over 3840px or
over the 25 MB load cap — re-encoding everything would flatten PNG/WebP alpha); off macOS, HEIC or
diff --git a/src/core/wallpaper.ts b/src/core/wallpaper.ts
index 38f7e8780..aeac1d076 100644
--- a/src/core/wallpaper.ts
+++ b/src/core/wallpaper.ts
@@ -23,6 +23,11 @@ import { platform } from './platform'
* child of the cache dir with a hash-shaped name (`cachedImagePath`). So a hand-edited
* settings.json cannot aim `load` at anything else, and there is no traversal to reject because
* no caller-supplied segment is ever joined.
+ *
+ * `import` is the one exception: it takes a caller-supplied source path (the file picker's answer)
+ * and copies any JPEG/PNG/WebP/HEIC-named regular file into the cache, whose bytes `load` then
+ * returns. That is no wider than what the same caller already has (`fs:read` on both shells), but
+ * it means the jail above governs `load`, not what can ENTER the cache.
*/
const run = promisify(execFile)
@@ -240,10 +245,13 @@ export async function importWallpaper(sourcePath: unknown): Promise<DesktopWallp
throw new Error('Choose a JPEG, PNG, WebP or HEIC image.')
}
const src = path.resolve(sourcePath)
- const current = currentWallpaper()
+ const keepNow = currentKeep()
const mac = process.platform === 'darwin'
const heic = /\.heic$/i.test(src)
- const tooBig = (await stat(src)).size > MAX_LOAD_BYTES
+ const srcStat = await stat(src)
+ // A FIFO or device named `x.png` would hang copyFile/sips and wedge publishOnce for the run.
+ if (!srcStat.isFile()) throw new Error('Choose a JPEG, PNG, WebP or HEIC image.')
+ const tooBig = srcStat.size > MAX_LOAD_BYTES
let result: DesktopWallpaper
if (mac && (heic || tooBig || ((await longEdge(src)) ?? Infinity) > FULL_PX)) {
result = { kind: 'image', path: await convertWithSips(src, FULL_PX, '') }
@@ -257,9 +265,11 @@ export async function importWallpaper(sourcePath: unknown): Promise<DesktopWallp
await publishOnce(target, (tmp) => copyFile(src, tmp))
result = { kind: 'image', path: target }
}
- // The setting is written by the renderer after this returns, so keep BOTH the new file and
- // whatever is on screen now; the settings hook prunes the old one once the choice lands.
- void pruneWallpaperCache([current, result])
+ // The setting is written by the renderer after this returns, so keep the new file AND everything
+ // the saved settings still name (the wallpaper on screen and the "Your image" tile's recent import):
+ // if that save never lands, nothing the settings point at may be gone. The settings hook prunes
+ // the old ones once the choice is saved.
+ void pruneWallpaperCache([...keepNow, result])
return result
}
@@ -302,7 +312,7 @@ export async function pruneWallpaperCache(keep: unknown[], dir = wallpaperCacheD
}
}
-let currentWallpaper: () => unknown = () => undefined
+let currentKeep: () => unknown[] = () => []
/**
* Wire onto the platform's RPC surface (Electron ipcMain / server WS-RPC alike). The settings
@@ -315,7 +325,7 @@ export function registerWallpaperIpc(settings: {
get: () => { desktopWallpaper?: unknown; recentWallpaperImage?: unknown }
onChange: (cb: (s: { desktopWallpaper?: unknown; recentWallpaperImage?: unknown }) => void) => unknown
}): void {
- currentWallpaper = () => settings.get().desktopWallpaper
+ currentKeep = () => wallpapersToKeep(settings.get())
// The user's most recent import is kept too (`wallpapersToKeep`): choosing a preset must not
// delete the image the "Your image" tile still offers.
const key = (s: { desktopWallpaper?: unknown; recentWallpaperImage?: unknown }): string =>