extern crate listenfd;
extern crate askama;
+// use futures::sink::With;
use listenfd::ListenFd;
use actix_files as fs;
-use actix_web::{ get, web, Responder, middleware, App, HttpServer, web::Query };
+use actix_web::{ get, Responder, middleware, App, HttpServer, web::Query };
use askama::Template;
-use std::{ sync::Mutex, fs::File, env::args, io::prelude::* };
+use std::{ /*sync::Mutex, */fs::File, env::args, io::prelude::* };
use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } };
use serde::{ Deserialize, Serialize };
#[derive(Template)]
#[template(path = "main.html")]
struct MainTemplate {
- sentence: String,
+ text_status: String,
+ memory: String,
+ cpu: String,
+ uptime: String
}
#[derive(Deserialize)]
m: Option<String>
}
+const VALUE_UNKNOWN: &str = "-";
+
#[get("/")]
async fn main_page(/*key_shared: web::Data<Mutex<String>>,*/ query: Query<Request>) -> impl Responder {
//let key = key_shared.lock().unwrap();
- let m =
+ match valheim_controller::get_valheim_executable_information() {
+ Some(info) =>
+ MainTemplate {
+ text_status: String::from("Valheim server is up and running :)"),
+ memory: info.format_memory(),
+ cpu: info.format_cpu_usage(),
+ uptime: info.format_uptime()
+ },
+ None => {
+ let value_unknown = String::from(VALUE_UNKNOWN);
+ MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), cpu: value_unknown.clone(), uptime: value_unknown.clone() }
+ }
+ }
+
+ /*
+
+ let m =
if valheim_controller::is_valheim_running() { String::from("Valheim server is up and running") } else { String::from("Valheim server is down :(") };
MainTemplate { sentence: m }
+ */
}
#[derive(Debug, Deserialize, Serialize)]
if process_args() { return Ok(()) }
- println!("Starting RUP as web server...");
+ println!("Starting Valheim Admin as web server...");
let config = load_config();
print_usage();
return true
} else if args.iter().any(|arg| arg == "--status") {
- valheim_controller::is_valheim_running();
+ println!("{:?}", valheim_controller::get_valheim_executable_information());
return true
}