QualityBadge: hardware rate detection + custom tooltip
Poll get_hardware_audio_status every 2s to get the actual hardware sample rate from /proc/asound. Compare decoded rate (kHz) vs hardware rate (Hz) for real downgrade detection instead of relying on originalSamplingRate which comes from the same decoder. Replace native title attribute with custom tooltip (matching AudioOutputBadges style) for the degraded state, showing source rate, output rate, resampling warning, and settings fix hint.
This commit is contained in:
1 parent
659a5b7718
commit
6794f00259
1 file changed
+139
-12
@@ -1,5 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/i18n';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
interface HardwareAudioStatus {
|
||||
hardware_sample_rate: number | null;
|
||||
hardware_format: string | null;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
quality?: string;
|
||||
@@ -21,19 +28,53 @@
|
||||
compact = false
|
||||
}: Props = $props();
|
||||
|
||||
// Check if quality was downgraded due to settings
|
||||
const isDowngraded = $derived.by(() => {
|
||||
// Need both original and current values to compare
|
||||
if (!originalSamplingRate || !samplingRate) return false;
|
||||
// Significant difference (more than 10% lower)
|
||||
return samplingRate < originalSamplingRate * 0.9;
|
||||
// Hardware sample rate from /proc/asound (sub-ms read)
|
||||
let hardwareSampleRate = $state<number | null>(null);
|
||||
let isHovering = $state(false);
|
||||
|
||||
// Poll hardware audio status when we have a sampling rate to compare against
|
||||
$effect(() => {
|
||||
if (!samplingRate) return;
|
||||
|
||||
async function poll() {
|
||||
try {
|
||||
const status = await invoke<HardwareAudioStatus>('get_hardware_audio_status').catch(() => null);
|
||||
if (status?.is_active && status.hardware_sample_rate) {
|
||||
hardwareSampleRate = status.hardware_sample_rate;
|
||||
} else {
|
||||
hardwareSampleRate = null;
|
||||
}
|
||||
} catch {
|
||||
hardwareSampleRate = null;
|
||||
}
|
||||
}
|
||||
|
||||
poll();
|
||||
const interval = setInterval(poll, 2000);
|
||||
return () => clearInterval(interval);
|
||||
});
|
||||
|
||||
// Format original quality for tooltip
|
||||
const originalQualityText = $derived.by(() => {
|
||||
if (!isDowngraded || !originalSamplingRate) return '';
|
||||
const depth = originalBitDepth || 24;
|
||||
return `${depth}-bit / ${originalSamplingRate} kHz`;
|
||||
// Downgrade detection: compare decoded rate (kHz) vs hardware rate (Hz)
|
||||
const isDowngraded = $derived.by(() => {
|
||||
if (hardwareSampleRate && samplingRate) {
|
||||
// samplingRate is in kHz (e.g. 192), hardwareSampleRate is in Hz (e.g. 48000)
|
||||
const decodedHz = samplingRate * 1000;
|
||||
// Significant difference: hardware is more than 10% lower than decoded
|
||||
return hardwareSampleRate < decodedHz * 0.9;
|
||||
}
|
||||
// Fallback: compare original vs current (old logic, for when hardware unavailable)
|
||||
if (originalSamplingRate && samplingRate) {
|
||||
return samplingRate < originalSamplingRate * 0.9;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Effective output rate for tooltip display (in kHz)
|
||||
const effectiveOutputRateKHz = $derived.by(() => {
|
||||
if (hardwareSampleRate) {
|
||||
return hardwareSampleRate / 1000;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// Determine quality tier
|
||||
@@ -140,7 +181,9 @@
|
||||
<div
|
||||
class="quality-badge"
|
||||
class:downgraded={isDowngraded}
|
||||
title={isDowngraded ? $t('quality.degradedTooltip', { values: { original: originalQualityText, current: displayText } }) : `${tierLabel}: ${displayText}`}
|
||||
title={isDowngraded ? undefined : `${tierLabel}: ${displayText}`}
|
||||
onmouseenter={() => { isHovering = true; }}
|
||||
onmouseleave={() => { isHovering = false; }}
|
||||
>
|
||||
<!-- Icon container with fixed width -->
|
||||
<div class="icon-container">
|
||||
@@ -160,6 +203,23 @@
|
||||
</span>
|
||||
<span class="quality-info">{displayText}</span>
|
||||
</div>
|
||||
|
||||
<!-- Custom tooltip for degraded state -->
|
||||
{#if isDowngraded && isHovering}
|
||||
<div class="quality-tooltip">
|
||||
<div class="tooltip-section">
|
||||
<div class="tooltip-label">{$t('quality.tooltip.source')}</div>
|
||||
<div class="tooltip-value">{displayText}</div>
|
||||
</div>
|
||||
<div class="tooltip-section">
|
||||
<div class="tooltip-label">{$t('quality.tooltip.output')}</div>
|
||||
<div class="tooltip-value">{effectiveOutputRateKHz ? `${effectiveOutputRateKHz} kHz` : displayText}</div>
|
||||
</div>
|
||||
<div class="tooltip-divider"></div>
|
||||
<div class="tooltip-warning">{$t('quality.tooltip.resampled')}</div>
|
||||
<div class="tooltip-fix">{$t('quality.tooltip.fix')}</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -176,6 +236,7 @@
|
||||
|
||||
/* Full mode styles */
|
||||
.quality-badge {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
@@ -250,4 +311,70 @@
|
||||
.downgrade-indicator.visible {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
/* Custom tooltip for degraded quality */
|
||||
.quality-tooltip {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 8px);
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--alpha-10);
|
||||
border-radius: 6px;
|
||||
padding: 8px 12px;
|
||||
min-width: 180px;
|
||||
max-width: 240px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
|
||||
z-index: 9999;
|
||||
animation: tooltip-appear 150ms ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@keyframes tooltip-appear {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(4px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.tooltip-section {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.tooltip-label {
|
||||
font-size: 9px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: var(--alpha-40);
|
||||
margin-bottom: 1px;
|
||||
}
|
||||
|
||||
.tooltip-value {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tooltip-divider {
|
||||
height: 1px;
|
||||
background: var(--alpha-10);
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.tooltip-warning {
|
||||
font-size: 11px;
|
||||
color: #eab308;
|
||||
font-weight: 500;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.tooltip-fix {
|
||||
font-size: 10px;
|
||||
color: var(--alpha-50);
|
||||
line-height: 1.3;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user