Der Podcast-Tab der Web-App zeigt jetzt dieselbe Oberfläche wie die Android-App: native-podcast.js aus diora-android, unverändert kopiert nach static/podcasts/ (tools/sync_podcast_ui.py, mit Quell-Commit im Kopf), dazu die Podcast-Teile von native.css. static/js/podcasts-web.js spielt im Browser die Rolle der App (window.DioraPodcastHost statt DioraNative): - Zustand aus /podcasts/state/, in localStorage für einen schnellen Start; Änderungen sofort lokal und der Reihe nach an den Server (Outbox, übersteht Neuladen und Offline), wie Podcasts.kt, inkl. „immer sortiert halten“ - eigener Player (nicht das Radio-Audio-Element), Warteschlange = Playlist, wie RadioService.EpisodeTracker: Stelle fortsetzen, Intro/Outro, Fortschritt alle 10 s und bei Pause, „gehört“ kurz vor Schluss (auch bei „nächste“), automatisch weiter, nach Pause etwas zurück (0,8/3/10/20 s), Tempo und Lautstärke (bis 1) pro Podcast, Sleep-Timer nur während des Abspielens mit Ausblenden - Sperrbildschirm und Medientasten über navigator.mediaSession - Abspiel-Einstellungen dieses Geräts in localStorage (wie PlaybackPrefs) - keine Downloads (die Oberfläche blendet sie aus) - Radio und Podcast nie gleichzeitig: eine Folge stoppt das Radio, ein Sender legt die Folge weg - Bottom-Sheet und Mini-Player-Dock über der Radio-Leiste; auf breiten Bildschirmen eine mittige Spalte (760 px) In der App und der Desktop-App (window.DioraNative vorhanden) tut podcasts-web.js nichts. Entfernt: der alte Podcast-Tab (Markup, ~1000 Zeilen in app.js, CSS), die Podcast-Leiste im Player, INITIAL_PODCAST_FEEDS und das Herunterladen von Folgen in den Browser-Cache (der Service Worker räumt diora-podcast-v1 ab). Service-Worker-Cache auf v52, neue Dateien im App-Shell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.3 KiB
JavaScript
101 lines
3.3 KiB
JavaScript
/**
|
|
* diora service worker — caches the app shell for offline use.
|
|
*/
|
|
|
|
const CACHE = 'diora-v52';
|
|
const SHELL = [
|
|
'/static/css/app.css',
|
|
'/static/js/app.js',
|
|
'/static/js/podcasts-web.js',
|
|
'/static/podcasts/native-podcast.js',
|
|
'/static/podcasts/podcast-ui.css',
|
|
'/static/podcasts/podcasts-web.css',
|
|
'/static/manifest.json',
|
|
'/static/fonts/SourceSerif4-normal-latin.woff2',
|
|
'/static/fonts/SourceSerif4-normal-latin-ext.woff2',
|
|
'/static/fonts/SourceSerif4-italic-latin.woff2',
|
|
'/static/fonts/SourceSerif4-italic-latin-ext.woff2',
|
|
];
|
|
|
|
// Install: pre-cache the app shell
|
|
self.addEventListener('install', function (event) {
|
|
event.waitUntil(
|
|
caches.open(CACHE).then(function (cache) {
|
|
return cache.addAll(SHELL);
|
|
})
|
|
);
|
|
// Activate immediately without waiting for old tabs to close
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// Activate: remove stale caches from previous versions (also the old
|
|
// 'diora-podcast-v1' of episodes the web app used to download)
|
|
self.addEventListener('activate', function (event) {
|
|
event.waitUntil(
|
|
caches.keys().then(function (keys) {
|
|
return Promise.all(
|
|
keys.filter(function (key) { return key !== CACHE; })
|
|
.map(function (key) { return caches.delete(key); })
|
|
);
|
|
}).then(function () {
|
|
return self.clients.claim();
|
|
}).then(function () {
|
|
// Tell all open tabs to reload so they get the latest cached assets
|
|
return self.clients.matchAll({type: 'window'}).then(function (clients) {
|
|
clients.forEach(function (client) {
|
|
client.postMessage({type: 'SW_ACTIVATED'});
|
|
});
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
// Fetch: serve from cache, fall back to network
|
|
self.addEventListener('fetch', function (event) {
|
|
// Only handle GET requests; let POST/SSE etc. pass through
|
|
if (event.request.method !== 'GET') return;
|
|
|
|
const url = new URL(event.request.url);
|
|
|
|
// Bypass for API/mutation endpoints
|
|
if (url.pathname.startsWith('/radio/sse/') ||
|
|
url.pathname.startsWith('/radio/record/') ||
|
|
url.pathname.startsWith('/radio/affiliate/') ||
|
|
url.pathname.startsWith('/tts/') ||
|
|
url.pathname.startsWith('/admin/') ||
|
|
url.pathname.startsWith('/podcasts/progress/') ||
|
|
url.pathname.startsWith('/podcasts/queue/') ||
|
|
url.pathname === '/podcasts/feeds/add' ||
|
|
url.pathname.startsWith('/podcasts/feeds/add') ||
|
|
url.pathname.includes('/remove') ||
|
|
url.pathname.startsWith('/podcasts/feeds/refresh')) {
|
|
return;
|
|
}
|
|
|
|
// Cache-first for pre-defined shell assets
|
|
const isShell = SHELL.some(function (s) { return url.pathname === s; });
|
|
if (isShell) {
|
|
event.respondWith(
|
|
caches.match(event.request).then(function (cached) {
|
|
return cached || fetch(event.request);
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Navigation requests (the HTML page itself): network-first, fall back to
|
|
// last cached version so the app opens offline after being visited once.
|
|
if (event.request.mode === 'navigate') {
|
|
event.respondWith(
|
|
fetch(event.request).then(function (response) {
|
|
if (response.ok) {
|
|
var clone = response.clone();
|
|
caches.open(CACHE).then(function (cache) { cache.put(event.request, clone); });
|
|
}
|
|
return response;
|
|
}).catch(function () {
|
|
return caches.match(event.request);
|
|
})
|
|
);
|
|
}
|
|
});
|