-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tauri) update error handling crate to anyhow+thiserror, close …
…#613 (#621) * Replace error-chain with thiserror in util crate * Replace errorchain with anyhow/thiserror in api * Replace with anyhow/thiserror in updater * Replace with anyhow/thiserror in tauri * Fix error handling on windows
- Loading branch information
Wu Yu Wei
authored
May 29, 2020
1 parent
974cd3d
commit c23675b
Showing
28 changed files
with
255 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
use nfd::{DialogType, open_dialog}; | ||
pub use nfd::Response; | ||
use nfd::{open_dialog, DialogType}; | ||
|
||
fn open_dialog_internal(dialog_type: DialogType, filter: Option<String>, default_path: Option<String>) -> crate::Result<Response> { | ||
open_dialog(filter.as_deref(), default_path.as_deref(), dialog_type) | ||
.map_err(|err| crate::Error::with_chain(err, "open dialog failed")) | ||
.and_then(|response| { | ||
match response { | ||
Response::Cancel => Err(crate::Error::from("user cancelled")), | ||
_ => Ok(response) | ||
} | ||
}) | ||
fn open_dialog_internal( | ||
dialog_type: DialogType, | ||
filter: Option<String>, | ||
default_path: Option<String>, | ||
) -> crate::Result<Response> { | ||
let response = open_dialog(filter.as_deref(), default_path.as_deref(), dialog_type)?; | ||
match response { | ||
Response::Cancel => Err(crate::Error::Dialog("user cancelled".into()).into()), | ||
_ => Ok(response), | ||
} | ||
} | ||
|
||
/// Open single select file dialog | ||
pub fn select(filter_list: Option<String>, default_path: Option<String>) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::SingleFile, filter_list, default_path) | ||
pub fn select( | ||
filter_list: Option<String>, | ||
default_path: Option<String>, | ||
) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::SingleFile, filter_list, default_path) | ||
} | ||
|
||
/// Open mulitple select file dialog | ||
pub fn select_multiple(filter_list: Option<String>, default_path: Option<String>) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::MultipleFiles, filter_list, default_path) | ||
pub fn select_multiple( | ||
filter_list: Option<String>, | ||
default_path: Option<String>, | ||
) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::MultipleFiles, filter_list, default_path) | ||
} | ||
|
||
/// Open save dialog | ||
pub fn save_file(filter_list: Option<String>, default_path: Option<String>) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::SaveFile, filter_list, default_path) | ||
pub fn save_file( | ||
filter_list: Option<String>, | ||
default_path: Option<String>, | ||
) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::SaveFile, filter_list, default_path) | ||
} | ||
|
||
/// Open pick folder dialog | ||
pub fn pick_folder(default_path: Option<String>) -> crate::Result<Response> { | ||
open_dialog_internal(DialogType::PickFolder, None, default_path) | ||
open_dialog_internal(DialogType::PickFolder, None, default_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.