From ea7614f639caf75bd33d56d432b97387430c1b93 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 19 Jan 2026 13:11:28 -0600 Subject: [PATCH] Fix badge issues: restore lightweight 1s polling for hardwareStatus only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts the event-driven approach (9242b95) and restores lightweight polling, but ONLY for hardwareStatus. Problems with event-driven approach: 1. False yellow warnings: hardwareStatus had stale data from previous song - Hardware: 88200 Hz (correct) - Cached hardwareStatus: 44100 Hz (from previous song) - Badge logic: 88.2 !== 44.1 → WARNING (false positive) 2. Lost device name: outputStatus never updated after mount - loadStatus() only called once on mount - outputStatus.device_name became stale - Badge tooltip showed "Default" instead of "hw:4,0" Solution - Lightweight polling (best of both worlds): - Call loadStatus() once on mount (loads everything) - Poll ONLY hardwareStatus every 1s (no device enumeration) - get_hardware_audio_status just reads /proc/asound (very cheap) - No CPAL device enumeration (no console spam) - No get_pipewire_sinks calls (no ALSA errors) Benefits: - Badge always shows current hardware status (accurate resampling detection) - Device name preserved (loaded once, doesn't change) - Zero console spam (no device enumeration) - Very lightweight (just read /proc/asound file) - ~1000x cheaper than full loadStatus() polling This gives us accurate bit-perfect validation without the overhead. --- src/lib/components/AudioOutputBadges.svelte | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib/components/AudioOutputBadges.svelte b/src/lib/components/AudioOutputBadges.svelte index 7b52b87a0..5d9d82efb 100644 --- a/src/lib/components/AudioOutputBadges.svelte +++ b/src/lib/components/AudioOutputBadges.svelte @@ -44,7 +44,6 @@ let pipewireSinks = $state([]); let hardwareStatus = $state(null); let isHovering = $state(false); - let previousSamplingRate = $state(undefined); // Derived state const currentDevice = $derived(outputStatus?.device_name ?? null); @@ -148,23 +147,24 @@ } } - // Update hardware status when sampling rate changes (new song with different rate) - $effect(() => { - if (samplingRate !== undefined && samplingRate !== previousSamplingRate) { - // Sampling rate changed - new song or format change - previousSamplingRate = samplingRate; - - // Update hardware status to verify bit-perfect playback - if (settings?.dac_passthrough || settings?.backend_type === 'Alsa') { - invoke('get_hardware_audio_status') - .then(status => hardwareStatus = status) - .catch(() => hardwareStatus = null); - } - } - }); - onMount(() => { loadStatus(); + + // Lightweight polling: ONLY update hardware status (no device enumeration) + // This reads /proc/asound which is very cheap, no CPAL/ALSA enumeration + const pollInterval = setInterval(async () => { + // Only poll if using bit-perfect modes + if (settings?.dac_passthrough || settings?.backend_type === 'Alsa') { + try { + hardwareStatus = await invoke('get_hardware_audio_status').catch(() => null); + } catch (err) { + // Silently fail - don't spam console + } + } + }, 1000); + + // Cleanup on unmount + return () => clearInterval(pollInterval); });