Reload Endpoint Reload Keybind Reload Logic

Remove TU Endpoint
This commit is contained in:
Alex Emmet 2025-12-04 17:35:07 +00:00
commit 7bf90a3699
10 changed files with 385 additions and 201 deletions

View file

@ -1,11 +1,16 @@
use crate::{SHUTDOWN, gui::tui::UNIQUE, util::config_util::CONFIG};
use crate::{ACTIVE_TASKS, RELOAD, SHUTDOWN, gui::tui::UNIQUE, util::config_util::CONFIG};
use crossterm::event::{KeyEvent, KeyModifiers};
use ratatui::crossterm::event::{Event, KeyCode, read};
use tokio::{self};
use tokio_util::sync::WaitForCancellationFutureOwned;
pub fn setup_input_handler() {
tokio::spawn(async move {
{
ACTIVE_TASKS
.lock()
.unwrap()
.push("Input Handler".to_string());
}
while let Ok(event) = read() {
if *SHUTDOWN.read().await {
break;
@ -13,6 +18,15 @@ pub fn setup_input_handler() {
if let Event::Key(key) = event {
handle_input(key).await;
}
if *SHUTDOWN.read().await {
break;
}
}
{
ACTIVE_TASKS
.lock()
.unwrap()
.retain(|t| !t.eq(&"Input Handler".to_string()));
}
});
}
@ -22,6 +36,14 @@ pub async fn handle_input(key: KeyEvent) {
(KeyCode::Char('c'), KeyModifiers::CONTROL) => {
*SHUTDOWN.write().await = true;
}
(KeyCode::Char('r'), KeyModifiers::CONTROL) => {
{
*RELOAD.write().await = true;
}
{
*SHUTDOWN.write().await = true;
}
}
(KeyCode::Backspace, KeyModifiers::NONE) => {
let password: String = {
let cfg = CONFIG.read().await;

View file

@ -1,3 +1,4 @@
use crate::ACTIVE_TASKS;
use crate::APP_STATE;
use crate::SHUTDOWN;
use crate::gui::tui::UNIQUE;
@ -36,6 +37,9 @@ pub fn log_message(msg: impl Into<String>) {
pub fn setup() {
// Start a background thread to sample metrics
tokio::spawn(async move {
{
ACTIVE_TASKS.lock().unwrap().push("metrics".to_string());
}
let mut sys = System::new_with_specifics(RefreshKind::new());
let mut last_total_received = 0u64;
let mut last_total_transmitted = 0u64;
@ -86,5 +90,11 @@ pub fn setup() {
*UNIQUE.write().await = true;
thread::sleep(Duration::from_millis(1000));
}
{
ACTIVE_TASKS
.lock()
.unwrap()
.retain(|t| !t.eq(&"metrics".to_string()));
}
});
}

View file

@ -6,7 +6,7 @@ use std::{
};
use crate::{
APP_STATE, SHUTDOWN,
ACTIVE_TASKS, APP_STATE, SHUTDOWN,
gui::{settings_panel, widgets::betterblock::draw_block_joins},
util::config_util::CONFIG,
};
@ -48,6 +48,10 @@ pub static TERMINAL: Lazy<Arc<Mutex<Terminal<CrosstermBackend<Stdout>>>>> = Lazy
pub fn start_tui() {
tokio::spawn(async move {
init_terminal();
{
ACTIVE_TASKS.lock().unwrap().push("UI".to_string());
}
loop {
if *SHUTDOWN.read().await {
break;
@ -58,6 +62,12 @@ pub fn start_tui() {
thread::sleep(Duration::from_millis(50));
}
}
{
ACTIVE_TASKS
.lock()
.unwrap()
.retain(|t| !t.eq(&"UI".to_string()));
}
});
}
pub async fn render_tui() {