From 41f5aa8c83696a284e95c783845030f520a1b6f5 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:05:11 -0400 Subject: [PATCH] feat: impl reload file --- src/app.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/app.rs b/src/app.rs index ca1c33f..0c20a95 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,5 @@ use std::{ + fs, path::PathBuf, sync::{Arc, Mutex}, }; @@ -238,6 +239,32 @@ impl LogViewerApp { let ctx = ui.ctx().clone(); self.loading_status = self.initiate_loading(ctx); } + #[cfg(not(target_arch = "wasm32"))] + { + if ui.button("Reload").clicked() { + let mut file_path = None; + if let Some(folder) = self.start_open_path.lock().unwrap().as_ref() { + if let Some(filename) = self.last_filename.lock().unwrap().as_ref() + { + file_path = Some(folder.join(filename)); + } + } + if let Some(path) = file_path { + match fs::read_to_string(path) { + Ok(val) => self.loading_status = LoadingStatus::Success(val), + Err(e) => { + self.loading_status = LoadingStatus::Failed(format!( + "error loading file: {e:?}" + )) + } + } + } else { + self.loading_status = LoadingStatus::Failed( + "unable to determine path to file to load".into(), + ); + } + } + } if ui.button("Clear Data").clicked() { self.data = None; }