diff --git a/backend/main.py b/backend/main.py index fe27243..3f3a50c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -3,7 +3,7 @@ NoteDiscovery - Self-Hosted Markdown Knowledge Base Main FastAPI application """ -from fastapi import FastAPI, HTTPException, UploadFile, File, Request, Form, Depends, APIRouter +from fastapi import FastAPI, HTTPException, UploadFile, File, Request, Form, Depends, APIRouter, Response from fastapi.staticfiles import StaticFiles from fastapi.responses import HTMLResponse, JSONResponse, FileResponse, RedirectResponse from fastapi.middleware.cors import CORSMiddleware @@ -171,6 +171,21 @@ plugin_manager.run_hook('on_app_startup') static_path = Path(__file__).parent.parent / "frontend" app.mount("/static", StaticFiles(directory=static_path), name="static") +# PWA Service Worker - must be served from root for proper scope +@app.get("/sw.js") +@limiter.limit("30/minute") +async def service_worker(request: Request): + """Serve the PWA service worker from root path for proper scope. + Injects the app version from VERSION file for cache invalidation.""" + sw_path = static_path / "sw.js" + if sw_path.exists(): + async with aiofiles.open(sw_path, 'r', encoding='utf-8') as f: + content = await f.read() + # Inject app version into cache name + content = content.replace('__APP_VERSION__', version) + return Response(content=content, media_type="application/javascript") + raise HTTPException(status_code=404, detail="Service worker not found") + # ============================================================================ # Custom Exception Handlers diff --git a/frontend/app.js b/frontend/app.js index 8644aa5..d01e9e2 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -875,6 +875,15 @@ function noteApp() { if (this.showGraph) { setTimeout(() => this.initGraph(), 300); } + + // Update PWA theme-color meta tag to match current theme + const themeColorMeta = document.querySelector('meta[name="theme-color"]'); + if (themeColorMeta) { + // Get the accent color from CSS variables + const accentColor = getComputedStyle(document.documentElement) + .getPropertyValue('--accent-primary').trim() || '#667eea'; + themeColorMeta.setAttribute('content', accentColor); + } } catch (error) { console.error('Failed to load theme:', error); } diff --git a/frontend/index.html b/frontend/index.html index 44aa8c5..8548888 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -11,6 +11,20 @@ + + + + + + + + + + + + + + @@ -2816,6 +2830,21 @@ + + + diff --git a/frontend/login.html b/frontend/login.html index 6ae4e0c..8e0706e 100644 --- a/frontend/login.html +++ b/frontend/login.html @@ -6,6 +6,13 @@ Login - NoteDiscovery + + + + + + +