Skip to content

Commit

Permalink
Use rfd directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Mar 22, 2023
1 parent d2bd00c commit 71fbe4f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bins/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bins/ayaka-gui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ayaka-model = { workspace = true }
flexi_logger = { workspace = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha.4", features = ["cli", "dialog-open", "window-all"] }
tauri = { version = "2.0.0-alpha.4", features = ["cli", "window-all"] }
rfd = { version = "0.11", features = ["gtk3", "common-controls-v6"] }
axum = { version = "0.6", default-features = false, features = [
"http1",
"tokio",
Expand Down
13 changes: 9 additions & 4 deletions bins/ayaka-gui/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,27 @@ fn dist_port(storage: State<Storage>) -> u16 {
}

#[cfg(desktop)]
fn show_pick_files() -> Vec<PathBuf> {
tauri::api::dialog::blocking::FileDialogBuilder::new()
async fn show_pick_files(handle: &AppHandle) -> Vec<PathBuf> {
rfd::AsyncFileDialog::new()
.add_filter("Ayaka package", &["ayapack"])
.set_parent(&handle.get_window("main").expect("cannot get main window"))
.pick_files()
.await
.unwrap_or_default()
.into_iter()
.map(|handle| handle.path().to_path_buf())
.collect()
}

#[cfg(mobile)]
fn show_pick_files() -> Vec<PathBuf> {
async fn show_pick_files(_handle: &AppHandle) -> Vec<PathBuf> {
vec![]
}

#[command]
async fn open_game(handle: AppHandle, storage: State<'_, Storage>) -> CommandResult<()> {
let config = if storage.config.is_empty() {
Cow::Owned(show_pick_files())
Cow::Owned(show_pick_files(&handle).await)
} else {
Cow::Borrowed(&storage.config)
};
Expand Down
4 changes: 0 additions & 4 deletions bins/ayaka-gui/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
"all": false,
"window": {
"all": true
},
"dialog": {
"all": false,
"open": true
}
},
"bundle": {
Expand Down

0 comments on commit 71fbe4f

Please sign in to comment.