feat(offline): implement Last.fm scrobble queue for offline mode

Research findings:
- Last.fm API supports batch scrobbling (up to 50 tracks)
- Timestamps can be backdated up to 14 days

Implementation:
- Add scrobble_queue table to offline database
- Add queue_scrobble, get_queued_scrobbles, mark_scrobbles_sent commands
- Queue scrobbles when offline instead of skipping
- Flush queue automatically when transitioning to online
- Skip scrobbles older than 14 days (Last.fm limit)
- Cleanup sent scrobbles after 7 days
This commit is contained in:
vicrodh committed 2026-01-15 23:24:24 -06:00
1 parent b4af6f6e9f
commit e7f06fcd2f
5 files changed
+400 -27

No files matched your search

+12 -2
View File
@@ -9,8 +9,8 @@ import { invoke } from '@tauri-apps/api/core';
import { getCurrentWebview } from '@tauri-apps/api/webview';
import { goBack, goForward } from '$lib/stores/navigationStore';
import { loadToastsPreference } from '$lib/stores/toastStore';
import { loadSystemNotificationsPreference } from '$lib/services/playbackService';
import { initOfflineStore, cleanupOfflineStore } from '$lib/stores/offlineStore';
import { loadSystemNotificationsPreference, flushScrobbleQueue } from '$lib/services/playbackService';
import { initOfflineStore, cleanupOfflineStore, onOnlineTransition } from '$lib/stores/offlineStore';
// ============ Theme Management ============
@@ -122,6 +122,16 @@ export function bootstrapApp(): BootstrapResult {
// Initialize offline store (async, fire-and-forget)
initOfflineStore();
// Register callback to flush scrobble queue when transitioning to online
onOnlineTransition(() => {
console.log('[Bootstrap] Online transition detected - flushing scrobble queue');
flushScrobbleQueue().then(({ sent, failed }) => {
if (sent > 0 || failed > 0) {
console.log(`[Bootstrap] Scrobble queue flush complete: ${sent} sent, ${failed} failed`);
}
});
});
return {
cleanup: () => {
cleanupMouse();