Work on log viewer

This commit is contained in:
Michael Mikovsky
2025-12-13 13:29:17 -07:00
parent 75f1fe1cc2
commit 7525b9a213
10 changed files with 274 additions and 5 deletions
+5 -1
View File
@@ -5,7 +5,7 @@ use std::collections::HashSet;
use crate::{
app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart,
payload_config::PayloadConfig,
log_viewer::LogViewer, payload_config::PayloadConfig,
};
pub use app::TemplateApp;
use egui_tiles::{TileId, Tree};
@@ -19,6 +19,7 @@ pub struct AppState {
pub flowchart: FlowChart,
pub config: Config,
pub payload_config: PayloadConfig,
pub log_viewer: LogViewer,
}
impl AppState {
@@ -27,6 +28,7 @@ impl AppState {
(AppWindow::Flowchart, "Flowchart"),
(AppWindow::PayloadConfig, "Payload Config"),
(AppWindow::Config, "Config"),
(AppWindow::LogViewer, "Log Viewer"),
])
.iter()
.enumerate()
@@ -100,6 +102,7 @@ pub enum AppWindow {
Flowchart,
Config,
PayloadConfig,
LogViewer,
}
impl AppWindow {
@@ -108,6 +111,7 @@ impl AppWindow {
AppWindow::Flowchart => state.flowchart.paint(ui),
AppWindow::Config => state.config.update(&mut state.auth, ui),
AppWindow::PayloadConfig => state.payload_config.update(ui),
AppWindow::LogViewer => state.log_viewer.update(&mut state.auth, ui),
}
}
-1
View File
@@ -162,7 +162,6 @@ impl Auth {
format!("Bearer {}", token.token),
Closure::once_into_js(move |ok: bool, response: String| {
if ok {
crate::log(&response);
if let Ok(value) = serde_json::from_str::<T>(&response) {
ret(value)
} else {
+1
View File
@@ -7,6 +7,7 @@ pub mod app;
mod auth;
mod config;
mod flowchart;
mod log_viewer;
mod payload_config;
use std::time::Duration;
+43
View File
@@ -0,0 +1,43 @@
use crate::auth::Auth;
use std::sync::Arc;
use std::sync::Mutex;
#[derive(serde::Deserialize, serde::Serialize)]
pub struct LogViewer {
#[serde(skip)]
state: Arc<Mutex<LogState>>,
}
#[derive(Default)]
struct LogState {
logs: Vec<String>,
// trees: Option<Vec<String>>,
// tree_keys: Option<HashMap<String, String>>,
// is_requesting: bool,
}
impl LogViewer {
pub fn update(&mut self, auth: &mut Auth, ui: &mut egui::Ui) {
ui.heading("Log Viewer");
for log in &self.state.lock().unwrap().logs {
ui.label(log);
}
if ui.button("Poll").clicked() {
let state_clone = self.state.clone();
auth.get(&format!("/api/log/{}", 0), move |e: Vec<String>| {
(*state_clone.lock().unwrap()).logs = e;
// crate::log(&format!("{e:?}"));
});
}
}
}
impl Default for LogViewer {
fn default() -> Self {
Self {
// logs: Vec::new(),
state: Arc::new(Mutex::new(LogState::default())),
}
}
}