diff --git a/backend/database.py b/backend/database.py index cff0f89..89c141e 100644 --- a/backend/database.py +++ b/backend/database.py @@ -2075,6 +2075,10 @@ def _migrate(conn_factory): _seed_help_articles(conn) logger.info("Migration: Hilfe/FAQ-Tabelle bereit.") + if 'preferred_theme' not in [row[1] for row in conn.execute("PRAGMA table_info(users)").fetchall()]: + conn.execute("ALTER TABLE users ADD COLUMN preferred_theme TEXT DEFAULT 'system'") + logger.info("Migration: preferred_theme Spalte zu users hinzugefügt.") + conn.executescript(""" CREATE TABLE IF NOT EXISTS bday_ki_cache ( dog_id INTEGER NOT NULL, diff --git a/backend/main.py b/backend/main.py index 9218a81..4a9ee01 100644 --- a/backend/main.py +++ b/backend/main.py @@ -327,7 +327,7 @@ MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media") os.makedirs(MEDIA_DIR, exist_ok=True) app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media") -APP_VER = "784" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "785" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/routes/auth.py b/backend/routes/auth.py index 4772ae6..a0174e6 100644 --- a/backend/routes/auth.py +++ b/backend/routes/auth.py @@ -238,7 +238,9 @@ async def me(user=Depends(get_current_user)): """SELECT id, name, real_name, email, rolle, is_premium, email_verified, bio, wohnort, erfahrung, social_link, profil_sichtbarkeit, avatar_url, created_at, - is_founder, is_partner, founder_number, is_founder_pending + is_founder, is_partner, founder_number, is_founder_pending, + notes_ki_enabled, gassi_stunde_push, + preferred_theme FROM users WHERE id=?""", (user["id"],) ).fetchone() diff --git a/backend/routes/profile.py b/backend/routes/profile.py index 9762f95..9cb0667 100644 --- a/backend/routes/profile.py +++ b/backend/routes/profile.py @@ -27,6 +27,7 @@ class ProfileUpdate(BaseModel): profil_sichtbarkeit: Optional[str] = None notes_ki_enabled: Optional[int] = None gassi_stunde_push: Optional[int] = None + preferred_theme: Optional[str] = None def _load_user(user_id: int) -> dict: @@ -54,6 +55,8 @@ async def update_profile(data: ProfileUpdate, user=Depends(get_current_user)): raise HTTPException(400, f"erfahrung muss eines von {sorted(VALID_ERFAHRUNG)} sein.") if "profil_sichtbarkeit" in fields and fields["profil_sichtbarkeit"] not in VALID_SICHTBARKEIT: raise HTTPException(400, f"profil_sichtbarkeit muss eines von {sorted(VALID_SICHTBARKEIT)} sein.") + if "preferred_theme" in fields and fields["preferred_theme"] not in ("system", "light", "dark"): + raise HTTPException(400, "preferred_theme muss 'system', 'light' oder 'dark' sein.") if "bio" in fields and len(fields["bio"]) > 300: raise HTTPException(400, "bio darf maximal 300 Zeichen lang sein.") if "wohnort" in fields and len(fields["wohnort"]) > 60: diff --git a/backend/static/index.html b/backend/static/index.html index 7213d86..8b0f233 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -575,10 +575,10 @@ - - - - + + + + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 163f8de..d7377de 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 = '784'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '785'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.5.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; // Cache-Bust-Parameter nach Update-Reload sofort entfernen @@ -529,6 +529,9 @@ const App = (() => { navigate('onboarding'); } + // Theme aus DB-Profil übernehmen (überschreibt localStorage-Wert) + _applyUserTheme(state.user); + // Drei Welten nach Login starten (falls noch nicht initialisiert) if (window.Worlds) window.Worlds.init(state); @@ -607,6 +610,15 @@ const App = (() => { navigate('welcome', false); } + function _applyUserTheme(user) { + const theme = user?.preferred_theme; + if (!theme || theme === 'system') return; // System-Einstellung: nichts tun + localStorage.setItem('by_theme', theme); + const html = document.documentElement; + if (theme === 'dark') html.setAttribute('data-theme', 'dark'); + else if (theme === 'light') html.setAttribute('data-theme', 'light'); + } + function _showVerifyBanner() { const banner = document.getElementById('verify-banner'); if (!banner) return; diff --git a/backend/static/js/pages/settings.js b/backend/static/js/pages/settings.js index 07cfab3..b772d0f 100644 --- a/backend/static/js/pages/settings.js +++ b/backend/static/js/pages/settings.js @@ -315,9 +315,9 @@ window.Page_settings = (() => { font-size:var(--text-sm); font-family:inherit; cursor:pointer"> - - - + + + @@ -849,22 +849,22 @@ window.Page_settings = (() => { } }); - document.getElementById('select-theme')?.addEventListener('change', e => { + document.getElementById('select-theme')?.addEventListener('change', async e => { const val = e.target.value; - localStorage.setItem('by_theme', val); + localStorage.setItem('by_theme', val); // lokaler Cache für schnellen Start const html = document.documentElement; - if (val === 'dark') { - html.setAttribute('data-theme', 'dark'); - } else if (val === 'light') { - html.setAttribute('data-theme', 'light'); - } else { - html.removeAttribute('data-theme'); - } + if (val === 'dark') html.setAttribute('data-theme', 'dark'); + else if (val === 'light') html.setAttribute('data-theme', 'light'); + else html.removeAttribute('data-theme'); UI.toast.info( val === 'dark' ? 'Dark Mode aktiviert.' : val === 'light' ? 'Hell-Modus aktiviert.' : 'Theme folgt der Systemeinstellung.' ); + try { + await API.patch('/profile', { preferred_theme: val }); + if (_appState?.user) _appState.user.preferred_theme = val; + } catch { /* ignorieren — localStorage-Fallback greift */ } }); document.getElementById('toggle-pocket-mode')?.addEventListener('change', e => { diff --git a/backend/static/sw.js b/backend/static/sw.js index fbdb8fe..0149aa7 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-v784'; +const CACHE_VERSION = 'by-v785'; 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