Преглед на файлове

Restore after the tray is up, and ask with the in-app screen list

Restore runs after the tray, autostart and schedule, and it is not awaited. Screens a playlist resumed, a playlist that was not resumed, an autostart playlist, or a schedule catch-up is about to use are skipped. A split that is not running comes back through showSplitScreen when the assignment is its first slot. Static images are left alone, and the unused forceFresh on that launch is gone.

Card Play asks with the in-app screen list. All screens is the default, so Enter still applies to every screen. The shared slider helper is in place for the detail panel.
Lennydev преди 3 седмици
родител
ревизия
b87eaf97b1

+ 12 - 4
src/main/index.ts

@@ -11,10 +11,10 @@ import { initDesktopIcons, cleanupDesktopIcons } from './services/desktop-icons.
 import { getTrayEnabled, getAutostartEnabled, getAutostartMinimized, getAutostartPlaylistId, getKillLweOnQuit, getConfiguredBackupPath } from './services/config.service'
 import { refreshAutostartExec } from './services/autostart.service'
 import { createTray } from './services/tray.service'
-import { activePlaylistScreens, initPlaylistPlayer, startPlaylist } from './services/playlist-player.service'
+import { initPlaylistPlayer, playlistRestoreSkipScreens, startPlaylist } from './services/playlist-player.service'
 import { checkEarlierRunEngines, killAllLweProcesses, getLweStatus } from './services/lwe.service'
-import { initDisplay, restoreAssignedWallpapers } from './services/display.service'
-import { initSchedule } from './services/schedule.service'
+import { expandScreen, initDisplay, restoreAssignedWallpapers } from './services/display.service'
+import { catchUpScreens, initSchedule } from './services/schedule.service'
 import { initUpdates } from './services/update.service'
 import { detectDesktopEnv, hasStatusNotifierHost } from './utils/platform'
 import { needsSoftwareCompositing, readGpuVendors } from './utils/gpuWorkaround'
@@ -244,22 +244,30 @@ app.whenReady().then(async () => {
   await checkEarlierRunEngines()
   initDisplay(win)
   const resumed = initPlaylistPlayer(win)
-  await restoreAssignedWallpapers(new Set(activePlaylistScreens()))
 
   if (getTrayEnabled()) createTray(win)
 
   if (getAutostartEnabled()) refreshAutostartExec(getAutostartMinimized())
 
   const autostartPlaylistId = getAutostartPlaylistId()
+  let autostartScreens: string[] = []
   if (!resumed && autostartPlaylistId && getLweStatus().installed) {
     try {
       startPlaylist(autostartPlaylistId)
+      autostartScreens = expandScreen(undefined)
     } catch (err) {
       console.error('[App] Failed to autostart playlist:', err)
     }
   }
+  const scheduleScreens = catchUpScreens().flatMap((screen) => expandScreen(screen))
   initSchedule(win)
   initUpdates(win)
+
+  // not awaited: a restore is at least 2s per screen, and its dependency dialog must not hold the tray.
+  // '*' is every current screen, same as a schedule rule for all of them
+  const playlistScreens = playlistRestoreSkipScreens().flatMap((screen) => expandScreen(screen))
+  const skip = new Set([...playlistScreens, ...autostartScreens, ...scheduleScreens])
+  void restoreAssignedWallpapers(skip).catch((err: unknown) => { console.error('[Display] Restore failed:', err) })
 }).catch((err: unknown) => { console.error('[Main] startup failed:', err) })
 
 app.on('before-quit', (event) => {

+ 8 - 0
src/main/ipc/config.handlers.ts

@@ -42,6 +42,8 @@ import {
   setKillLweOnQuit,
   getSkipPlaylistResume,
   setSkipPlaylistResume,
+  getFreshProcessOnPathChange,
+  setFreshProcessOnPathChange,
   getCardBorders,
   getCardBadges,
   getAppearance,
@@ -126,6 +128,7 @@ export function registerConfigHandlers(): void {
     autostartPlaylistId: getAutostartPlaylistId(),
     killLweOnQuit: getKillLweOnQuit(),
     skipPlaylistResume: getSkipPlaylistResume(),
+    freshProcessOnPathChange: getFreshProcessOnPathChange(),
     cardBorders: getCardBorders(),
     cardBadges: getCardBadges(),
     audioScreen: getAudioScreen(),
@@ -184,6 +187,11 @@ export function registerConfigHandlers(): void {
     return { ok: true }
   })
 
+  ipcMain.handle(IpcChannels.CONFIG_SET_FRESH_PROCESS_ON_PATH_CHANGE, (_e, enabled: boolean) => {
+    setFreshProcessOnPathChange(enabled)
+    return { ok: true }
+  })
+
   ipcMain.handle(IpcChannels.CONFIG_SET_CARD_BORDERS, (_e, borders: CardBorders) => {
     return setCardBorders(borders)
   })

+ 3 - 34
src/main/ipc/wallpaper.handlers.ts

@@ -14,30 +14,10 @@ import {
   testFreshLaunch
 } from '../services/display.service'
 import type { ApplyWallpaperOptions, ScreenTarget, SplitScreen } from '@shared/types'
-import { getDisplayMode, setSplitScreen } from '../services/config.service'
-import { ALL_SCREENS } from '../services/lwe.service'
+import { setSplitScreen } from '../services/config.service'
 import { deleteThumbnail, generateThumbnail, IMAGE_EXTENSIONS, useThumbnailFile } from '../services/thumbnail.service'
 import { t } from '../i18n'
 
-/** null means the user cancelled. undefined means every screen. */
-async function askWhichScreen(targets: ScreenTarget[]): Promise<ScreenTarget | undefined | null> {
-  const buttons = [...targets, t('common.allScreens'), t('common.cancel')]
-  const cancelId = buttons.length - 1
-  const parent = BrowserWindow.getFocusedWindow() ?? BrowserWindow.getAllWindows()[0]
-  const box = {
-    type: 'question' as const,
-    title: t('playlist.whichScreen'),
-    message: t('playlist.whichScreen'),
-    buttons,
-    defaultId: 0,
-    cancelId
-  }
-  const { response } = parent ? await dialog.showMessageBox(parent, box) : await dialog.showMessageBox(box)
-  if (response === cancelId || response < 0) return null
-  if (response < targets.length) return targets[response]
-  return undefined
-}
-
 export function registerWallpaperHandlers(): void {
   ipcMain.handle(IpcChannels.WALLPAPER_DETECT_ENV, () => {
     return detectEnvironment()
@@ -56,21 +36,10 @@ export function registerWallpaperHandlers(): void {
     const wallpaper = getWallpaper(options.wallpaperId)
     if (!wallpaper) throw new Error(`Wallpaper ${options.wallpaperId} not found in library`)
 
-    // the detail panel already picked a screen. Play from a card has not, and per-screen mode asks.
-    let screen = options.screen
-    if ((screen === undefined || screen === null) && getDisplayMode() === 'per-screen') {
-      const targets = expandScreen(undefined).filter((name) => name !== ALL_SCREENS)
-      if (targets.length > 1) {
-        const chosen = await askWhichScreen(targets)
-        if (chosen === null) return { ok: false, appliedPath: '' }
-        screen = chosen
-      }
-    }
-
     // a playlist would replace it again on its next switch
-    for (const target of expandScreen(screen)) pausePlaylist(target)
+    for (const target of expandScreen(options.screen)) pausePlaylist(target)
 
-    const appliedPath = await showWallpaper(wallpaper, screen, { backend: options.backend })
+    const appliedPath = await showWallpaper(wallpaper, options.screen, { backend: options.backend })
 
     updateWallpaper(options.wallpaperId, {
       appliedCount: (wallpaper.appliedCount ?? 0) + 1,

+ 12 - 0
src/main/services/config.service.ts

@@ -38,6 +38,8 @@ interface AppConfig {
   autostartPlaylistId: string | null
   killLweOnQuit: boolean
   skipPlaylistResume: boolean
+  /** A path change starts a new engine instead of hotswapping. Off keeps transitions. */
+  freshProcessOnPathChange: boolean
   /** Legacy, only read to migrate into cardBorders */
   voteBorders: boolean
   cardBorders: CardBorders | null
@@ -91,6 +93,7 @@ const store = openStore<AppConfig>({
     autostartPlaylistId: null,
     killLweOnQuit: false,
     skipPlaylistResume: false,
+    freshProcessOnPathChange: false,
     voteBorders: true,
     cardBorders: null,
     cardBadges: null,
@@ -199,6 +202,14 @@ export function getSkipPlaylistResume(): boolean {
   return store.get('skipPlaylistResume')
 }
 
+export function getFreshProcessOnPathChange(): boolean {
+  return store.get('freshProcessOnPathChange')
+}
+
+export function setFreshProcessOnPathChange(enabled: boolean): void {
+  store.set('freshProcessOnPathChange', enabled)
+}
+
 export function setSkipPlaylistResume(enabled: boolean): void {
   store.set('skipPlaylistResume', enabled)
 }
@@ -391,6 +402,7 @@ const RESETS_WITH_ENGINE_SETTINGS: Record<keyof AppConfig, boolean> = {
   autostartPlaylistId: false,
   killLweOnQuit: false,
   skipPlaylistResume: false,
+  freshProcessOnPathChange: false,
   voteBorders: false,
   cardBorders: false,
   cardBadges: false,

+ 37 - 13
src/main/services/display.service.ts

@@ -31,6 +31,7 @@ import {
 import { resolveEngineFlags } from '@shared/engineFlags'
 import { clearAssignment, getAssignments, setAssignment } from './wallpaper-state.service'
 import { getDefaultFps, getDisplayMode, getGlobalEngineFlags, getSplitScreens } from './config.service'
+import { planRestore } from './restore-plan'
 import { ensureDependencyInstalled } from './dependency.service'
 import { t } from '../i18n'
 
@@ -152,7 +153,7 @@ export async function showSplitScreen(screen: ScreenTarget, beforeLaunch?: () =>
   const shown: WallpaperMeta[] = []
   for (const slot of split?.slots ?? []) {
     const wallpaper = getWallpaper(slot.wallpaperId)
-    if (!wallpaper?.localPath || !isAnimatedWallpaper(wallpaper)) continue
+    if (!wallpaper?.localPath || !isAnimatedWallpaper(wallpaper) || !wallpaperIsOnDisk(wallpaper.localPath)) continue
     await ensureDependencyInstalled(wallpaper)
     slots.push({
       path: wallpaper.localPath,
@@ -322,29 +323,52 @@ function wallpaperIsOnDisk(localPath: string): boolean {
   }
 }
 
+/** The slot showSplitScreen would store as the assignment, when that folder is actually there */
+function splitSlotId(screen: ScreenTarget): string | null {
+  const split = getSplitScreens()[screen]
+  if (!split) return null
+  for (const slot of split.slots) {
+    const wallpaper = getWallpaper(slot.wallpaperId)
+    if (!wallpaper?.localPath || !isAnimatedWallpaper(wallpaper) || !wallpaperIsOnDisk(wallpaper.localPath)) continue
+    return wallpaper.id
+  }
+  return null
+}
+
 /**
- * Puts the last wallpaper back on each screen after a restart. A live engine already showing it is left
- * alone, including a split, whose assignment is only the first slot. Screens a playlist just claimed are
- * skipped so the two restores do not launch over each other.
+ * Puts the last animated wallpaper back on each screen after a restart. A live engine already showing
+ * it is left alone. A split comes back through showSplitScreen. Screens a playlist or schedule just
+ * claimed are skipped so the two launches do not run over each other.
  */
 export async function restoreAssignedWallpapers(skipScreens: ReadonlySet<ScreenTarget> = new Set()): Promise<void> {
   if (!getLweStatus().installed) return
   const targets = new Set(getDisplayTargets())
   const running = new Map(getRunningInstances().map((inst) => [inst.screen, inst]))
   for (const [screen, wallpaperId] of Object.entries(getAssignments())) {
-    if (skipScreens.has(screen) || !targets.has(screen)) continue
     const wallpaper = getWallpaper(wallpaperId)
-    const localPath = wallpaper?.localPath
-    if (!wallpaper || !localPath || !wallpaperIsOnDisk(localPath)) continue
+    const localPath = wallpaper?.localPath ?? ''
     const inst = running.get(screen)
-    // the saved id is slot 1, so relaunching it would replace the split with one wallpaper
-    if (inst?.split) continue
-    if (inst && inst.wallpaperPath === localPath) continue
+    const plan = planRestore({
+      skipped: skipScreens.has(screen),
+      connected: targets.has(screen),
+      animated: !!wallpaper && isAnimatedWallpaper(wallpaper),
+      onDisk: !!localPath && wallpaperIsOnDisk(localPath),
+      localPath,
+      running: inst ? { split: !!inst.split, wallpaperPath: inst.wallpaperPath } : undefined,
+      splitSlotId: splitSlotId(screen),
+      wallpaperId
+    })
+    if (plan === 'skip' || !wallpaper) continue
     try {
-      console.log(`[Display] Restoring ${wallpaper.title} on ${screen}`)
-      await showWallpaper(wallpaper, screen, { dependencyPrompt: 'once', forceFresh: !inst })
+      if (plan === 'split') {
+        console.log(`[Display] Restoring split on ${screen}`)
+        await showSplitScreen(screen)
+      } else {
+        console.log(`[Display] Restoring ${wallpaper.title} on ${screen}`)
+        await showWallpaper(wallpaper, screen, { dependencyPrompt: 'once' })
+      }
     } catch (err) {
-      console.error(`[Display] Could not restore ${wallpaper.title} on ${screen}:`, (err as Error).message)
+      console.error(`[Display] Could not restore ${wallpaper?.title ?? wallpaperId} on ${screen}:`, (err as Error).message)
     }
   }
 }

+ 6 - 0
src/main/services/playlist-player.service.ts

@@ -387,6 +387,12 @@ export function activePlaylistScreens(): ScreenTarget[] {
   return [...players.values()].filter((player) => player.state.playlistId).map((player) => player.state.screen)
 }
 
+/** With "Don't resume playlists", the saved screens are skipped too, or restore puts the last item back without its volume */
+export function playlistRestoreSkipScreens(): ScreenTarget[] {
+  if (getSkipPlaylistResume()) return Object.keys(savedPlayers())
+  return activePlaylistScreens()
+}
+
 /** Resumes the playlists active at the last close, true if any (the autostart playlist is then skipped) */
 
 export function initPlaylistPlayer(window: BrowserWindow): boolean {

+ 65 - 0
src/main/services/restore-plan.test.ts

@@ -0,0 +1,65 @@
+import { describe, expect, it } from 'vitest'
+import { mergeSkipScreens, planRestore, playlistSkipScreens, type RestoreInput } from './restore-plan'
+
+function input(patch: Partial<RestoreInput> = {}): RestoreInput {
+  return {
+    skipped: false,
+    connected: true,
+    animated: true,
+    onDisk: true,
+    localPath: '/w/a',
+    splitSlotId: null,
+    wallpaperId: 'a',
+    ...patch
+  }
+}
+
+describe('planRestore', () => {
+  it('leaves a running engine that already shows the wallpaper', () => {
+    expect(planRestore(input({ running: { split: false, wallpaperPath: '/w/a' } }))).toBe('skip')
+  })
+
+  it('hotswaps when a different wallpaper is running', () => {
+    expect(planRestore(input({ running: { split: false, wallpaperPath: '/w/old' } }))).toBe('wallpaper')
+  })
+
+  it('leaves a running split alone', () => {
+    expect(planRestore(input({ running: { split: true, wallpaperPath: '/w/a' }, splitSlotId: 'a' }))).toBe('skip')
+  })
+
+  it('restores a split that is not running through the split, not as one wallpaper', () => {
+    expect(planRestore(input({ splitSlotId: 'a', wallpaperId: 'a' }))).toBe('split')
+  })
+
+  it('restores the assigned wallpaper when it is not the split first slot', () => {
+    expect(planRestore(input({ splitSlotId: 'slot', wallpaperId: 'a' }))).toBe('wallpaper')
+  })
+
+  it('skips a screen a playlist or schedule already claimed', () => {
+    expect(planRestore(input({ skipped: true }))).toBe('skip')
+  })
+
+  it('skips a wallpaper whose folder is missing', () => {
+    expect(planRestore(input({ onDisk: false }))).toBe('skip')
+  })
+
+  it('skips a static image, which has no engine and would cover every screen', () => {
+    expect(planRestore(input({ animated: false }))).toBe('skip')
+  })
+})
+
+describe('playlistSkipScreens', () => {
+  it('skips the saved playlist screens when playlists are not resumed', () => {
+    expect(playlistSkipScreens(true, ['HDMI-A-2'], [])).toEqual(['HDMI-A-2'])
+  })
+
+  it('skips only the screens that actually resumed', () => {
+    expect(playlistSkipScreens(false, ['HDMI-A-2'], ['HDMI-A-3'])).toEqual(['HDMI-A-3'])
+  })
+})
+
+describe('mergeSkipScreens', () => {
+  it('keeps playlist, autostart and schedule screens together', () => {
+    expect([...mergeSkipScreens(['HDMI-A-2'], ['*'], ['HDMI-A-3'])]).toEqual(['HDMI-A-2', '*', 'HDMI-A-3'])
+  })
+})

+ 32 - 0
src/main/services/restore-plan.ts

@@ -0,0 +1,32 @@
+export interface RestoreInput {
+  skipped: boolean
+  connected: boolean
+  animated: boolean
+  onDisk: boolean
+  localPath: string
+  running?: { split: boolean; wallpaperPath: string }
+  /** First on-disk slot a split would show, or null when this screen has no showable split */
+  splitSlotId: string | null
+  wallpaperId: string
+}
+
+export type RestorePlan = 'skip' | 'split' | 'wallpaper'
+
+/** What startup should do with one saved screen. A static image and a missing folder are skipped. */
+export function planRestore(input: RestoreInput): RestorePlan {
+  if (input.skipped || !input.connected) return 'skip'
+  if (input.running?.split) return 'skip'
+  if (input.splitSlotId !== null && input.splitSlotId === input.wallpaperId) return 'split'
+  if (!input.animated || !input.onDisk) return 'skip'
+  if (input.running && input.running.wallpaperPath === input.localPath) return 'skip'
+  return 'wallpaper'
+}
+
+/** Don't-resume skips the saved playlist screens. Otherwise only screens that actually resumed. */
+export function playlistSkipScreens(skipResume: boolean, saved: readonly string[], active: readonly string[]): string[] {
+  return skipResume ? [...saved] : [...active]
+}
+
+export function mergeSkipScreens(...groups: readonly (readonly string[])[]): Set<string> {
+  return new Set(groups.flat())
+}

+ 9 - 1
src/main/services/schedule.service.ts

@@ -2,7 +2,7 @@ import { openStore } from '../utils/safeStore'
 import { nativeTheme, type BrowserWindow } from 'electron'
 import { randomUUID } from 'crypto'
 import { IpcChannels } from '@shared/ipc-channels'
-import type { ScheduleRule } from '@shared/types'
+import type { ScheduleRule, ScreenTarget } from '@shared/types'
 import { dueTimeRules } from '@shared/schedule'
 import { getWallpaper, updateWallpaper } from './library.service'
 import { getPlaylist } from './playlist.service'
@@ -100,6 +100,14 @@ function onThemeChanged(): void {
   void runAll(store.get('rules').filter((r) => r.enabled && r.trigger.type === 'theme' && r.trigger.theme === theme))
 }
 
+/** Screens whose catch-up rule is about to launch, so restore does not launch there as well */
+export function catchUpScreens(now = Date.now()): ScreenTarget[] {
+  const last = store.get('lastTick')
+  if (last === null || last >= now) return []
+  const from = new Date(Math.max(last, now - MAX_CATCH_UP_MS))
+  return dueTimeRules(store.get('rules'), from, new Date(now)).map((rule) => rule.screen)
+}
+
 /** Call after the playlist player resumed, so a rule that came due while closed wins over it */
 export function initSchedule(window: BrowserWindow): void {
   win = window

+ 2 - 0
src/preload/index.ts

@@ -185,6 +185,8 @@ const api = {
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_KILL_LWE_ON_QUIT, enabled),
     setSkipPlaylistResume: (enabled: boolean): Promise<{ ok: boolean }> =>
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_SKIP_PLAYLIST_RESUME, enabled),
+    setFreshProcessOnPathChange: (enabled: boolean): Promise<{ ok: boolean }> =>
+      ipcRenderer.invoke(IpcChannels.CONFIG_SET_FRESH_PROCESS_ON_PATH_CHANGE, enabled),
     setCardBorders: (borders: CardBorders): Promise<CardBorders> =>
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_CARD_BORDERS, borders),
     setCardBadges: (badges: CardBadges): Promise<CardBadges> =>

+ 2 - 0
src/renderer/src/App.tsx

@@ -12,6 +12,7 @@ import GnomeExtensionNotice from './components/layout/GnomeExtensionNotice'
 import UpdateNotice from './components/updates/UpdateNotice'
 import GraphicsNotice from './components/layout/GraphicsNotice'
 import UpdatePrompt from './components/updates/UpdatePrompt'
+import PlayScreenPrompt from './components/common/PlayScreenPrompt'
 import { useToast } from './components/common/Toast'
 import { screenLabel } from './utils/screens'
 import { UPDATE_STATUS_KEY, useConfig } from './hooks/queries'
@@ -188,6 +189,7 @@ export default function App() {
         </div>
         <StatusBar />
         <UpdatePrompt />
+        <PlayScreenPrompt />
       </div>
     </ErrorBoundary>
   )

+ 66 - 0
src/renderer/src/components/common/PlayScreenPrompt.tsx

@@ -0,0 +1,66 @@
+import { useEffect, useState } from 'react'
+import type { ScreenTarget } from '@shared/types'
+import { CARD_PLAY_DEFAULT_SCREEN } from '@shared/playScreen'
+import { t } from '../../i18n'
+import ScreenSelect from './ScreenSelect'
+
+type Pending = {
+  targets: ScreenTarget[]
+  resolve: (screen: ScreenTarget | null) => void
+}
+
+let openPrompt: ((targets: ScreenTarget[]) => Promise<ScreenTarget | null>) | null = null
+
+/** null means cancel. The default is every screen, which is what card Play used to do. */
+export function askPlayScreen(targets: ScreenTarget[]): Promise<ScreenTarget | null> {
+  if (!openPrompt) return Promise.resolve(CARD_PLAY_DEFAULT_SCREEN)
+  return openPrompt(targets)
+}
+
+export default function PlayScreenPrompt() {
+  const [pending, setPending] = useState<Pending | null>(null)
+  const [value, setValue] = useState<ScreenTarget>(CARD_PLAY_DEFAULT_SCREEN)
+
+  useEffect(() => {
+    openPrompt = (targets) => new Promise((resolve) => {
+      setValue(CARD_PLAY_DEFAULT_SCREEN)
+      setPending({ targets, resolve })
+    })
+    return () => { openPrompt = null }
+  }, [])
+
+  if (!pending) return null
+
+  function finish(screen: ScreenTarget | null) {
+    pending?.resolve(screen)
+    setPending(null)
+  }
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-8">
+      <div className="w-full max-w-sm rounded-xl border border-fg/10 bg-popup p-4 shadow-2xl">
+        <h3 className="text-sm font-semibold text-gray-100">{t('playlist.whichScreen')}</h3>
+        <div className="mt-3">
+          <ScreenSelect targets={pending.targets} value={value} onChange={setValue} title={t('playlist.whichScreen')} />
+        </div>
+        <div className="mt-4 flex justify-end gap-2">
+          <button
+            type="button"
+            onClick={() => { finish(null) }}
+            className="rounded-lg px-3 py-1.5 text-sm text-gray-300 hover:bg-fg/5"
+          >
+            {t('common.cancel')}
+          </button>
+          <button
+            type="button"
+            autoFocus
+            onClick={() => { finish(value) }}
+            className="rounded-lg bg-accent-600 px-3 py-1.5 text-sm text-white hover:bg-accent-500"
+          >
+            {t('play.wallpaper')}
+          </button>
+        </div>
+      </div>
+    </div>
+  )
+}

+ 59 - 0
src/renderer/src/components/common/RangeInput.tsx

@@ -0,0 +1,59 @@
+import type { ChangeEvent, KeyboardEvent, PointerEvent } from 'react'
+import { useRef } from 'react'
+import { isRangeKey } from '../../utils/dom'
+import { createRangeCommit } from '../../utils/rangeCommit'
+
+interface Props {
+  min: number
+  max: number
+  step?: number
+  value: number
+  disabled?: boolean
+  title?: string
+  className?: string
+  onLive?: (value: number) => void
+  onCommit: (value: number) => void
+}
+
+/** One commit path for every detail-panel slider. The value comes from the drag, not a later read of the input. */
+export default function RangeInput({ min, max, step, value, disabled, title, className, onLive, onCommit }: Props) {
+  const machine = useRef(createRangeCommit())
+
+  function end() {
+    const next = machine.current.end()
+    if (next !== null) onCommit(next)
+  }
+
+  function pointerDown(e: PointerEvent<HTMLInputElement>) {
+    machine.current.pointerDown()
+    try {
+      e.currentTarget.setPointerCapture(e.pointerId)
+    } catch {
+      // the pointer can already be gone; the drag flag still tracks moves over the input
+    }
+  }
+
+  return (
+    <input
+      type="range"
+      min={min}
+      max={max}
+      step={step}
+      value={value}
+      disabled={disabled}
+      title={title}
+      className={`w-full touch-none accent-accent-500 disabled:opacity-50 ${className ?? ''}`}
+      onPointerDown={pointerDown}
+      onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => { machine.current.keyDown(e.key) }}
+      onChange={(e: ChangeEvent<HTMLInputElement>) => {
+        const next = machine.current.change(e.target.value)
+        if (next !== null) onLive?.(next)
+      }}
+      onPointerUp={end}
+      onPointerCancel={end}
+      onLostPointerCapture={end}
+      onBlur={end}
+      onKeyUp={(e: KeyboardEvent<HTMLInputElement>) => { if (isRangeKey(e.key)) end() }}
+    />
+  )
+}

+ 15 - 1
src/renderer/src/hooks/useWallpaperActions.ts

@@ -1,6 +1,8 @@
 import { useQueryClient } from '@tanstack/react-query'
 import type { ScreenTarget } from '@shared/types'
+import { cardPlayNeedsScreenChoice } from '@shared/playScreen'
 import { useToast } from '../components/common/Toast'
+import { askPlayScreen } from '../components/common/PlayScreenPrompt'
 import { forEachIgnoringErrors } from '../utils/async'
 import { t } from '../i18n'
 
@@ -10,7 +12,19 @@ export function useApplyWallpaper(): (id: string, screen?: ScreenTarget) => Prom
 
   return async (id, screen) => {
     try {
-      await window.electronAPI.wallpaper.apply({ wallpaperId: id, screen })
+      let chosen = screen
+      if (chosen === undefined) {
+        const [cfg, targets] = await Promise.all([
+          window.electronAPI.config.get(),
+          window.electronAPI.wallpaper.getTargets()
+        ])
+        if (cardPlayNeedsScreenChoice(cfg.displayMode, targets)) {
+          const picked = await askPlayScreen(targets.filter((name) => name !== '*'))
+          if (picked === null) return
+          chosen = picked
+        }
+      }
+      await window.electronAPI.wallpaper.apply({ wallpaperId: id, screen: chosen })
       void queryClient.invalidateQueries({ queryKey: ['library'] })
     } catch (err) {
       showToast((err as Error).message)

+ 35 - 0
src/renderer/src/utils/rangeCommit.test.ts

@@ -0,0 +1,35 @@
+import { describe, expect, it } from 'vitest'
+import { createRangeCommit } from './rangeCommit'
+
+describe('range commit', () => {
+  it('ignores a max-value change that arrives with no drag', () => {
+    const range = createRangeCommit()
+    expect(range.change('128')).toBeNull()
+    expect(range.end()).toBeNull()
+  })
+
+  it('commits the dragged value, including 0, and then ignores a later max event', () => {
+    const range = createRangeCommit()
+    range.pointerDown()
+    expect(range.change('0')).toBe(0)
+    expect(range.end()).toBe(0)
+    expect(range.change('128')).toBeNull()
+    expect(range.end()).toBeNull()
+  })
+
+  it('ends the drag on cancel, so a stray event afterwards is ignored', () => {
+    const range = createRangeCommit()
+    range.pointerDown()
+    range.change('40')
+    expect(range.end()).toBe(40)
+    range.change('128')
+    expect(range.end()).toBeNull()
+  })
+
+  it('tracks keyboard changes and commits on keyup', () => {
+    const range = createRangeCommit()
+    range.keyDown('ArrowRight')
+    expect(range.change('15')).toBe(15)
+    expect(range.end()).toBe(15)
+  })
+})

+ 30 - 0
src/renderer/src/utils/rangeCommit.ts

@@ -0,0 +1,30 @@
+import { isRangeKey } from './dom'
+
+/** Remembers a range drag so a change event that arrives on its own cannot commit the max. */
+export function createRangeCommit() {
+  let dragging = false
+  let live: number | null = null
+
+  return {
+    pointerDown() {
+      dragging = true
+    },
+    keyDown(key: string) {
+      if (isRangeKey(key)) dragging = true
+    },
+    change(raw: string): number | null {
+      if (!dragging) return null
+      const value = Number(raw)
+      if (!Number.isFinite(value)) return null
+      live = value
+      return value
+    },
+    end(): number | null {
+      const value = live
+      const active = dragging || value !== null
+      live = null
+      dragging = false
+      return active && value !== null ? value : null
+    }
+  }
+}

+ 1 - 0
src/shared/ipc-channels.ts

@@ -124,6 +124,7 @@ export const IpcChannels = {
   CONFIG_SET_TRAY_ENABLED: 'config:set-tray-enabled',
   CONFIG_SET_KILL_LWE_ON_QUIT: 'config:set-kill-lwe-on-quit',
   CONFIG_SET_SKIP_PLAYLIST_RESUME: 'config:set-skip-playlist-resume',
+  CONFIG_SET_FRESH_PROCESS_ON_PATH_CHANGE: 'config:set-fresh-process-on-path-change',
   CONFIG_SET_CARD_BORDERS: 'config:set-card-borders',
   CONFIG_SET_CARD_BADGES: 'config:set-card-badges',
   CONFIG_SET_APPEARANCE: 'config:set-appearance',

+ 18 - 0
src/shared/playScreen.test.ts

@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest'
+import { CARD_PLAY_DEFAULT_SCREEN, cardPlayNeedsScreenChoice } from './playScreen'
+
+describe('card play screen question', () => {
+  it('asks in per-screen mode when two monitors are connected', () => {
+    expect(cardPlayNeedsScreenChoice('per-screen', ['HDMI-A-3', 'HDMI-A-2'])).toBe(true)
+  })
+
+  it('does not ask for one monitor, shared mode, or when a screen was already chosen by the caller', () => {
+    expect(cardPlayNeedsScreenChoice('per-screen', ['HDMI-A-3'])).toBe(false)
+    expect(cardPlayNeedsScreenChoice('shared', ['HDMI-A-3', 'HDMI-A-2'])).toBe(false)
+    expect(cardPlayNeedsScreenChoice('per-screen', ['*'])).toBe(false)
+  })
+
+  it('defaults to every screen, which is what Enter used to do', () => {
+    expect(CARD_PLAY_DEFAULT_SCREEN).toBe('*')
+  })
+})

+ 8 - 0
src/shared/playScreen.ts

@@ -0,0 +1,8 @@
+import type { DisplayMode } from './types'
+
+/** Card Play asks only in per-screen mode with two or more real monitors. All screens is the default. */
+export function cardPlayNeedsScreenChoice(mode: DisplayMode, targets: readonly string[]): boolean {
+  return mode === 'per-screen' && targets.filter((name) => name !== '*').length > 1
+}
+
+export const CARD_PLAY_DEFAULT_SCREEN = '*'

+ 1 - 0
src/shared/types.ts

@@ -680,6 +680,7 @@ export interface AppConfigSnapshot {
   autostartPlaylistId: string | null
   killLweOnQuit: boolean
   skipPlaylistResume: boolean
+  freshProcessOnPathChange: boolean
   cardBorders: CardBorders
   cardBadges: CardBadges
   audioScreen: string | null