Quellcode durchsuchen

Keep hotswap when the wallpaper changes

A path change no longer forces a new engine process. That restart dropped transitions and made every playlist advance, schedule rule, and tray next/previous blank the screen. Volume 0 is still sent on the hotswap.

Restore leaves a running split alone, and skips a wallpaper whose folder or project.json is missing, so an unmounted library disk cannot mark it as a launch crash.

The volume slider ends the drag on pointer cancel, lost capture, and blur.
Lennydev vor 3 Wochen
Ursprung
Commit
d425b98cc0

+ 19 - 4
src/main/services/display.service.ts

@@ -1,4 +1,6 @@
 import type { BrowserWindow } from 'electron'
+import fs from 'fs'
+import path from 'path'
 import { IpcChannels } from '@shared/ipc-channels'
 import type {
   CrashEvent,
@@ -310,9 +312,20 @@ export function initDisplay(window: BrowserWindow): void {
   })
 }
 
+/** A missing drive still has a library entry. Launching that path marks a healthy wallpaper as a launch crash. */
+function wallpaperIsOnDisk(localPath: string): boolean {
+  if (!fs.existsSync(localPath)) return false
+  try {
+    return fs.statSync(localPath).isFile() || fs.existsSync(path.join(localPath, 'project.json'))
+  } catch {
+    return false
+  }
+}
+
 /**
  * Puts the last wallpaper back on each screen after a restart. A live engine already showing it is left
- * alone. Screens a playlist just claimed are skipped so the two restores do not launch over each other.
+ * 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.
  */
 export async function restoreAssignedWallpapers(skipScreens: ReadonlySet<ScreenTarget> = new Set()): Promise<void> {
   if (!getLweStatus().installed) return
@@ -321,10 +334,12 @@ export async function restoreAssignedWallpapers(skipScreens: ReadonlySet<ScreenT
   for (const [screen, wallpaperId] of Object.entries(getAssignments())) {
     if (skipScreens.has(screen) || !targets.has(screen)) continue
     const wallpaper = getWallpaper(wallpaperId)
-    if (!wallpaper?.localPath) continue
+    const localPath = wallpaper?.localPath
+    if (!wallpaper || !localPath || !wallpaperIsOnDisk(localPath)) continue
     const inst = running.get(screen)
-    // same wallpaper, still on this screen: nothing to reload
-    if (inst && !inst.split && inst.wallpaperPath === wallpaper.localPath) continue
+    // 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
     try {
       console.log(`[Display] Restoring ${wallpaper.title} on ${screen}`)
       await showWallpaper(wallpaper, screen, { dependencyPrompt: 'once', forceFresh: !inst })

+ 1 - 4
src/main/services/lwe.service.ts

@@ -1775,13 +1775,10 @@ export async function launchLweAsync(wallpaperPath: string, options: LweLaunchOp
   }
 
   const existing = liveInstance(screen)
-  // A different wallpaper has to be a new process. Hotswapping the path leaves the previous
-  // wallpaper's audio playing, and the new one often does not start until a later change (such as moving it).
   const canHotswap =
-    existing?.wallpaperPath === wallpaperPath &&
     !options.forceFresh &&
     !options.customArgs?.trim() &&
-    existing.launchKey === key &&
+    existing?.launchKey === key &&
     (existing.controlFile !== null || liveInstances().length === 1)
 
   if (canHotswap && (await hotswapLweSettings(hotswapOptionsFor(wallpaperPath, options), { screens: [screen] }))) {

+ 13 - 11
src/renderer/src/components/common/DetailSidebar.tsx

@@ -724,6 +724,14 @@ export default function DetailSidebar({
     }
   }
 
+  function endVolumeGesture() {
+    const v = volumeLive.current
+    if (!volumeDragging.current && v === null) return
+    volumeLive.current = null
+    volumeDragging.current = false
+    if (v !== null) void commitVolume(v)
+  }
+
   const [isCommittingXray, setIsCommittingXray] = useState(false)
   const xrayDisabled = libraryMeta?.xrayDisabled ?? false
   const xrayFullReveal = !xrayDisabled && (libraryMeta?.xrayFullReveal ?? false)
@@ -1374,18 +1382,12 @@ export default function DetailSidebar({
                 setVolumeDraft(v)
                 previewLive({ volume: v })
               }}
-              onPointerUp={() => {
-                const v = volumeLive.current
-                volumeLive.current = null
-                volumeDragging.current = false
-                if (v !== null) void commitVolume(v)
-              }}
+              onPointerUp={endVolumeGesture}
+              onPointerCancel={endVolumeGesture}
+              onLostPointerCapture={endVolumeGesture}
+              onBlur={endVolumeGesture}
               onKeyUp={(e) => {
-                if (!isRangeKey(e.key)) return
-                const v = volumeLive.current ?? Number(e.currentTarget.value)
-                volumeLive.current = null
-                volumeDragging.current = false
-                if (Number.isFinite(v)) void commitVolume(v)
+                if (isRangeKey(e.key)) endVolumeGesture()
               }}
               className="w-full touch-none accent-accent-500 disabled:opacity-50"
             />