endlich funktionierender Darkmodus

This commit is contained in:
eneuber committed 2026-02-13 22:21:29 +01:00
1 parent 4bc399b44f
commit e8d77ec18e
3 files changed
+34 -38

No files matched your search

+17 -3
View File
@@ -117,7 +117,10 @@ async fn settings_page(data: web::Data<AppState>) -> Result<HttpResponse> {
eprintln!("Template error: {}", e);
actix_web::error::ErrorInternalServerError("Template error")
})?;
Ok(HttpResponse::Ok().content_type("text/html").body(html))
Ok(HttpResponse::Ok()
.content_type("text/html")
.insert_header(("Cache-Control", "no-store, must-revalidate"))
.body(html))
}
@@ -194,15 +197,26 @@ async fn save_settings(
// Value-Maps neu initialisieren
let mut value_maps = data.value_maps.lock().unwrap();
*value_maps = ModbusValueMaps::from_config(&new_config);
*config = new_config;
let conf_path = "paramod.yaml";
let yaml_str = match serde_yaml::to_string(&*config) {
let yaml_str = match serde_yaml::to_string(&new_config) {
Ok(s) => s,
Err(e) => return Ok(HttpResponse::InternalServerError().body(format!("Serialisierungsfehler: {}", e))),
};
if let Err(e) = fs::write(conf_path, yaml_str) {
return Ok(HttpResponse::InternalServerError().body(format!("Fehler beim Schreiben: {}", e)));
}
// Reload config from file
let conf_str = match std::fs::read_to_string(conf_path) {
Ok(s) => s,
Err(e) => return Ok(HttpResponse::InternalServerError().body(format!("Fehler beim Lesen: {}", e))),
};
let mut updated_config: AppConfig = match serde_yaml::from_str(&conf_str) {
Ok(cfg) => cfg,
Err(e) => return Ok(HttpResponse::InternalServerError().body(format!("Deserialisierungsfehler: {}", e))),
};
// darkmode-Konvertierung: String zu bool
// (YAML kann bool als string interpretieren)
*config = updated_config;
Ok(HttpResponse::Ok().body("success"))
}