From 57192ea010a9598fa6d95e5e9e23f116df7bf49e Mon Sep 17 00:00:00 2001 From: rene Date: Fri, 15 May 2026 18:11:52 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Routen-Aufzeichnung=20offline=20?= =?UTF-8?q?=E2=80=94=20Buttons=20Abbruch/Start=20reagieren=20nicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L.map() warf ReferenceError wenn Leaflet offline nicht geladen → _openRecOvl() crashte, Event-Listener für #rk-rec-cancel und #rk-rec-startbtn wurden nie angehängt. Fix: - Listener direkt nach appendChild() registrieren (vor jeder async-Operation) - Map-Setup in try/catch; bei fehlendem Leaflet: Offline-Platzhalter im Map-Bereich - _recMap?.setView / _recLocMarker?.setLatLng mit Optional Chaining (null-safe) - SW by-v994, APP_VER 994 --- backend/main.py | 2 +- backend/static/js/app.js | 2 +- backend/static/js/pages/routes.js | 39 ++++++++++++++++++++----------- backend/static/sw.js | 2 +- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/backend/main.py b/backend/main.py index 42f22ba..c2a6929 100644 --- a/backend/main.py +++ b/backend/main.py @@ -410,7 +410,7 @@ async def serve_media(path: str, request: _Request): raise _HE(404, "Nicht gefunden.") return _media_response(filepath) -APP_VER = "993" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "994" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/static/js/app.js b/backend/static/js/app.js index aa2c342..67c2516 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '993'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '994'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; // Cache-Bust-Parameter nach Update-Reload sofort entfernen diff --git a/backend/static/js/pages/routes.js b/backend/static/js/pages/routes.js index 4689ded..7213da3 100644 --- a/backend/static/js/pages/routes.js +++ b/backend/static/js/pages/routes.js @@ -726,24 +726,37 @@ window.Page_routes = (() => { document.body.appendChild(ovl); _recOvl = ovl; - const pos = _userPos || { lat: 48.1, lon: 11.5 }; - _recMap = L.map(ovl.querySelector('#rk-rec-map-wrap'), { zoomControl: false, attributionControl: false }) - .setView([pos.lat, pos.lon], 15); - L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19 }).addTo(_recMap); - _recLocMarker = L.circleMarker([pos.lat, pos.lon], { - radius: 8, color: '#fff', weight: 2.5, fillColor: '#3b82f6', fillOpacity: 1 - }).addTo(_recMap); + // Listener sofort nach DOM-Einfügen — nicht nach async-Operationen + ovl.querySelector('#rk-rec-cancel').addEventListener('click', () => _closeRecOvlClean()); + ovl.querySelector('#rk-rec-startbtn').addEventListener('click', _startRecInOvl); - // Get accurate position + // Map-Setup: Leaflet könnte offline fehlen → alles in try/catch + const pos = _userPos || { lat: 48.1, lon: 11.5 }; + try { + if (!window.L) throw new Error('Leaflet not loaded'); + _recMap = L.map(ovl.querySelector('#rk-rec-map-wrap'), { zoomControl: false, attributionControl: false }) + .setView([pos.lat, pos.lon], 15); + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19 }).addTo(_recMap); + _recLocMarker = L.circleMarker([pos.lat, pos.lon], { + radius: 8, color: '#fff', weight: 2.5, fillColor: '#3b82f6', fillOpacity: 1 + }).addTo(_recMap); + } catch { + const mapWrap = ovl.querySelector('#rk-rec-map-wrap'); + if (mapWrap) mapWrap.innerHTML = + `
+ 📡 + Karte offline nicht verfügbar — GPS läuft trotzdem +
`; + } + + // Genaueren Standort nachladen (best-effort, klappt auch offline via gespeichertem GPS) try { const p = await API.getLocation(); _userPos = p; - _recMap.setView([p.lat, p.lon], 16); - _recLocMarker.setLatLng([p.lat, p.lon]); + _recMap?.setView([p.lat, p.lon], 16); + _recLocMarker?.setLatLng([p.lat, p.lon]); } catch {} - - ovl.querySelector('#rk-rec-cancel').addEventListener('click', () => _closeRecOvlClean()); - ovl.querySelector('#rk-rec-startbtn').addEventListener('click', _startRecInOvl); } async function _startRecInOvl() { diff --git a/backend/static/sw.js b/backend/static/sw.js index aa5a66d..bb12985 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -3,7 +3,7 @@ Offline-Cache + Push Notifications + Tile-Cache ============================================================ */ -const CACHE_VERSION = 'by-v993'; +const CACHE_VERSION = 'by-v994'; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache