wallpaper fix

This commit is contained in:
2025-02-19 21:14:02 +01:00
parent 209a23509b
commit d5a92d187f
5 changed files with 195 additions and 145 deletions

View File

@@ -564,12 +564,32 @@ def get_settings():
else:
# Falls noch kein Datensatz existiert
return jsonify({
"wallpaper": "1.png",
"wallpaper": "24.png",
"city": "",
"show_forecast": False,
"bookmarks": []
})
@app.context_processor
def inject_wallpaper():
"""
Dieser Context Processor wird bei jedem Template-Aufruf ausgeführt.
Ermittelt das Wallpaper des eingeloggten Benutzers (falls eingeloggt)
und stellt es allen Templates als Variable 'WALLPAPER_URL' bereit.
"""
if 'user_id' in session:
db = get_db()
row = db.execute("SELECT wallpaper FROM user_settings WHERE user_id=?", (session['user_id'],)).fetchone()
if row and row['wallpaper']:
# Bsp: row['wallpaper'] könnte '19.png' o. ä. sein
return {
"WALLPAPER_URL": url_for('static', filename=row['wallpaper'])
}
# Fallback: Wenn User nicht eingeloggt oder kein Wallpaper gesetzt
return {
"WALLPAPER_URL": url_for('static', filename='24.png')
}
@app.route('/save_settings', methods=['POST'])
def save_settings():
"""
@@ -580,7 +600,7 @@ def save_settings():
return jsonify({"success": False, "error": "not logged in"}), 403
data = request.get_json()
wallpaper = data.get('wallpaper', '1.png')
wallpaper = data.get('wallpaper', '24.png')
city = data.get('city', '')
show_forecast = data.get('show_forecast', False)
bookmarks_list = data.get('bookmarks', [])