From a045ab4fbe5ba6132981f3358d8a062f9fdac2a1 Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 24 Nov 2026 03:40:41 +0200 Subject: [PATCH] Fix offline playback ownership and polish the artist list and desktop sidebar --- CHANGELOG.md | 12 ++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/i18n/phrases.rs | 3 +- src/player/offline-catalog.js | 57 ++++-- src/player/offline-worker.js | 4 + templates/player/account_actions.html | 20 +- templates/player/artist_popular_tracks.html | 4 +- templates/player/offline_scripts.html | 58 ++++-- templates/player/offline_styles.css | 14 +- templates/player/scripts.html | 206 ++++++++++++-------- templates/player/search_group_scripts.html | 30 ++- templates/player/shell.html | 9 +- templates/player/sidebar_styles.html | 17 ++ templates/player/wordmark_font.css | 106 ++++++++++ tests/browser-offline-catalog.cjs | 17 +- tests/browser-offline-player.cjs | 69 ++++++- tests/browser-offline-worker.cjs | 7 + tests/browser-search-groups.cjs | 38 ++++ tests/browser-sidebar.cjs | 15 +- tests/federation_navigation.test.cjs | 49 ++++- tests/offline_devices.test.cjs | 125 ++++++++++++ 22 files changed, 724 insertions(+), 140 deletions(-) create mode 100644 templates/player/wordmark_font.css create mode 100644 tests/offline_devices.test.cjs diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e5314..170a458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,18 @@ - Desktop/mobile lyrics view following playback, individual track previews, availability icons, and local version editing in the admin track editor. +## v0.16.2 — 2026-11-24 + +- Saved tracks and their likes load when the browser loses its connection. + Federation streams close while offline and reconnect when the server returns. +- Only the device already playing a saved track automatically continues offline. + Remote controller tabs stay paused. The account menu explains offline mode, + and a soft yellow label beside search shows when it is active. +- Collapsing popular tracks on an artist page returns the list to the position + where it was expanded. +- The desktop sidebar now has a `#furumi` wordmark with an embedded monospace + font and a subtle click animation that respects reduced motion. + ## v0.16.1 — 2026-11-24 - Artist pages show five distinct popular titles at first. Matching titles are diff --git a/Cargo.lock b/Cargo.lock index e12d157..f739431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2062,7 +2062,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "furumusic" -version = "0.16.1" +version = "0.16.2" dependencies = [ "anyhow", "async-stream", diff --git a/Cargo.toml b/Cargo.toml index 4ba49c4..b35d75d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "furumusic" -version = "0.16.1" +version = "0.16.2" edition = "2024" description = "Reusable web-app boilerplate: auth, OIDC/SSO, admin panel, user management, i18n, PostgreSQL" diff --git a/src/i18n/phrases.rs b/src/i18n/phrases.rs index 5af1206..f2a367e 100644 --- a/src/i18n/phrases.rs +++ b/src/i18n/phrases.rs @@ -295,7 +295,8 @@ translations! { player_offline_auto: "Offline · automatic" , "Офлайн · автоматически"; player_offline_manage: "Manage" , "Управление"; player_offline_manage_label: "Manage offline music" , "Управление офлайн-музыкой"; - player_offline_cache_only: "Use saved music only" , "Только сохранённая музыка"; + player_offline_mode: "Offline mode" , "Офлайн-режим"; + player_offline_mode_hint: "Uses only the local cache. No network requests." , "Плеер работает только с локальным кешем, без сетевых запросов."; player_offline_enable: "Save music on this device" , "Сохранять музыку на устройстве"; player_offline_preparing: "Preparing offline listening…" , "Готовим плеер для офлайн-прослушивания…"; player_offline_hint: "Played tracks are saved automatically. You can also save a track from its menu." , "Прослушанные треки сохраняются автоматически. Трек также можно сохранить через его меню."; diff --git a/src/player/offline-catalog.js b/src/player/offline-catalog.js index 949c5d9..4352ed8 100644 --- a/src/player/offline-catalog.js +++ b/src/player/offline-catalog.js @@ -230,6 +230,7 @@ if (!url.pathname.startsWith(BASE)) return; if (route === 'me' && Number(value.id) === this.account) data = value; else if (['likes','follows','pins','state'].includes(route)) data = value; + else if (route === 'tracks/content/like' && Array.isArray(value)) data = value; else if (route === 'playlists' && Array.isArray(value)) data = value.map(summarizePlaylist); else if (/^playlists\/-?\d+$/.test(route) && Array.isArray(value.tracks)) { data = {...summarizePlaylist(value), members:value.tracks.map(t => ({id:t.id, content_id:t.content_id, @@ -556,24 +557,46 @@ this._catalog = {tracks, artists, artistCards, releases, releaseCards:[...releases.values()].map(card)}; return this._catalog; } + async likedTracks(tracks, members = []) { + const [local, federated] = await Promise.all([ + this.read('meta','likes'), this.read('meta','tracks/content/like'), + ]); + const byId = new Map(tracks.map(t => [t.id,t])); + const trackIds = new Set(local?.track_ids || []); + const contentIds = new Set(federated || []); + const ordered = new Map(); + for (const member of members) { + const track = byId.get(member.id); + if (track && (!local || trackIds.has(track.id) || contentIds.has(track.content_id))) ordered.set(track.id, track); + if (member.content_id && (!local || trackIds.has(member.id))) contentIds.add(member.content_id); + } + for (const id of trackIds) { + const track = byId.get(id); + if (track) { + ordered.set(track.id, track); + if (track.content_id) contentIds.add(track.content_id); + } + } + // A saved federated recording has a browser-only numeric ID. Its like follows the content. + for (const track of tracks) { + if (contentIds.has(track.content_id)) ordered.set(track.id, track); + } + return [...ordered.values()]; + } async playlist(id, tracks) { - const byId = new Map(tracks.map(t => [t.id,t])), byContent = new Map(tracks.map(t => [contentKey(t),t])); const saved = await this.read('meta','playlists/'+id); if (!saved && id !== -1) return null; let items; if (id === -1) { - const likes = await this.read('meta','likes'); - const ids = likes?.track_ids; - const allowed = new Set(ids || []); const seen = new Set(); - const ordered = [...(saved?.members || []).map(m => m.id), ...(ids || [])]; - items = []; - for (const id of ordered) { - const t = byId.get(id); - if (!t || (ids && !allowed.has(id)) || seen.has(contentKey(t))) continue; - seen.add(contentKey(t)); items.push(t); - } + items = (await this.likedTracks(tracks, saved?.members)).filter(track => { + const key = contentKey(track); + if (seen.has(key)) return false; + seen.add(key); + return true; + }); } else { + const byId = new Map(tracks.map(t => [t.id,t])), byContent = new Map(tracks.map(t => [contentKey(t),t])); items = saved.members.flatMap(m => { const track = byId.get(m.id) || byContent.get(m.content_id); return track ? [{...track, playlist_track_id:m.playlist_track_id ?? null, sort_key:m.sort_key}] : []; @@ -621,16 +644,16 @@ return json(id && await this.read('lyrics',id) || {versions:[]}); } if (/^playlists\/-?\d+\/federation-tracks$/.test(path)) return json([]); - if (['me','likes','pins','follows','state','tracks/content/like'].includes(path)) { + if (path === 'likes' || path === 'tracks/content/like') { + const rows = await this.likedTracks((await this.catalog()).tracks); + return path === 'likes' ? json({track_ids:rows.map(t => t.id)}) : + json([...new Set(rows.map(t => t.content_id).filter(Boolean))]); + } + if (['me','pins','follows','state'].includes(path)) { const data = await this.read('meta', path); if (path === 'me') return data ? json(data) : json({id:this.account,name:'',role:'user',stats:{}}); if (path === 'state') return json(data || {queue:[],current_track_id:null,position_ms:0,volume:0.7}); - if (path === 'tracks/content/like') return json({content_ids:[]}); const catalog = await this.catalog(); - if (path === 'likes') { - const ids = new Set(catalog.tracks.map(t => t.id)); - return json({track_ids:(data?.track_ids || []).filter(id => ids.has(id))}); - } if (path === 'follows') { const artists = (data?.artist_ids || []).map(id => catalog.artistCards.get(id)).filter(Boolean); return json({artist_ids:artists.map(a => a.id),artists}); diff --git a/src/player/offline-worker.js b/src/player/offline-worker.js index d88a439..09888bd 100644 --- a/src/player/offline-worker.js +++ b/src/player/offline-worker.js @@ -184,6 +184,10 @@ async function local(request, state, rootNavigation) { } if (ASSETS.includes(url.pathname)) return await cache.match(url.pathname) || unavailable(); if (request.mode === 'navigate') return unavailable(); + if (request.method === 'GET' && ['/api/player/federation/artists/events', '/api/player/federation/search/events'].includes(url.pathname)) { + // A stream opened just before disconnection must stop without reconnecting. + return new Response(null, {status:204, headers:{'Cache-Control':'no-store'}}); + } const read = ['GET','HEAD'].includes(request.method) || (request.method === 'POST' && url.pathname === '/api/player/tracks-by-ids'); if (read && url.pathname.startsWith('/api/')) { diff --git a/templates/player/account_actions.html b/templates/player/account_actions.html index 8d10ace..54945a2 100644 --- a/templates/player/account_actions.html +++ b/templates/player/account_actions.html @@ -11,10 +11,22 @@ - +
+ + + {{ t.player_offline_mode_hint }} + +
{% endif %}
diff --git a/templates/player/artist_popular_tracks.html b/templates/player/artist_popular_tracks.html index 5ca7f36..2375f12 100644 --- a/templates/player/artist_popular_tracks.html +++ b/templates/player/artist_popular_tracks.html @@ -12,7 +12,7 @@ -