Fixed code styling.
This commit is contained in:
1 parent
7b716c1115
commit
c8ae3d3ff9
11 files changed
+85
-96
No files matched your search
+16
-31
@@ -1,38 +1,35 @@
|
||||
#![feature(future_join)]
|
||||
|
||||
use std::{collections::HashMap, env, fs, io, path::PathBuf};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use crate::webui::worker::worker_loop;
|
||||
use actix_files;
|
||||
use actix_utils::future::{ready, Ready};
|
||||
|
||||
use actix_web::{
|
||||
App,
|
||||
dev::ServiceResponse,
|
||||
error,
|
||||
FromRequest,
|
||||
http::{header::ContentType, StatusCode}, HttpRequest, HttpResponse, HttpServer, middleware::{ErrorHandlerResponse, ErrorHandlers, Logger}, Responder, Result, web,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers, Logger},
|
||||
web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, Result,
|
||||
};
|
||||
use actix_web_lab::respond::Html;
|
||||
use async_channel;
|
||||
use futures::{FutureExt, pin_mut, select};
|
||||
use futures::{pin_mut, select, FutureExt};
|
||||
use minijinja;
|
||||
use minijinja_autoreload::AutoReloader;
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
|
||||
mod views;
|
||||
mod config;
|
||||
mod worker;
|
||||
|
||||
struct MiniJinjaRenderer {
|
||||
tmpl_env: web::Data<minijinja_autoreload::AutoReloader>,
|
||||
}
|
||||
|
||||
impl MiniJinjaRenderer {
|
||||
fn render(
|
||||
&self,
|
||||
tmpl: &str,
|
||||
ctx: impl Into<minijinja::value::Value>,
|
||||
) -> Result<Html> {
|
||||
fn render(&self, tmpl: &str, ctx: impl Into<minijinja::value::Value>) -> Result<Html> {
|
||||
log::info!("Rendering template {:?}", tmpl);
|
||||
self.tmpl_env
|
||||
.acquire_env()
|
||||
@@ -61,19 +58,6 @@ impl FromRequest for MiniJinjaRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
async fn worker_loop(r: async_channel::Receiver<i32>) -> io::Result<()> {
|
||||
loop {
|
||||
let x = r.recv().await;
|
||||
match x {
|
||||
Ok(v) => println!("Processed value: {:?}", v),
|
||||
Err(e) => {
|
||||
println!("Error: {:?}", e);
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io::Result<()> {
|
||||
// The closure is invoked every time the environment is outdated to recreate it.
|
||||
@@ -99,8 +83,9 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
|
||||
App::new()
|
||||
.app_data(tmpl_reloader.clone())
|
||||
.app_data(web::Data::new(s.clone()))
|
||||
.service(actix_files::Files::new("/static", "./resources/static/")
|
||||
.use_last_modified(true))
|
||||
.service(
|
||||
actix_files::Files::new("/static", "./resources/static/").use_last_modified(true),
|
||||
)
|
||||
.service(views::index)
|
||||
.service(views::actions)
|
||||
.service(views::overview)
|
||||
@@ -117,7 +102,7 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
|
||||
let t2 = worker_loop(r).fuse();
|
||||
pin_mut!(t1, t2);
|
||||
|
||||
select!{
|
||||
select! {
|
||||
x = t1 => x,
|
||||
y = t2 => y,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user