main.py nutzt nun import app.state as state und schreibt/liest konsequent state.current_config

This commit is contained in:
oberon 2026-02-16 20:54:12 +01:00
parent 0d6e416464
commit 93bd4cc06d

View File

@ -5,7 +5,7 @@ import json
from flask import Blueprint, render_template, redirect, url_for, request, jsonify, send_from_directory, current_app
from app.utils.helpers import load_configs, load_default_sounds
from app.state import current_config, reset_state
import app.state as state
from config import Config
@ -39,7 +39,6 @@ def serve_config_file(filename):
@main_bp.route('/load_config/<filename>')
def load_config(filename):
global current_config
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
if not os.path.exists(path):
@ -48,9 +47,9 @@ def load_config(filename):
try:
with open(path, 'r', encoding='utf-8') as f:
current_config = json.load(f)
current_config['filename'] = filename
logger.info(f"Config erfolgreich geladen: {filename} mit {len(current_config.get('channels', []))} Kanälen")
state.current_config = json.load(f)
state.current_config['filename'] = filename
logger.info(f"Config erfolgreich geladen: {filename} mit {len(state.current_config.get('channels', []))} Kanälen")
return redirect(url_for('main.control_page'))
except json.JSONDecodeError as e:
logger.error(f"Ungültiges JSON in {filename}: {e}")
@ -62,26 +61,26 @@ def load_config(filename):
@main_bp.route('/control')
def control_page():
if current_config is None:
if state.current_config is None:
logger.warning("current_config ist None → Redirect zu index")
return redirect(url_for('main.index'))
# Globale Sounds immer laden
global_sounds = load_default_sounds(current_app.config['CONFIG_DIR'])
logger.info(f"Steuerseite geladen für Config: {current_config.get('filename', 'unbekannt')} mit {len(current_config.get('channels', []))} Kanälen")
logger.info(f"Steuerseite geladen für Config: {state.current_config.get('filename', 'unbekannt')} mit {len(state.current_config.get('channels', []))} Kanälen")
logger.info(f"Übergebe config an Template: {current_config}")
print("DEBUG: config hat channels?", 'channels' in current_config, len(current_config.get('channels', [])))
logger.info(f"Übergebe config an Template: {state.current_config}")
print("DEBUG: config hat channels?", 'channels' in state.current_config, len(state.current_config.get('channels', [])))
return render_template('control.html', config=current_config, global_sounds=global_sounds)
return render_template('control.html', config=state.current_config, global_sounds=global_sounds)
@main_bp.route('/soundboard')
def soundboard():
if current_config is None or 'sounds' not in current_config:
if state.current_config is None or 'sounds' not in state.current_config:
return redirect(url_for('main.index'))
sounds = current_config.get('sounds', [])
return render_template('soundboard.html', sounds=sounds, config=current_config)
sounds = state.current_config.get('sounds', [])
return render_template('soundboard.html', sounds=sounds, config=state.current_config)
pass