Skip to content

Commit

Permalink
feat: impl reload file
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jun 2, 2024
1 parent 4260df8 commit 41f5aa8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
fs,
path::PathBuf,
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 41f5aa8

Please sign in to comment.