chore: moved to only one message
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
390b30d084
commit
99e8a25686
@ -308,7 +308,7 @@ pub async fn stop_animation(name: &str, stop_sender: &State<ASender<String>>) ->
|
|||||||
#[get("/start/<name>")]
|
#[get("/start/<name>")]
|
||||||
pub async fn start_animation(
|
pub async fn start_animation(
|
||||||
name: &str,
|
name: &str,
|
||||||
start_sender: &State<ASender<Animation>>,
|
action: &State<ASender<Action>>,
|
||||||
db: &State<DBPool>,
|
db: &State<DBPool>,
|
||||||
) -> String {
|
) -> String {
|
||||||
println!("try to get animation!");
|
println!("try to get animation!");
|
||||||
@ -335,7 +335,7 @@ pub async fn start_animation(
|
|||||||
|
|
||||||
let animation = animation.unwrap();
|
let animation = animation.unwrap();
|
||||||
|
|
||||||
let r = start_sender.lock().unwrap().send(animation);
|
let r = action.lock().unwrap().send(Action::Start(animation));
|
||||||
if r.is_err() || r.as_ref().ok().is_none() {
|
if r.is_err() || r.as_ref().ok().is_none() {
|
||||||
return json!(ApiResponse {
|
return json!(ApiResponse {
|
||||||
code: 500,
|
code: 500,
|
||||||
@ -658,10 +658,8 @@ fn get_error_message(message: &str) -> String {
|
|||||||
#[get("/toggle/<name>")]
|
#[get("/toggle/<name>")]
|
||||||
pub async fn toggle_animation(
|
pub async fn toggle_animation(
|
||||||
name: &str,
|
name: &str,
|
||||||
start_sender: &State<ASender<Animation>>,
|
|
||||||
action: &State<ASender<Action>>,
|
action: &State<ASender<Action>>,
|
||||||
messages: &State<AReceiver<RenderMessage>>,
|
messages: &State<AReceiver<RenderMessage>>,
|
||||||
stop_sender: &State<ASender<String>>,
|
|
||||||
db: &State<DBPool>,
|
db: &State<DBPool>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let animation = get_animation_or_string_error(name, db);
|
let animation = get_animation_or_string_error(name, db);
|
||||||
@ -670,7 +668,9 @@ pub async fn toggle_animation(
|
|||||||
}
|
}
|
||||||
let animation = animation.unwrap();
|
let animation = animation.unwrap();
|
||||||
|
|
||||||
let send = action.lock().unwrap().send(Action::GetActiveList);
|
let action = action.lock().unwrap();
|
||||||
|
|
||||||
|
let send = action.send(Action::GetActiveList);
|
||||||
if send.is_err() || send.ok().is_none() {
|
if send.is_err() || send.ok().is_none() {
|
||||||
return get_error_message("Failed to get list");
|
return get_error_message("Failed to get list");
|
||||||
}
|
}
|
||||||
@ -683,7 +683,7 @@ pub async fn toggle_animation(
|
|||||||
if let RenderMessage::ActiveList(list) = data.ok().unwrap() {
|
if let RenderMessage::ActiveList(list) = data.ok().unwrap() {
|
||||||
if list.contains(&name.to_string()) {
|
if list.contains(&name.to_string()) {
|
||||||
// Disable
|
// Disable
|
||||||
let r = stop_sender.lock().unwrap().send(name.to_string());
|
let r = action.send(Action::Stop(name.to_string()));
|
||||||
|
|
||||||
if r.is_err() || r.ok().is_none() {
|
if r.is_err() || r.ok().is_none() {
|
||||||
return get_error_message("Something went wrong");
|
return get_error_message("Something went wrong");
|
||||||
@ -692,7 +692,7 @@ pub async fn toggle_animation(
|
|||||||
return create_message(200, "Configuration was successful");
|
return create_message(200, "Configuration was successful");
|
||||||
} else {
|
} else {
|
||||||
// Enable
|
// Enable
|
||||||
let r = start_sender.lock().unwrap().send(animation);
|
let r = action.send(Action::Start(animation));
|
||||||
if r.is_err() || r.as_ref().ok().is_none() {
|
if r.is_err() || r.as_ref().ok().is_none() {
|
||||||
return get_error_message("Probelms with the sender");
|
return get_error_message("Probelms with the sender");
|
||||||
}
|
}
|
||||||
|
45
src/main.rs
45
src/main.rs
@ -39,9 +39,11 @@ fn index() -> &'static str {
|
|||||||
|
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
Reload,
|
Reload,
|
||||||
Stop,
|
Exit,
|
||||||
Clear,
|
Clear,
|
||||||
GetActiveList,
|
GetActiveList,
|
||||||
|
Start(Animation),
|
||||||
|
Stop(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RenderMessage {
|
pub enum RenderMessage {
|
||||||
@ -54,7 +56,7 @@ pub enum RenderMessage {
|
|||||||
async fn quit(shutdown: rocket::Shutdown, action: &State<ASender<Action>>) -> String {
|
async fn quit(shutdown: rocket::Shutdown, action: &State<ASender<Action>>) -> String {
|
||||||
println!("Got Shutdown");
|
println!("Got Shutdown");
|
||||||
|
|
||||||
let send = action.lock().unwrap().send(Action::Stop);
|
let send = action.lock().unwrap().send(Action::Exit);
|
||||||
|
|
||||||
if send.is_err() || send.ok().is_none() {
|
if send.is_err() || send.ok().is_none() {
|
||||||
return json!(ApiResponse {
|
return json!(ApiResponse {
|
||||||
@ -97,8 +99,6 @@ async fn reload(action: &State<ASender<Action>>) -> String {
|
|||||||
fn ligth_controll(
|
fn ligth_controll(
|
||||||
pool: DBPool,
|
pool: DBPool,
|
||||||
action: Receiver<Action>,
|
action: Receiver<Action>,
|
||||||
start_ani: Receiver<Animation>,
|
|
||||||
stop_ani: Receiver<String>,
|
|
||||||
message_server: Sender<RenderMessage>,
|
message_server: Sender<RenderMessage>,
|
||||||
) {
|
) {
|
||||||
println!("Data loop started");
|
println!("Data loop started");
|
||||||
@ -115,8 +115,8 @@ fn ligth_controll(
|
|||||||
'mainloop: loop {
|
'mainloop: loop {
|
||||||
let action = action.try_recv();
|
let action = action.try_recv();
|
||||||
|
|
||||||
if action.is_ok() {
|
if let Ok(action) = action {
|
||||||
match action.ok().unwrap() {
|
match action {
|
||||||
Action::Reload => {
|
Action::Reload => {
|
||||||
let result = render.load_config();
|
let result = render.load_config();
|
||||||
if result.is_err() || result.as_ref().ok().is_none() {
|
if result.is_err() || result.as_ref().ok().is_none() {
|
||||||
@ -126,7 +126,7 @@ fn ligth_controll(
|
|||||||
Action::Clear => {
|
Action::Clear => {
|
||||||
render.blank();
|
render.blank();
|
||||||
}
|
}
|
||||||
Action::Stop => {
|
Action::Exit => {
|
||||||
render.blank();
|
render.blank();
|
||||||
render.im_render();
|
render.im_render();
|
||||||
break 'mainloop;
|
break 'mainloop;
|
||||||
@ -139,24 +139,15 @@ fn ligth_controll(
|
|||||||
println!("Failed to send message ups");
|
println!("Failed to send message ups");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Action::Start(animation) => {
|
||||||
|
render.add_animation(animation);
|
||||||
|
}
|
||||||
|
Action::Stop(animation) => {
|
||||||
|
render.remove_animation(animation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ani = start_ani.try_recv();
|
|
||||||
|
|
||||||
if ani.is_ok() {
|
|
||||||
println!("Added animation");
|
|
||||||
//TODO
|
|
||||||
render.add_animation(ani.ok().unwrap());
|
|
||||||
//ani.ok().unwrap().
|
|
||||||
}
|
|
||||||
|
|
||||||
let ani = stop_ani.try_recv();
|
|
||||||
|
|
||||||
if ani.is_ok() {
|
|
||||||
render.remove_animation(ani.ok().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
render.render();
|
render.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,12 +171,6 @@ async fn main() -> GResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (action_sender, action_receiver): (Sender<Action>, Receiver<Action>) = mpsc::channel();
|
let (action_sender, action_receiver): (Sender<Action>, Receiver<Action>) = mpsc::channel();
|
||||||
let (start_animation_sender, start_animation_receiver): (
|
|
||||||
Sender<Animation>,
|
|
||||||
Receiver<Animation>,
|
|
||||||
) = mpsc::channel();
|
|
||||||
let (stop_animation_sender, stop_animation_receiver): (Sender<String>, Receiver<String>) =
|
|
||||||
mpsc::channel();
|
|
||||||
|
|
||||||
let (messager_sender, messager_revicer): (Sender<RenderMessage>, Receiver<RenderMessage>) =
|
let (messager_sender, messager_revicer): (Sender<RenderMessage>, Receiver<RenderMessage>) =
|
||||||
mpsc::channel();
|
mpsc::channel();
|
||||||
@ -196,8 +181,6 @@ async fn main() -> GResult {
|
|||||||
ligth_controll(
|
ligth_controll(
|
||||||
pool_clone,
|
pool_clone,
|
||||||
action_receiver,
|
action_receiver,
|
||||||
start_animation_receiver,
|
|
||||||
stop_animation_receiver,
|
|
||||||
messager_sender,
|
messager_sender,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -227,8 +210,6 @@ async fn main() -> GResult {
|
|||||||
)
|
)
|
||||||
.manage(conn_pool_arc.clone())
|
.manage(conn_pool_arc.clone())
|
||||||
.manage(Arc::new(Mutex::new(action_sender)))
|
.manage(Arc::new(Mutex::new(action_sender)))
|
||||||
.manage(Arc::new(Mutex::new(start_animation_sender)))
|
|
||||||
.manage(Arc::new(Mutex::new(stop_animation_sender)))
|
|
||||||
.manage(Arc::new(Mutex::new(messager_revicer)))
|
.manage(Arc::new(Mutex::new(messager_revicer)))
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user