get_config realisiert, damti der darkmode aus der yaml geladen wird
This commit is contained in:
1 parent
3fb6051e4a
commit
49bd17d52b
6 files changed
+105
-86
No files matched your search
+15
-14
@@ -1,6 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DefaultConfig {
|
||||
pub loglevel: Option<String>,
|
||||
pub darkmode: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModbusConfig {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub max_coils_addr: Option<u16>,
|
||||
pub max_input_addr: Option<u16>,
|
||||
pub max_holding_addr: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct MqttConfig {
|
||||
pub broker: String,
|
||||
@@ -30,20 +45,6 @@ pub struct ModbusRegisterConfig {
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModbusConfig {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub max_coils_addr: Option<u16>,
|
||||
pub max_input_addr: Option<u16>,
|
||||
pub max_holding_addr: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DefaultConfig {
|
||||
pub loglevel: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AppConfig {
|
||||
pub default: DefaultConfig,
|
||||
|
||||
+6
-7
@@ -1,4 +1,3 @@
|
||||
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Result};
|
||||
use actix_files as actix_fs;
|
||||
use std::sync::{Mutex, Arc};
|
||||
@@ -12,9 +11,6 @@ mod modbus;
|
||||
use crate::config::{AppConfig, ModbusRegisterConfig, ModbusValueMaps};
|
||||
|
||||
|
||||
|
||||
// ...existing code...
|
||||
|
||||
struct AppState {
|
||||
config: Mutex<AppConfig>,
|
||||
value_maps: Arc<Mutex<ModbusValueMaps>>,
|
||||
@@ -44,9 +40,6 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ...existing code...
|
||||
|
||||
async fn index(data: web::Data<AppState>) -> Result<HttpResponse> {
|
||||
let config = data.config.lock().unwrap();
|
||||
let value_maps = data.value_maps.lock().unwrap();
|
||||
@@ -184,6 +177,11 @@ async fn save_settings(
|
||||
Ok(HttpResponse::Ok().body("success"))
|
||||
}
|
||||
|
||||
async fn get_config(data: web::Data<AppState>) -> HttpResponse {
|
||||
let config = data.config.lock().unwrap();
|
||||
HttpResponse::Ok().json(&*config)
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
|
||||
@@ -215,6 +213,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.route("/settings", web::get().to(settings_page))
|
||||
.route("/api/save", web::post().to(save_table))
|
||||
.route("/api/save-settings", web::post().to(save_settings))
|
||||
.route("/api/config", web::get().to(get_config))
|
||||
.service(actix_fs::Files::new("/static", "./static"))
|
||||
})
|
||||
.bind("0.0.0.0:8080")?
|
||||
|
||||
Reference in new issue
Block a user