mirror of https://codeberg.org/topola/topola.git
egui: fix saving history files
This commit is contained in:
parent
3a7e504c29
commit
2368feded1
|
|
@ -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,18 +70,24 @@ 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) =
|
||||||
|
arc_mutex_maybe_invoker.clone().lock().unwrap().as_ref()
|
||||||
|
{
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let task = rfd::AsyncFileDialog::new().save_file();
|
let task = rfd::AsyncFileDialog::new().save_file();
|
||||||
|
|
||||||
|
// FIXME: I don't think we should be buffering everything in a `Vec<u8>`.
|
||||||
|
let mut writebuf = vec![];
|
||||||
|
serde_json::to_writer_pretty(&mut writebuf, invoker.history());
|
||||||
|
|
||||||
execute(async move {
|
execute(async move {
|
||||||
if let Some(file_handle) = task.await {
|
if let Some(file_handle) = task.await {
|
||||||
let file_sender = FileSender::new(history_sender);
|
dbg!(file_handle.write(&writebuf).await);
|
||||||
file_sender.send(file_handle).await;
|
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue