Fix badge issues: restore lightweight 1s polling for hardwareStatus only
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.
This commit is contained in:
1 parent
9242b95939
commit
ea7614f639
1 file changed
+16
-16
@@ -44,7 +44,6 @@
|
||||
let pipewireSinks = $state<PipewireSink[]>([]);
|
||||
let hardwareStatus = $state<HardwareAudioStatus | null>(null);
|
||||
let isHovering = $state(false);
|
||||
let previousSamplingRate = $state<number | undefined>(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<HardwareAudioStatus>('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<HardwareAudioStatus>('get_hardware_audio_status').catch(() => null);
|
||||
} catch (err) {
|
||||
// Silently fail - don't spam console
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Cleanup on unmount
|
||||
return () => clearInterval(pollInterval);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user