added clear toggle
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andre Henriques 2023-08-19 14:46:34 +01:00
parent 41210d756c
commit 856ab2853e
2 changed files with 62 additions and 0 deletions

View File

@ -674,3 +674,64 @@ pub async fn toggle_animation(
return get_error_message("Failed to get list"); return get_error_message("Failed to get list");
} }
/**
*
* Start animations
*
*/
#[get("/cleartoggle/<name>")]
pub async fn cleartoggle_animation(
name: &str,
action: &State<ASender<Action>>,
messages: &State<AReceiver<RenderMessage>>,
db: &State<DBPool>,
) -> String {
let r = action.lock().unwrap().send(Action::Clear);
if r.is_err() || r.ok().is_none() {
return get_error_message("Something went wrong");
}
let animation = get_animation_or_string_error(name, db);
if let Err(error) = animation {
return error;
}
let animation = animation.unwrap();
let action = action.lock().unwrap();
let send = action.send(Action::GetActiveList);
if send.is_err() || send.ok().is_none() {
return get_error_message("Failed to get list");
}
let data = messages.lock().unwrap().recv();
if data.is_err() || data.as_ref().ok().is_none() {
return get_error_message("Failed to get list");
}
if let RenderMessage::ActiveList(list) = data.ok().unwrap() {
if list.contains(&name.to_string()) {
// Disable
let r = action.send(Action::Stop(name.to_string()));
if r.is_err() || r.ok().is_none() {
return get_error_message("Something went wrong");
}
return create_message(200, "Configuration was successful");
} else {
// Enable
let r = action.send(Action::Start(animation));
if r.is_err() || r.as_ref().ok().is_none() {
return get_error_message("Probelms with the sender");
}
return create_message(200, "Started animation");
}
}
return get_error_message("Failed to get list");
}

View File

@ -232,6 +232,7 @@ async fn main() -> GResult {
animations::clear_all, animations::clear_all,
animations::get_animation_request, animations::get_animation_request,
animations::toggle_animation, animations::toggle_animation,
animations::cleartoggle_animation,
animations::get_animations, animations::get_animations,
animations::get_animation_by_name, animations::get_animation_by_name,
], ],