From 5723a5d2a0ea9dcab84fb78fd3ad1a372b09a0d3 Mon Sep 17 00:00:00 2001 From: nessi Date: Sun, 16 Aug 2026 17:29:21 +0200 Subject: [PATCH] feat: add service worker route with cache-control headers and update PWA manifest icons for proper maskable support Add /sw.js route with send_from_directory to serve service worker from root scope with Service-Worker-Allowed:/ and Cache-Control:no-cache headers. Add navigator.serviceWorker.register() script to index.html with load event listener and scope:/ parameter. Update service worker cache to v4 with media-mark-192.svg/media-mark-512.svg additions to SHELL array. Update manifest.json icons --- app.py | 11 ++++++++++- static/manifest.json | 5 +++-- static/media-mark-192.svg | 2 +- static/sw.js | 4 ++-- templates/index.html | 8 +++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index cb888c5..b5efe3e 100644 --- a/app.py +++ b/app.py @@ -13,7 +13,7 @@ from datetime import datetime from pathlib import Path import requests -from flask import Flask, jsonify, render_template, request +from flask import Flask, jsonify, render_template, request, send_from_directory RADARR_URL = os.environ.get("RADARR_URL", "http://radarr:7878").rstrip("/") RADARR_API_KEY = os.environ.get("RADARR_API_KEY", "") @@ -57,6 +57,15 @@ try: except OSError as exc: log.warning("Datei-Logging nicht verfügbar (%s): %s", LOG_FILE, exc) app = Flask(__name__) + + +@app.get("/sw.js") +def service_worker(): + """Serve the worker from the origin root so it can control the whole app.""" + response = send_from_directory(app.static_folder, "sw.js", mimetype="application/javascript") + response.headers["Service-Worker-Allowed"] = "/" + response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" + return response executor = ThreadPoolExecutor(max_workers=int(os.environ.get("SCAN_WORKERS", "2"))) scan_executor = ThreadPoolExecutor(max_workers=int(os.environ.get("SCAN_WORKERS", "4"))) jobs = {"radarr": {"state": "idle", "total": 0, "done": 0, "error": None}, "sonarr": {"state": "idle", "total": 0, "done": 0, "error": None}} diff --git a/static/manifest.json b/static/manifest.json index 536ff79..16ad1aa 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -13,7 +13,8 @@ "theme_color": "#1f252d", "orientation": "any", "icons": [ - {"src": "/static/media-mark-192.svg", "sizes": "192x192", "type": "image/svg+xml", "purpose": "any maskable"}, - {"src": "/static/media-mark-512.svg", "sizes": "512x512", "type": "image/svg+xml", "purpose": "any maskable"} + {"src": "/static/media-mark-192.svg", "sizes": "192x192", "type": "image/svg+xml", "purpose": "any"}, + {"src": "/static/media-mark-512.svg", "sizes": "512x512", "type": "image/svg+xml", "purpose": "any"}, + {"src": "/static/media-mark-512.svg", "sizes": "512x512", "type": "image/svg+xml", "purpose": "maskable"} ] } diff --git a/static/media-mark-192.svg b/static/media-mark-192.svg index 1a6011a..a912e33 100644 --- a/static/media-mark-192.svg +++ b/static/media-mark-192.svg @@ -1 +1 @@ - + diff --git a/static/sw.js b/static/sw.js index 6beaa79..48e8d32 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,5 +1,5 @@ -const CACHE_NAME = 'media-max-shell-v3'; -const SHELL = ['/static/media-mark.svg', '/static/manifest.json']; +const CACHE_NAME = 'media-max-shell-v4'; +const SHELL = ['/static/media-mark.svg', '/static/media-mark-192.svg', '/static/media-mark-512.svg', '/static/manifest.json']; self.addEventListener('install', event => { event.waitUntil(caches.open(CACHE_NAME).then(cache => cache.addAll(SHELL))); diff --git a/templates/index.html b/templates/index.html index 1b1baad..724776e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,11 @@ + @@ -29,7 +36,6 @@
MEDIA
Media Max
Audio- und Untertitelspuren aus den Mediendateien
-{% if error %}{% endif %}
MEDIA MAX

Dashboard

Deine gesamte Medienbibliothek und Systemauslastung auf einen Blick.

Live
Filme{{ rows|length }}Radarr Library
Serien{{ series|length }}Sonarr Shows
Ohne Deutsch{{ missing_german_movies|length + (missing_german_series|map(attribute='episodes')|map('length')|sum) }}Audio oder Untertitel prüfen
DownloadsSABnzbd wird geladen …

Systemauslastung

Aktuelle Werte aus dem Dashboard-Container

Wird geladen …
CPU
RAM
Laufwerke werden geladen …

Dienste

Verbindung und Bibliotheksstatus

RadarrFilme & Qualität
Aktiv
SonarrSerien & Episoden
{% if sonarr_enabled %}Aktiv{% else %}Nicht konfiguriert{% endif %}
SABnzbdDownloads & Queue
{% if sab_enabled %}Wird geprüft …{% else %}Nicht konfiguriert{% endif %}