refactor: use libcosmic::dialog and make rfd optional

This commit is contained in:
Michael Aaron Murphy 2024-01-22 08:42:18 +01:00
parent 6a74db14ed
commit a1c80efe69
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
3 changed files with 38 additions and 34 deletions

View file

@ -3,7 +3,9 @@
use cosmic::{
app::{message, Command, Core, Settings},
cosmic_config::{self, CosmicConfigEntry},
cosmic_theme, executor,
cosmic_theme,
dialog::file_chooser,
executor,
font::Font,
iced::{
clipboard, event,
@ -1437,17 +1439,15 @@ impl Application for App {
}
},
Message::OpenFileDialog => {
#[cfg(feature = "rfd")]
return Command::perform(
async {
if let Some(handle) = rfd::AsyncFileDialog::new().pick_file().await {
message::app(Message::OpenFile(handle.path().to_owned()))
} else {
message::none()
return cosmic::command::future(async {
if let Ok(response) = file_chooser::open::Dialog::new().open_file().await {
if let Ok(path) = response.url().to_file_path() {
return message::app(Message::OpenFile(path));
}
},
|x| x,
);
}
message::none()
});
}
Message::OpenFile(path) => {
self.open_tab(Some(path));