egui: fix saving history files

This commit is contained in:
Mikolaj Wielgus 2024-07-06 15:02:59 +02:00
parent 3a7e504c29
commit 2368feded1
1 changed files with 16 additions and 11 deletions

View File

@ -59,7 +59,6 @@ impl Top {
ui.separator(); ui.separator();
if ui.button("Load history").clicked() { if ui.button("Load history").clicked() {
let invoker_arc_mutex = arc_mutex_maybe_invoker.clone();
let ctx = ui.ctx().clone(); let ctx = ui.ctx().clone();
let task = rfd::AsyncFileDialog::new().pick_file(); let task = rfd::AsyncFileDialog::new().pick_file();
@ -71,17 +70,23 @@ impl Top {
} }
}); });
} else if ui.button("Save history").clicked() { } else if ui.button("Save history").clicked() {
let invoker_arc_mutex = arc_mutex_maybe_invoker.clone(); if let Some(invoker) =
let ctx = ui.ctx().clone(); arc_mutex_maybe_invoker.clone().lock().unwrap().as_ref()
let task = rfd::AsyncFileDialog::new().save_file(); {
let ctx = ui.ctx().clone();
let task = rfd::AsyncFileDialog::new().save_file();
execute(async move { // FIXME: I don't think we should be buffering everything in a `Vec<u8>`.
if let Some(file_handle) = task.await { let mut writebuf = vec![];
let file_sender = FileSender::new(history_sender); serde_json::to_writer_pretty(&mut writebuf, invoker.history());
file_sender.send(file_handle).await;
ctx.request_repaint(); execute(async move {
} if let Some(file_handle) = task.await {
}); dbg!(file_handle.write(&writebuf).await);
ctx.request_repaint();
}
});
}
} }
ui.separator(); ui.separator();