Parcourir la source

Start a fresh engine only when that setting is on

Hotswap stays the default, and volume 0 is still sent. The setting skips the hotswap when the wallpaper path changes. The same path, a forced fresh launch and a missing engine behave as before.
Lennydev il y a 3 semaines
Parent
commit
6203bdd058
2 fichiers modifiés avec 56 ajouts et 6 suppressions
  1. 30 0
      src/main/services/lwe.service.test.ts
  2. 26 6
      src/main/services/lwe.service.ts

+ 30 - 0
src/main/services/lwe.service.test.ts

@@ -19,6 +19,7 @@ vi.mock('./config.service', () => ({
   getDefaultAudioSensitivity: () => 1,
   getDisablePuppetAnimation: () => false,
   getScriptLimits: () => false,
+  getFreshProcessOnPathChange: () => false,
   getLoader: () => loaderSettings
 }))
 
@@ -27,6 +28,7 @@ const {
   buildLweEnvVars,
   buildHotswapLines,
   buildLweArgs,
+  canHotswapExisting,
   hotswapOptionsFor,
   lwePackageOwner,
   nodeDevelPackage,
@@ -197,6 +199,34 @@ describe('buildHotswapLines', () => {
   })
 })
 
+describe('canHotswapExisting', () => {
+  const existing = { wallpaperPath: '/w/a', launchKey: 'k', controlFile: '/run/c' }
+
+  it('hotswaps a different wallpaper by default', () => {
+    expect(canHotswapExisting(existing, {}, 'k', '/w/b', 1, false)).toBe(true)
+  })
+
+  it('starts a new process for a different path when that setting is on', () => {
+    expect(canHotswapExisting(existing, {}, 'k', '/w/b', 1, true)).toBe(false)
+  })
+
+  it('keeps the same wallpaper on a hotswap even with the setting on', () => {
+    expect(canHotswapExisting(existing, {}, 'k', '/w/a', 1, true)).toBe(true)
+  })
+
+  it('does not hotswap a forced fresh launch, a different key, or a missing engine', () => {
+    expect(canHotswapExisting(existing, { forceFresh: true }, 'k', '/w/a', 1, false)).toBe(false)
+    expect(canHotswapExisting(existing, {}, 'other', '/w/a', 1, false)).toBe(false)
+    expect(canHotswapExisting(undefined, {}, 'k', '/w/a', 0, false)).toBe(false)
+  })
+
+  it('hotswaps a missing control file only when that engine is the only one', () => {
+    const bare = { wallpaperPath: '/w/a', launchKey: 'k', controlFile: null }
+    expect(canHotswapExisting(bare, {}, 'k', '/w/b', 1, false)).toBe(true)
+    expect(canHotswapExisting(bare, {}, 'k', '/w/b', 2, false)).toBe(false)
+  })
+})
+
 describe('buildCleanBuildEnv', () => {
   it('drops AppImage mount entries from path lists and the AppImage variables', () => {
     const saved = { ...process.env }

+ 26 - 6
src/main/services/lwe.service.ts

@@ -63,7 +63,8 @@ import {
   getDefaultAudioSensitivity,
   getDisablePuppetAnimation,
   getScriptLimits,
-  getDisabledScreens
+  getDisabledScreens,
+  getFreshProcessOnPathChange
 } from './config.service'
 import { DEFAULT_LWE_FPS, DEFAULT_LWE_REPO } from '@shared/constants'
 import { engineFlagArgs, filterSupportedArgs } from '@shared/engineFlags'
@@ -1764,6 +1765,22 @@ export function hotswapOptionsFor(wallpaperPath: string, options: LweLaunchOptio
   }
 }
 
+/** Same-path changes hotswap. A different path hotswaps too, unless the setting starts a new process. */
+export function canHotswapExisting(
+  existing: { wallpaperPath: string; launchKey: string; controlFile: string | null } | undefined,
+  options: { forceFresh?: boolean; customArgs?: string },
+  key: string,
+  wallpaperPath: string,
+  liveCount: number,
+  freshProcessOnPathChange: boolean
+): boolean {
+  if (options.forceFresh || !!options.customArgs?.trim()) return false
+  if (!existing || existing.launchKey !== key) return false
+  if (existing.controlFile === null && liveCount !== 1) return false
+  if (freshProcessOnPathChange && existing.wallpaperPath !== wallpaperPath) return false
+  return true
+}
+
 /** Hotswaps the engine on the screen when possible, else restarts it. Resolves once it survived 2s */
 export async function launchLweAsync(wallpaperPath: string, options: LweLaunchOptions = {}): Promise<void> {
   const screen = options.screen ?? ALL_SCREENS
@@ -1775,11 +1792,14 @@ export async function launchLweAsync(wallpaperPath: string, options: LweLaunchOp
   }
 
   const existing = liveInstance(screen)
-  const canHotswap =
-    !options.forceFresh &&
-    !options.customArgs?.trim() &&
-    existing?.launchKey === key &&
-    (existing.controlFile !== null || liveInstances().length === 1)
+  const canHotswap = canHotswapExisting(
+    existing,
+    options,
+    key,
+    wallpaperPath,
+    liveInstances().length,
+    getFreshProcessOnPathChange()
+  )
 
   if (canHotswap && (await hotswapLweSettings(hotswapOptionsFor(wallpaperPath, options), { screens: [screen] }))) {
     return