mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Work on log viewer
This commit is contained in:
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -7,6 +7,7 @@ pub mod app;
|
||||
mod auth;
|
||||
mod config;
|
||||
mod flowchart;
|
||||
mod log_viewer;
|
||||
mod payload_config;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user