feat(settings): add lyrics cache clear button
- Add Lyrics section to Settings with cache clear button - Add explicit debug logging for lyrics fetch/parse - Add track change detection logging to watcher
This commit is contained in:
1 parent
baf8a57516
commit
182479f6c2
2 files changed
+60
No files matched your search
@@ -13,6 +13,7 @@
|
||||
setDownloadCacheLimit,
|
||||
type DownloadCacheStats
|
||||
} from '$lib/stores/downloadState';
|
||||
import { clearCache as clearLyricsCache } from '$lib/stores/lyricsStore';
|
||||
|
||||
interface Props {
|
||||
onBack?: () => void;
|
||||
@@ -45,6 +46,9 @@
|
||||
let isClearingDownloads = $state(false);
|
||||
let downloadCacheLimit = $state('2 GB'); // Default 2GB
|
||||
|
||||
// Lyrics cache state
|
||||
let isClearingLyrics = $state(false);
|
||||
|
||||
// Audio device state
|
||||
let audioDevices = $state<AudioDevice[]>([]);
|
||||
let audioDeviceOptions = $derived(['System Default', ...audioDevices.map(d => d.name)]);
|
||||
@@ -369,6 +373,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClearLyricsCache() {
|
||||
if (isClearingLyrics) return;
|
||||
isClearingLyrics = true;
|
||||
try {
|
||||
await clearLyricsCache();
|
||||
console.log('Lyrics cache cleared');
|
||||
} catch (err) {
|
||||
console.error('Failed to clear lyrics cache:', err);
|
||||
} finally {
|
||||
isClearingLyrics = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -678,6 +695,25 @@
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Lyrics Section -->
|
||||
<section class="section">
|
||||
<h3 class="section-title">Lyrics</h3>
|
||||
<div class="setting-row">
|
||||
<span class="setting-label">Provider</span>
|
||||
<span class="setting-value">LRCLIB / lyrics.ovh</span>
|
||||
</div>
|
||||
<div class="setting-row last">
|
||||
<span class="setting-label">Clear Lyrics Cache</span>
|
||||
<button
|
||||
class="clear-btn"
|
||||
onclick={handleClearLyricsCache}
|
||||
disabled={isClearingLyrics}
|
||||
>
|
||||
{isClearingLyrics ? 'Clearing...' : 'Clear'}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -224,6 +224,7 @@ function calculateLineProgress(lines: LyricsLine[], index: number, currentTimeMs
|
||||
/**
|
||||
* Update active line based on current playback time
|
||||
*/
|
||||
let lastLogTime = 0;
|
||||
export function updateActiveLine(): void {
|
||||
if (!parsedLyrics.isSynced || parsedLyrics.lines.length === 0) {
|
||||
if (activeIndex !== -1 || activeProgress !== 0) {
|
||||
@@ -238,6 +239,18 @@ export function updateActiveLine(): void {
|
||||
const newIndex = findActiveLineIndex(parsedLyrics.lines, currentTimeMs);
|
||||
const newProgress = calculateLineProgress(parsedLyrics.lines, newIndex, currentTimeMs);
|
||||
|
||||
// Debug log every 2 seconds
|
||||
const now = Date.now();
|
||||
if (now - lastLogTime > 2000) {
|
||||
lastLogTime = now;
|
||||
console.log('[Lyrics] Update:', {
|
||||
currentTimeMs,
|
||||
newIndex,
|
||||
newProgress: newProgress.toFixed(2),
|
||||
activeLine: parsedLyrics.lines[newIndex]?.text?.substring(0, 30)
|
||||
});
|
||||
}
|
||||
|
||||
if (newIndex !== activeIndex || Math.abs(newProgress - activeProgress) > 0.01) {
|
||||
activeIndex = newIndex;
|
||||
activeProgress = newProgress;
|
||||
@@ -269,6 +282,7 @@ export async function fetchLyrics(): Promise<void> {
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
console.log(`[Lyrics] Fetching for: "${track.title}" by "${track.artist}"`);
|
||||
const result = await invoke<LyricsPayload | null>('lyrics_get', {
|
||||
trackId: track.id,
|
||||
title: track.title,
|
||||
@@ -277,9 +291,16 @@ export async function fetchLyrics(): Promise<void> {
|
||||
durationSecs: track.duration || null
|
||||
});
|
||||
|
||||
// Explicit logging - no objects to expand
|
||||
console.log(`[Lyrics] Backend: hasResult=${!!result}, hasSyncedLrc=${!!result?.synced_lrc}, syncedLen=${result?.synced_lrc?.length ?? 0}, hasPlain=${!!result?.plain}, provider=${result?.provider}`);
|
||||
if (result?.synced_lrc) {
|
||||
console.log(`[Lyrics] Synced LRC preview: ${result.synced_lrc.substring(0, 150)}`);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
payload = result;
|
||||
parsedLyrics = parsePayload(result);
|
||||
console.log(`[Lyrics] Parsed: linesCount=${parsedLyrics.lines.length}, isSynced=${parsedLyrics.isSynced}, firstTimeMs=${parsedLyrics.lines[0]?.timeMs ?? 'N/A'}, firstText="${parsedLyrics.lines[0]?.text?.substring(0, 30) ?? 'N/A'}"`);
|
||||
status = 'loaded';
|
||||
activeIndex = -1;
|
||||
activeProgress = 0;
|
||||
@@ -368,6 +389,7 @@ let updateInterval: number | null = null;
|
||||
export function startActiveLineUpdates(): void {
|
||||
if (updateInterval !== null) return;
|
||||
|
||||
console.log('[Lyrics] Starting active line updates, isSynced:', parsedLyrics.isSynced);
|
||||
updateInterval = window.setInterval(() => {
|
||||
if (parsedLyrics.isSynced) {
|
||||
updateActiveLine();
|
||||
@@ -397,12 +419,14 @@ let lastTrackId: number | null = null;
|
||||
export function startWatching(): void {
|
||||
if (playerUnsubscribe) return;
|
||||
|
||||
console.log('[Lyrics] Starting track watcher');
|
||||
playerUnsubscribe = subscribePlayer(() => {
|
||||
const track = getCurrentTrack();
|
||||
const trackId = track?.id ?? null;
|
||||
|
||||
// Track changed - always prefetch lyrics for new track
|
||||
if (trackId !== lastTrackId) {
|
||||
console.log('[Lyrics] Track changed:', { from: lastTrackId, to: trackId, title: track?.title });
|
||||
lastTrackId = trackId;
|
||||
if (trackId !== null) {
|
||||
// Always prefetch lyrics when a new track starts
|
||||
|
||||
Reference in new issue
Block a user