Add PipeWire device names via pactl and fix badge margins
This commit is contained in:
1 parent
78e3af691f
commit
b6b019e659
5 files changed
+208
-18
No files matched your search
@@ -15,6 +15,13 @@
|
||||
is_playing: boolean;
|
||||
}
|
||||
|
||||
interface PipewireSink {
|
||||
name: string;
|
||||
description: string;
|
||||
volume: number | null;
|
||||
is_default: boolean;
|
||||
}
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
showTooltips?: boolean;
|
||||
@@ -25,11 +32,31 @@
|
||||
// State
|
||||
let settings = $state<AudioSettings | null>(null);
|
||||
let outputStatus = $state<AudioOutputStatus | null>(null);
|
||||
let pipewireSinks = $state<PipewireSink[]>([]);
|
||||
let isHovering = $state(false);
|
||||
|
||||
// Derived state
|
||||
const currentDevice = $derived(outputStatus?.device_name ?? null);
|
||||
const prettyDeviceName = $derived(currentDevice ? getDevicePrettyName(currentDevice) : 'No device');
|
||||
|
||||
// Get PipeWire description for current device
|
||||
const pipewireDescription = $derived.by(() => {
|
||||
if (!currentDevice) return null;
|
||||
const sink = pipewireSinks.find(s => s.name === currentDevice);
|
||||
return sink?.description ?? null;
|
||||
});
|
||||
|
||||
// Get volume for current device from PipeWire
|
||||
const currentVolume = $derived.by(() => {
|
||||
if (!currentDevice) return null;
|
||||
const sink = pipewireSinks.find(s => s.name === currentDevice);
|
||||
return sink?.volume ?? null;
|
||||
});
|
||||
|
||||
// Use PipeWire description if available, otherwise fall back to heuristic
|
||||
const prettyDeviceName = $derived(
|
||||
pipewireDescription ?? (currentDevice ? getDevicePrettyName(currentDevice) : 'No device')
|
||||
);
|
||||
|
||||
const isExternal = $derived(currentDevice ? isExternalDevice(currentDevice) : false);
|
||||
|
||||
// Badge states - based on settings AND actual device capability
|
||||
@@ -47,12 +74,14 @@
|
||||
|
||||
async function loadStatus() {
|
||||
try {
|
||||
const [settingsResult, statusResult] = await Promise.all([
|
||||
const [settingsResult, statusResult, sinksResult] = await Promise.all([
|
||||
invoke<AudioSettings>('get_audio_settings'),
|
||||
invoke<AudioOutputStatus>('get_audio_output_status')
|
||||
invoke<AudioOutputStatus>('get_audio_output_status'),
|
||||
invoke<PipewireSink[]>('get_pipewire_sinks').catch(() => [] as PipewireSink[])
|
||||
]);
|
||||
settings = settingsResult;
|
||||
outputStatus = statusResult;
|
||||
pipewireSinks = sinksResult;
|
||||
} catch (err) {
|
||||
console.error('Failed to load audio status:', err);
|
||||
}
|
||||
@@ -98,6 +127,12 @@
|
||||
{#if currentDevice && currentDevice !== prettyDeviceName}
|
||||
<div class="tooltip-raw">{currentDevice}</div>
|
||||
{/if}
|
||||
{#if currentVolume !== null}
|
||||
<div class="tooltip-volume">
|
||||
<span class="volume-label">Volume:</span>
|
||||
<span class="volume-value">{currentVolume}%</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -190,4 +225,24 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.tooltip-volume {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.volume-label {
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.volume-value {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
</style>
|
||||
@@ -519,7 +519,7 @@
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 12px;
|
||||
padding: 2px 12px 2px 2px;
|
||||
padding: 2px;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border-radius: 8px;
|
||||
min-width: 580px;
|
||||
@@ -532,7 +532,7 @@
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 2px 0 2px 2px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
line-height: 0;
|
||||
@@ -644,7 +644,7 @@
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
align-self: stretch;
|
||||
margin: 2px 2px 2px 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.audio-badges-row {
|
||||
|
||||
@@ -36,6 +36,13 @@
|
||||
is_default: boolean;
|
||||
}
|
||||
|
||||
interface PipewireSink {
|
||||
name: string;
|
||||
description: string;
|
||||
volume: number | null;
|
||||
is_default: boolean;
|
||||
}
|
||||
|
||||
let { onBack, onLogout, userName = 'User', userEmail = '', subscription = 'Qobuz' }: Props = $props();
|
||||
|
||||
// Cache state (memory cache)
|
||||
@@ -52,20 +59,39 @@
|
||||
|
||||
// Audio device state
|
||||
let audioDevices = $state<AudioDevice[]>([]);
|
||||
let pipewireSinks = $state<PipewireSink[]>([]);
|
||||
|
||||
// Map of ALSA name -> PipeWire description (for pretty names)
|
||||
const pipewireNameMap = $derived.by(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const sink of pipewireSinks) {
|
||||
map.set(sink.name, sink.description);
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
// Get pretty name: prefer PipeWire description, fall back to heuristic
|
||||
function getPrettyName(alsaName: string): string {
|
||||
// Try PipeWire description first
|
||||
const pwDesc = pipewireNameMap.get(alsaName);
|
||||
if (pwDesc) return pwDesc;
|
||||
// Fall back to heuristic
|
||||
return getDevicePrettyName(alsaName);
|
||||
}
|
||||
|
||||
// Map of pretty name -> raw name
|
||||
const deviceNameMap = $derived.by(() => {
|
||||
const map = new Map<string, string>();
|
||||
map.set('System Default', 'System Default');
|
||||
for (const d of audioDevices) {
|
||||
const pretty = getDevicePrettyName(d.name);
|
||||
const pretty = getPrettyName(d.name);
|
||||
map.set(pretty, d.name);
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
// Options for dropdown (pretty names)
|
||||
let audioDeviceOptions = $derived(['System Default', ...audioDevices.map(d => getDevicePrettyName(d.name))]);
|
||||
// Options for dropdown (pretty names from PipeWire when available)
|
||||
let audioDeviceOptions = $derived(['System Default', ...audioDevices.map(d => getPrettyName(d.name))]);
|
||||
|
||||
// Theme mapping: display name -> data-theme value
|
||||
const themeMap: Record<string, string> = {
|
||||
@@ -141,9 +167,8 @@
|
||||
// Load download cache stats
|
||||
loadDownloadStats();
|
||||
|
||||
// Load audio devices and settings
|
||||
loadAudioDevices();
|
||||
loadAudioSettings();
|
||||
// Load audio devices first (includes PipeWire sinks), then settings
|
||||
loadAudioDevices().then(() => loadAudioSettings());
|
||||
|
||||
// Load Last.fm state
|
||||
loadLastfmState();
|
||||
@@ -299,13 +324,21 @@
|
||||
|
||||
async function loadAudioDevices() {
|
||||
try {
|
||||
const devices = await invoke<AudioDevice[]>('get_audio_devices');
|
||||
// Load both ALSA devices and PipeWire sinks in parallel
|
||||
const [devices, sinks] = await Promise.all([
|
||||
invoke<AudioDevice[]>('get_audio_devices'),
|
||||
invoke<PipewireSink[]>('get_pipewire_sinks').catch(() => [] as PipewireSink[])
|
||||
]);
|
||||
|
||||
audioDevices = devices;
|
||||
pipewireSinks = sinks;
|
||||
|
||||
// Debug: log raw names and their pretty versions
|
||||
console.log('[Audio] Devices loaded:', devices.map(d => ({
|
||||
console.log('[Audio] ALSA devices:', devices.map(d => d.name));
|
||||
console.log('[Audio] PipeWire sinks:', sinks.map(s => ({ name: s.name, desc: s.description })));
|
||||
console.log('[Audio] Final device options:', devices.map(d => ({
|
||||
raw: d.name,
|
||||
pretty: getDevicePrettyName(d.name),
|
||||
isDefault: d.is_default
|
||||
pretty: getPrettyName(d.name)
|
||||
})));
|
||||
} catch (err) {
|
||||
console.error('Failed to load audio devices:', err);
|
||||
@@ -315,9 +348,9 @@
|
||||
async function loadAudioSettings() {
|
||||
try {
|
||||
const settings = await invoke<AudioSettings>('get_audio_settings');
|
||||
// Convert raw name to pretty name for display
|
||||
// Convert raw name to pretty name for display (uses PipeWire when available)
|
||||
if (settings.output_device) {
|
||||
outputDevice = getDevicePrettyName(settings.output_device);
|
||||
outputDevice = getPrettyName(settings.output_device);
|
||||
} else {
|
||||
outputDevice = 'System Default';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user