Skip to content

Commit

Permalink
desktop: Use async dialogs when saving files
Browse files Browse the repository at this point in the history
Since we're using tokio we can easily migrate save dialogs to async
ones, that do not require another thread to be handled.
  • Loading branch information
kjarosh authored and evilpie committed Jan 5, 2025
1 parent d5f06ac commit f101687
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions desktop/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use egui::*;
use fluent_templates::fluent_bundle::FluentValue;
use fluent_templates::{static_loader, Loader};
use menu_bar::MenuBar;
use rfd::FileDialog;
use rfd::AsyncFileDialog;
use ruffle_core::debug_ui::Message as DebugMessage;
use ruffle_core::{Player, PlayerEvent};
use std::collections::HashMap;
Expand Down Expand Up @@ -170,19 +170,23 @@ impl RuffleGui {
}
}
for item in player.debug_ui().items_to_save() {
std::thread::spawn(move || {
if let Some(path) = FileDialog::new()
.set_file_name(&item.suggested_name)
.save_file()
{
if let Err(e) = fs::write(&path, item.data) {
let dialog = AsyncFileDialog::new().set_file_name(&item.suggested_name);
let picker = self.dialogs.file_picker();
let result = picker.show_dialog(dialog, |d| d.save_file());
if let Some(result) = result {
tokio::spawn(async move {
let Some(handle) = result.await else {
return;
};
let path = handle.path();
if let Err(e) = fs::write(path, item.data) {
tracing::error!(
"Couldn't save {} to {path:?}: {e}",
item.suggested_name,
);
}
}
});
});
}
}

if let Some(context_menu) = &mut self.context_menu {
Expand Down

0 comments on commit f101687

Please sign in to comment.