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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(windows): Windows wallpaper stills and nativeImage conversion
review9db312548439
diff --git a/src/core/wallpaper.test.ts b/src/core/wallpaper.test.tsindex 0c752cabe..1425ea1b5 100644--- a/src/core/wallpaper.test.ts+++ b/src/core/wallpaper.test.ts@@ -4,7 +4,21 @@ import path from 'node:path'import { afterEach, describe, expect, it } from 'vitest'import { existsSync, readdirSync } from 'node:fs'import { wallpapersToKeep } from '../shared/wallpaper'-import { cachedImagePath, importWallpaper, pruneWallpaperCache, scanStills } from './wallpaper'+import {+ cachedImagePath,+ importWallpaper,+ listStills,+ loadWallpaper,+ pruneWallpaperCache,+ scanStills,+ setWallpaperHostForTests,+ setWallpaperImageOps,+ sipsImageOps,+ windowsWallpaperRoot,+ type WallpaperImageOps+} from './wallpaper'+import { initPlatform, resetPlatformForTests } from './platform'+import { fakePlatform } from './platform-fake'const HASH = 'a'.repeat(40)let root: string | null = null@@ -91,3 +105,130 @@ describe('pruneWallpaperCache', () => {expect(existsSync(path.join(tmpdir(), 'no-such-wp-cache-xyz'))).toBe(false)})})++describe('Windows stills and image ops', () => {+ let ud: string | null = null+ afterEach(() => {+ setWallpaperHostForTests(null)+ resetPlatformForTests()+ if (ud) rmSync(ud, { recursive: true, force: true })+ ud = null+ })++ /** Fake converter: "converts" by writing a marker JPEG; sizes come from a table. */+ function fakeOps(sizes: Record<string, number | null> = {}, canHeic = false): WallpaperImageOps & {+ converted: string[]+ } {+ const converted: string[] = []+ return {+ id: 'fake',+ canHeic,+ convertUnknownSize: false,+ converted,+ longEdge: async (src) => sizes[path.basename(src)] ?? null,+ toJpeg: async (src, px, out) => {+ converted.push(`${path.basename(src)}@${px}`)+ writeFileSync(out, Buffer.from([0xff, 0xd8, 0xff]))+ }+ }+ }++ function windowsHost(): string {+ root = mkdtempSync(path.join(tmpdir(), 'wp-win-'))+ ud = mkdtempSync(path.join(tmpdir(), 'wp-ud-'))+ initPlatform(fakePlatform({ userDataDir: ud }))+ put('Web/Wallpaper/Windows/img0.jpg', 300_000)+ put('Web/Wallpaper/ThemeA/img20.jpg', 300_000)+ put('Web/Wallpaper/Windows/tiny.jpg', 1000)+ return root+ }++ it('scanStills takes a prefix and a size floor for the Windows tree', async () => {+ const r = windowsHost()+ const list = await scanStills(path.join(r, 'Web', 'Wallpaper'), 2, { prefix: 'win:', minBytes: 200_000 })+ expect(list.map((s) => s.id).sort()).toEqual(['win:ThemeA/img20.jpg', 'win:Windows/img0.jpg'])+ })++ it('the Windows root is %WINDIR%\\Web\\Wallpaper, defaulting to C:\\Windows', () => {+ expect(windowsWallpaperRoot({ WINDIR: 'D:\\Win' })).toBe('D:\\Win\\Web\\Wallpaper')+ expect(windowsWallpaperRoot({})).toBe('C:\\Windows\\Web\\Wallpaper')+ })++ it('win32 with no registered ops lists no stills (nothing to thumbnail with)', async () => {+ windowsHost()+ setWallpaperHostForTests({ platform: 'win32', env: { WINDIR: '/nonexistent' } })+ expect(await listStills()).toEqual([])+ })++ it('linux (the Server Edition) lists nothing and refuses an over-cap or HEIC import, as before', async () => {+ windowsHost()+ setWallpaperHostForTests({ platform: 'linux' })+ expect(await listStills()).toEqual([])+ put('photo.heic', 10)+ await expect(importWallpaper(path.join(root!, 'photo.heic'))).rejects.toThrow(/HEIC images can't be converted/)+ put('ok.png', 10)+ const copied = await importWallpaper(path.join(root!, 'ok.png'))+ expect(copied.kind).toBe('image')+ })++ it('with registered ops: oversized images convert, small ones copy, HEIC is refused without canHeic', async () => {+ const r = windowsHost()+ setWallpaperHostForTests({ platform: 'win32' })+ const ops = fakeOps({ 'big.png': 6000, 'small.png': 1920, 'pic.webp': null })+ setWallpaperImageOps(ops)+ put('big.png', 10)+ put('small.png', 10)+ put('pic.webp', 10)+ put('photo.heic', 10)++ const big = await importWallpaper(path.join(r, 'big.png'))+ expect(big.kind === 'image' && big.path.endsWith('.jpg')).toBe(true)+ expect(ops.converted).toEqual(['big.png@3840'])++ const small = await importWallpaper(path.join(r, 'small.png'))+ expect(small.kind === 'image' && small.path.endsWith('.png')).toBe(true)+ // An unmeasurable WebP is copied, not handed to a decoder that cannot read it.+ const webp = await importWallpaper(path.join(r, 'pic.webp'))+ expect(webp.kind === 'image' && webp.path.endsWith('.webp')).toBe(true)+ expect(ops.converted).toEqual(['big.png@3840'])++ await expect(importWallpaper(path.join(r, 'photo.heic'))).rejects.toThrow(/HEIC/)+ expect(ops.converted).toEqual(['big.png@3840'])+ })++ it('a HEIC converts when the ops can decode it', async () => {+ const r = windowsHost()+ setWallpaperHostForTests({ platform: 'win32' })+ const ops = fakeOps({}, true)+ setWallpaperImageOps(ops)+ put('photo.heic', 10)+ const out = await importWallpaper(path.join(r, 'photo.heic'))+ expect(out.kind === 'image' && out.path.endsWith('.jpg')).toBe(true)+ expect(ops.converted).toEqual(['photo.heic@3840'])+ })++ it('win: stills list with thumbnails and load; an id not in the scan is null (the jail)', async () => {+ const r = windowsHost()+ setWallpaperHostForTests({ platform: 'win32', windowsStillsRoot: path.join(r, 'Web', 'Wallpaper') })+ const ops = fakeOps()+ setWallpaperImageOps(ops)++ const list = await listStills()+ expect(list.map((s) => s.id).sort()).toEqual(['win:ThemeA/img20.jpg', 'win:Windows/img0.jpg'])+ expect(list[0].thumb).toMatch(/^data:image\/jpeg;base64,/)+ expect(ops.converted.sort()).toEqual(['img0.jpg@320', 'img20.jpg@320'])++ expect(await loadWallpaper({ kind: 'preset', id: 'win:Windows/img0.jpg' })).toMatch(/^data:image\/jpeg/)+ expect(await loadWallpaper({ kind: 'preset', id: 'win:Windows/../../secret.jpg' })).toBeNull()+ expect(await loadWallpaper({ kind: 'preset', id: 'mac:Sonoma.heic' })).toBeNull()+ })+})++describe('sipsImageOps', () => {+ it('keeps the historical cache-key id and HEIC/unknown-size semantics (macOS byte-identical)', () => {+ // The id feeds cacheKey: `sips3840` is what every pre-seam macOS cache file was named under.+ expect(sipsImageOps.id).toBe('sips')+ expect(sipsImageOps.canHeic).toBe(true)+ expect(sipsImageOps.convertUnknownSize).toBe(true)+ })+})diff --git a/src/core/wallpaper.ts b/src/core/wallpaper.tsindex aeac1d076..ab9fb1409 100644--- a/src/core/wallpaper.ts+++ b/src/core/wallpaper.ts@@ -17,9 +17,14 @@ import { platform } from './platform'* Wallpaper files for the canvas background (Liquid Glass appearance). Core, so both shells serve* it: on the Server Edition (Linux) the stills list is simply empty and gradients need no files.*+ * Image work (measuring, converting to JPEG) goes through `WallpaperImageOps`. macOS defaults to+ * its built-in `sips`; the Electron shell registers a `nativeImage` implementation on Windows+ * (`src/main/wallpaper-native-image.ts` — core may not import electron). With no ops (Linux, the+ * Server Edition) there are no stills, and HEIC / over-cap imports are refused with a reason.+ ** Every file the renderer can get bytes for lives in ONE directory, `<userData>/wallpapers/`, under* a hash name this module minted. The renderer never names a path to read: a still is named by its- * `mac:` id and re-resolved against a fresh scan, and an imported image's path must be a direct+ * `mac:` / `win:` id and re-resolved against a fresh scan, and an imported image's path must be a direct* 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.@@ -36,6 +41,8 @@ export const SYSTEM_WALLPAPER_DIR = '/System/Library/Desktop Pictures'const SIPS = '/usr/bin/sips'/** Real stills are several MB; the 356px `.madesktop` placeholders and thumbnails are not. */const MIN_STILL_BYTES = 1_000_000+/** Windows' stock JPEGs are far smaller than macOS's HEICs (some theme stills are ~300 KB). */+const MIN_WINDOWS_STILL_BYTES = 200_000const STILL_EXT = /\.(heic|jpe?g|png)$/iconst IMPORT_EXT = /\.(heic|jpe?g|png|webp)$/i/** Shown first, in this order: the scenic ones. */@@ -52,6 +59,66 @@ export interface ScannedStill {path: string}+/**+ * The image converter seam. `id` is part of the cache key, which is why the sips one stays `sips`:+ * every macOS cache file minted before this seam existed keeps its name.+ */+export interface WallpaperImageOps {+ id: string+ /** Can `toJpeg` decode HEIC? (sips: yes; Chromium's nativeImage: no.) */+ canHeic: boolean+ /** An unreadable size counts as "too large" and is converted (sips can read what it cannot+ * measure); false = copy it as-is (nativeImage cannot measure WebP, and cannot convert it). */+ convertUnknownSize: boolean+ /** Long edge in px, or null when it cannot say. */+ longEdge(src: string): Promise<number | null>+ /** Write a JPEG of `src` to `out`, downscaled to `maxPx` on its long edge only when larger. */+ toJpeg(src: string, maxPx: number, out: string): Promise<void>+}++export interface WallpaperHost {+ platform: string+ env: Record<string, string | undefined>+ /** Tests only: the Windows stills root, bypassing `windowsWallpaperRoot(env)`. */+ windowsStillsRoot?: string+}+let host: () => WallpaperHost = () => ({ platform: process.platform, env: process.env })+let registeredOps: WallpaperImageOps | null = null++/** The shell's converter (Electron on Windows). macOS keeps sips whatever is registered. */+export function setWallpaperImageOps(ops: WallpaperImageOps | null): void {+ registeredOps = ops+ stillScan = null+}++/** Tests only: pretend to be another OS / environment, and forget the memoized scan. */+export function setWallpaperHostForTests(next: Partial<WallpaperHost> | null): void {+ host = next+ ? () => ({+ platform: next.platform ?? process.platform,+ env: next.env ?? process.env,+ windowsStillsRoot: next.windowsStillsRoot+ })+ : () => ({ platform: process.platform, env: process.env })+ registeredOps = null+ stillScan = null+}++function imageOps(): WallpaperImageOps | null {+ if (host().platform === 'darwin') return sipsImageOps+ return registeredOps+}++/** A system still's id, on any platform: the prefix names the OS whose scan resolves it. */+export function isSystemStillId(id: string): boolean {+ return id.startsWith('mac:') || id.startsWith('win:')+}++/** `%WINDIR%\Web\Wallpaper` — the stock Windows stills (Windows, ThemeA…, one folder each). */+export function windowsWallpaperRoot(env: Record<string, string | undefined>): string {+ return path.win32.join(env.WINDIR || env.SystemRoot || 'C:\\Windows', 'Web', 'Wallpaper')+}+export function wallpaperCacheDir(): string {return path.join(platform().userDataDir, 'wallpapers')}@@ -61,7 +128,11 @@ export function wallpaperCacheDir(): string {* `.thumbnails` and anything under 1 MB (which is what drops the `.madesktop` placeholders' tiny* siblings). A missing root is an empty list, which is the answer everywhere but macOS.*/-export async function scanStills(root = SYSTEM_WALLPAPER_DIR, depth = 3): Promise<ScannedStill[]> {+export async function scanStills(+ root = SYSTEM_WALLPAPER_DIR,+ depth = 3,+ { prefix = 'mac:', minBytes = MIN_STILL_BYTES }: { prefix?: string; minBytes?: number } = {}+): Promise<ScannedStill[]> {const found: ScannedStill[] = []const walk = async (dir: string, left: number): Promise<void> => {let entries@@ -76,12 +147,12 @@ export async function scanStills(root = SYSTEM_WALLPAPER_DIR, depth = 3): Promisif (e.name !== '.thumbnails' && left > 0) await walk(p, left - 1)} else if (e.isFile() && STILL_EXT.test(e.name)) {try {- if ((await stat(p)).size < MIN_STILL_BYTES) continue+ if ((await stat(p)).size < minBytes) continue} catch {continue}const rel = path.relative(root, p).split(path.sep).join('/')- found.push({ id: `mac:${rel}`, label: e.name.replace(STILL_EXT, ''), path: p })+ found.push({ id: `${prefix}${rel}`, label: e.name.replace(STILL_EXT, ''), path: p })}}}@@ -132,7 +203,7 @@ function publishOnce(target: string, produce: (tmp: string) => Promise<void>): P}/** The long edge of an image in px, per `sips`; null when it cannot say. */-async function longEdge(src: string): Promise<number | null> {+async function sipsLongEdge(src: string): Promise<number | null> {try {const { stdout } = await run(SIPS, ['-g', 'pixelWidth', '-g', 'pixelHeight', src], {timeout: 30_000@@ -149,22 +220,46 @@ async function longEdge(src: string): Promise<number | null> {* `-Z` alone would also UPSCALE (measured: a 320px image comes out 3840px wide), so it is passed* only when the image is actually larger; an unreadable size is treated as larger.*/-function convertWithSips(src: string, px: number, suffix: string): Promise<string> {- return cacheKey(src, `sips${px}`).then((key) =>- publishOnce(path.join(wallpaperCacheDir(), `${key}${suffix}.jpg`), async (tmp) => {- const edge = await longEdge(src)- const resize = edge === null || edge > px ? ['-Z', String(px)] : []- await run(SIPS, ['-s', 'format', 'jpeg', ...resize, src, '--out', tmp], { timeout: 60_000 })- })+export const sipsImageOps: WallpaperImageOps = {+ id: 'sips',+ canHeic: true,+ convertUnknownSize: true,+ longEdge: sipsLongEdge,+ async toJpeg(src, px, out) {+ const edge = await sipsLongEdge(src)+ const resize = edge === null || edge > px ? ['-Z', String(px)] : []+ await run(SIPS, ['-s', 'format', 'jpeg', ...resize, src, '--out', out], { timeout: 60_000 })+ }+}++/** The cache file `convert` publishes for `src` at `px` — also what the prune must keep. */+async function convertedName(ops: WallpaperImageOps, src: string, px: number, suffix: string, dir: string) {+ return path.join(dir, `${await cacheKey(src, `${ops.id}${px}`)}${suffix}.jpg`)+}++function convert(ops: WallpaperImageOps, src: string, px: number, suffix: string): Promise<string> {+ return convertedName(ops, src, px, suffix, wallpaperCacheDir()).then((target) =>+ publishOnce(target, (tmp) => ops.toJpeg(src, px, tmp)))}let stillScan: Promise<ScannedStill[]> | null = nullfunction stills(): Promise<ScannedStill[]> {- if (process.platform !== 'darwin') return Promise.resolve([])+ const { platform: os, env, windowsStillsRoot } = host()// One scan per app run: the system stills only change with an OS update.- stillScan ??= scanStills().catch(() => [])- return stillScan+ if (os === 'darwin') {+ stillScan ??= scanStills().catch(() => [])+ return stillScan+ }+ // Windows lists its stills only when the shell gave us something to thumbnail them with.+ if (os === 'win32' && registeredOps) {+ stillScan ??= scanStills(windowsStillsRoot ?? windowsWallpaperRoot(env), 2, {+ prefix: 'win:',+ minBytes: MIN_WINDOWS_STILL_BYTES+ }).catch(() => [])+ return stillScan+ }+ return Promise.resolve([])}/**@@ -204,8 +299,10 @@ export async function listStills(): Promise<WallpaperStill[]> {const out: WallpaperStill[] = []// Sequential on purpose: a fresh cache runs one `sips` per still, and a dozen at once is a burst// of CPU for a grid of 320px thumbnails. Cached, each is a stat plus a small read.+ const ops = imageOps()for (const s of list) {- const thumb = await convertWithSips(s.path, THUMB_PX, '-t')+ if (!ops) break+ const thumb = await convert(ops, s.path, THUMB_PX, '-t').then(toDataUrl).catch(() => null)out.push({ id: s.id, label: s.label, thumb })@@ -219,10 +316,11 @@ export async function loadWallpaper(value: unknown): Promise<string | null> {const file = cachedImagePath(w.path)return file ? toDataUrl(file) : null}- if (w.kind === 'preset' && w.id.startsWith('mac:')) {- const still = (await stills()).find((s) => s.id === w.id)- if (!still) return null- return convertWithSips(still.path, FULL_PX, '')+ if (w.kind === 'preset' && isSystemStillId(w.id)) {+ const ops = imageOps()+ const still = ops && (await stills()).find((s) => s.id === w.id)+ if (!ops || !still) return null+ return convert(ops, still.path, FULL_PX, '').then(toDataUrl).catch(() => null)}@@ -233,12 +331,13 @@ export async function loadWallpaper(value: unknown): Promise<string | null> {* Put a picked image into the cache and return the value to store. The cached copy is what keeps* the wallpaper when the original moves.*- * The file is copied untouched when the page can show it as-is. On macOS `sips` converts to a- * JPEG ≤ 3840px only when it must: HEIC (Chromium cannot decode it), or an image over 3840px or- * over `load`'s 25 MB cap — a 60 MB camera PNG copied as-is would otherwise be refused at load,- * which reads as a wallpaper that silently never appears. Re-encoding everything would flatten a- * PNG/WebP's alpha and recompress a JPEG for nothing. Elsewhere there is no converter, so HEIC and- * an over-cap image are refused HERE, where the picker can show the reason.+ * The file is copied untouched when the page can show it as-is. The image ops (`sips` on macOS,+ * `nativeImage` on Windows) convert to a JPEG ≤ 3840px only when they must: HEIC (Chromium cannot+ * decode it — and only an ops that `canHeic`), or an image over 3840px or over `load`'s 25 MB cap —+ * a 60 MB camera PNG copied as-is would otherwise be refused at load, which reads as a wallpaper+ * that silently never appears. Re-encoding everything would flatten a PNG/WebP's alpha and+ * recompress a JPEG for nothing. Where no ops can do it, HEIC and an over-cap image are refused+ * HERE, where the picker can show the reason.*/export async function importWallpaper(sourcePath: unknown): Promise<DesktopWallpaper> {if (typeof sourcePath !== 'string' || !IMPORT_EXT.test(sourcePath)) {@@ -246,17 +345,17 @@ export async function importWallpaper(sourcePath: unknown): Promise<DesktopWallp}const src = path.resolve(sourcePath)const keepNow = currentKeep()- const mac = process.platform === 'darwin'+ const ops = imageOps()const heic = /\.heic$/i.test(src)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_BYTESlet result: DesktopWallpaper- if (mac && (heic || tooBig || ((await longEdge(src)) ?? Infinity) > FULL_PX)) {- result = { kind: 'image', path: await convertWithSips(src, FULL_PX, '') }+ if (ops && (heic ? ops.canHeic : tooBig || (await oversize(ops, src)))) {+ result = { kind: 'image', path: await convert(ops, src, FULL_PX, '') }} else {- if (heic) throw new Error('HEIC images can only be converted on macOS.')+ if (heic) throw new Error("HEIC images can't be converted on this system. Choose a JPEG, PNG or WebP.")if (tooBig) {throw new Error(`That image is larger than ${MAX_LOAD_BYTES / 1024 / 1024} MB. Choose a smaller one.`)}@@ -273,15 +372,21 @@ export async function importWallpaper(sourcePath: unknown): Promise<DesktopWallpreturn result}+/** Is this image larger than the full-size cap? An unreadable size asks the ops what that means. */+async function oversize(ops: WallpaperImageOps, src: string): Promise<boolean> {+ const edge = await ops.longEdge(src)+ return edge === null ? ops.convertUnknownSize : edge > FULL_PX+}+/** The cache file a wallpaper value is drawn from, or null for none/gradients/unknown stills. */async function fileFor(value: unknown, dir: string): Promise<string | null> {const w = normalizeWallpaper(value)if (w.kind === 'image') return cachedImagePath(w.path, dir)- if (w.kind === 'preset' && w.id.startsWith('mac:')) {- const still = (await stills()).find((s) => s.id === w.id)- if (!still) return null- const key = await cacheKey(still.path, `sips${FULL_PX}`).catch(() => null)- return key ? path.join(dir, `${key}.jpg`) : null+ if (w.kind === 'preset' && isSystemStillId(w.id)) {+ const ops = imageOps()+ const still = ops && (await stills()).find((s) => s.id === w.id)+ if (!ops || !still) return null+ return convertedName(ops, still.path, FULL_PX, '', dir).catch(() => null)}return null}diff --git a/src/main/index.ts b/src/main/index.tsindex a291f0e9b..2ca3e984a 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -352,7 +352,8 @@ import type { CodexCliCaps } from '../shared/types'import { registerGrokCliIpc } from '../core/grok-cli'import { refreshCodexIdentityCaps, registerCodexIdentityIpc } from '../core/codex-identity-caps'import { codexCliCaps, registerCodexCliIpc } from '../core/codex-cli'-import { registerWallpaperIpc } from '../core/wallpaper'+import { registerWallpaperIpc, setWallpaperImageOps } from '../core/wallpaper'+import { nativeImageWallpaperOps } from './wallpaper-native-image'import { registerRunConfigIpc, stopAllRunWatches } from '../core/run-service'import {bindCodexThreadIdentity,@@ -1529,6 +1530,9 @@ app.whenReady().then(async () => {// What THIS machine's codex accepts for `--ask-for-approval`. Lazy + memoized inside the probe,// so registering it costs nothing until the first Codex launch line asks.registerCodexCliIpc()+ // Windows has no sips: convert (thumbnails, Windows stills, oversized imports) with Chromium's+ // own decoder. macOS keeps sips and Linux keeps no converter, byte for byte.+ if (process.platform === 'win32') setWallpaperImageOps(nativeImageWallpaperOps)registerWallpaperIpc(settingsStore)registerRunConfigIpc()// Warm the `claude --version` probe now (it spawns a login shell + node, ~sub-second) so thediff --git a/src/main/wallpaper-native-image.ts b/src/main/wallpaper-native-image.tsnew file mode 100644index 000000000..cf1f27bd2--- /dev/null+++ b/src/main/wallpaper-native-image.ts@@ -0,0 +1,31 @@+import { nativeImage } from 'electron'+import { writeFile } from 'node:fs/promises'+import type { WallpaperImageOps } from '../core/wallpaper'++/**+ * The Windows wallpaper converter: Chromium's own decoder via `nativeImage` (PNG/JPEG — no HEIC,+ * no WebP), registered by the Electron shell with `setWallpaperImageOps`. Lives in src/main because+ * core may not import electron. A WebP it cannot read measures as `null`, which this ops says to+ * COPY as-is (`convertUnknownSize: false`) — the page can show a WebP, nativeImage cannot convert it.+ */+export const nativeImageWallpaperOps: WallpaperImageOps = {+ id: 'nimg',+ canHeic: false,+ convertUnknownSize: false,+ async longEdge(src) {+ const img = nativeImage.createFromPath(src)+ if (img.isEmpty()) return null+ const { width, height } = img.getSize()+ return Math.max(width, height)+ },+ async toJpeg(src, maxPx, out) {+ let img = nativeImage.createFromPath(src)+ if (img.isEmpty()) throw new Error('That image could not be read. Choose a smaller JPEG or PNG.')+ const { width, height } = img.getSize()+ // Downscale only — never enlarge (same rule as the sips path).+ if (Math.max(width, height) > maxPx) {+ img = img.resize(width >= height ? { width: maxPx, quality: 'best' } : { height: maxPx, quality: 'best' })+ }+ await writeFile(out, img.toJPEG(90))+ }+}diff --git a/src/shared/wallpaper.test.ts b/src/shared/wallpaper.test.tsindex 0845c4aea..41e411a1f 100644--- a/src/shared/wallpaper.test.ts+++ b/src/shared/wallpaper.test.ts@@ -35,3 +35,18 @@ describe('recent wallpaper image (choosing a preset keeps the last import)', ()expect(recentWallpaperImage('')).toBeNull()})})++describe('normalizeWallpaper system-still prefixes', () => {+ it('round-trips mac: and win: still ids', () => {+ expect(normalizeWallpaper({ kind: 'preset', id: 'mac:Sonoma.heic' })).toEqual({ kind: 'preset', id: 'mac:Sonoma.heic' })+ expect(normalizeWallpaper({ kind: 'preset', id: 'win:Windows/img0.jpg' })).toEqual({+ kind: 'preset',+ id: 'win:Windows/img0.jpg'+ })+ })++ it('still collapses an unknown prefix to none', () => {+ expect(normalizeWallpaper({ kind: 'preset', id: 'linux:x.jpg' })).toEqual({ kind: 'none' })+ expect(normalizeWallpaper({ kind: 'preset', id: 'windows:x.jpg' })).toEqual({ kind: 'none' })+ })+})diff --git a/src/shared/wallpaper.ts b/src/shared/wallpaper.tsindex 334abbbcf..3453d9c18 100644--- a/src/shared/wallpaper.ts+++ b/src/shared/wallpaper.ts@@ -11,6 +11,8 @@* - `mac:<path under /System/Library/Desktop Pictures>` presets are the stock macOS stills, read* from disk at runtime and NEVER bundled (they are Apple's). Converted to JPEG by `sips` in* core, since Chromium cannot decode HEIC.+ * - `win:<path under %WINDIR%\\Web\\Wallpaper>` presets are the stock Windows stills, read and+ * converted the same way through Electron's `nativeImage` (desktop only).* - `image` is a picture the user chose, COPIED into `<userData>/wallpapers/` on import so moving* the original does not break it. `path` names that copy; core refuses to read anything else.*/@@ -92,7 +94,11 @@ export function normalizeWallpaper(v: unknown): DesktopWallpaper {const o = v as Record<string, unknown>if (o.kind === 'preset' && typeof o.id === 'string' && o.id.length > 0 && o.id.length < MAX_FIELD) {if (o.id.startsWith('gradient:') && !gradientCss(o.id)) return NO_WALLPAPER- if (!o.id.startsWith('gradient:') && !o.id.startsWith('mac:')) return NO_WALLPAPER+ // `mac:` / `win:` name a system still; core re-resolves it against its OWN fresh scan, so an id+ // from the other OS (a settings.json synced across machines) simply loads nothing there.+ if (!o.id.startsWith('gradient:') && !o.id.startsWith('mac:') && !o.id.startsWith('win:')) {+ return NO_WALLPAPER+ }return { kind: 'preset', id: o.id }}if (o.kind === 'image' && typeof o.path === 'string' && o.path.length > 0 && o.path.length < MAX_FIELD) {@@ -103,8 +109,9 @@ export function normalizeWallpaper(v: unknown): DesktopWallpaper {/*** What Liquid Glass picks when it is chosen with no wallpaper, so glass never sits over plain- * black: the first macOS still (the scan already orders Sonoma Horizon first), else the first- * gradient — the answer on Linux, Windows and the Server Edition, where the list is empty.+ * black: the first system still (the macOS scan already orders Sonoma Horizon first; Windows lists+ * its stock stills when the desktop shell can convert them), else the first gradient — the answer+ * on Linux and the Server Edition, where the list is empty.*/export function defaultWallpaper(stills: readonly { id: string }[]): DesktopWallpaper {return stills[0] ? { kind: 'preset', id: stills[0].id } : { kind: 'preset', id: GRADIENT_WALLPAPERS[0].id }