Use async file picker API
This commit is contained in:
+10
-11
@@ -1,12 +1,12 @@
|
||||
use std::{fs, sync::Arc, time::Duration};
|
||||
use std::{fs, time::Duration};
|
||||
|
||||
use anyhow::Result;
|
||||
use egui::{Button, CentralPanel, Checkbox, Label, ViewportBuilder};
|
||||
use egui_notify::{Anchor, Toast, Toasts};
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId},
|
||||
filepicker::FilePicker,
|
||||
profiler::{Profiler, ProfilerStatus},
|
||||
window::{AppWindow, InitArgs},
|
||||
};
|
||||
@@ -16,7 +16,7 @@ pub struct ProfileWindow {
|
||||
client: EmulatorClient,
|
||||
profiler: Profiler,
|
||||
toasts: Toasts,
|
||||
window: Option<Arc<Window>>,
|
||||
file_picker: FilePicker,
|
||||
}
|
||||
|
||||
impl ProfileWindow {
|
||||
@@ -29,7 +29,7 @@ impl ProfileWindow {
|
||||
.with_anchor(Anchor::BottomLeft)
|
||||
.with_margin((10.0, 10.0).into())
|
||||
.reverse(true),
|
||||
window: None,
|
||||
file_picker: FilePicker::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,12 @@ impl ProfileWindow {
|
||||
|
||||
fn try_finish_recording(&mut self) -> Result<Option<String>> {
|
||||
let bytes_receiver = self.profiler.finish_recording();
|
||||
let mut file_dialog = rfd::FileDialog::new()
|
||||
let file = self
|
||||
.file_picker
|
||||
.new_dialog()
|
||||
.add_filter("Profiler files", &["json"])
|
||||
.set_file_name("profile.json");
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
file_dialog = file_dialog.set_parent(window);
|
||||
}
|
||||
let file = file_dialog.save_file();
|
||||
.set_file_name("profile.json")
|
||||
.save_file();
|
||||
if let Some(path) = file {
|
||||
let bytes = pollster::block_on(bytes_receiver)?;
|
||||
let _ = fs::remove_file(&path);
|
||||
@@ -164,6 +163,6 @@ impl AppWindow for ProfileWindow {
|
||||
}
|
||||
|
||||
fn on_init(&mut self, args: InitArgs) {
|
||||
self.window = Some(args.window.clone());
|
||||
self.file_picker.set_window(args.window);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user