|
@@ -1,9 +1,13 @@
|
|
|
use super::cmd::{OpenDialogOptions, SaveDialogOptions};
|
|
|
-use crate::api::dialog::{pick_folder, save_file, select, select_multiple, Response};
|
|
|
+use crate::api::dialog::{
|
|
|
+ ask as ask_dialog, message as message_dialog, pick_folder, save_file, select, select_multiple,
|
|
|
+ DialogSelection, Response,
|
|
|
+};
|
|
|
use serde_json::Value as JsonValue;
|
|
|
use webview_rust_sys::Webview;
|
|
|
|
|
|
/// maps a dialog response to a JS value to eval
|
|
|
+#[cfg(any(open_dialog, save_dialog))]
|
|
|
fn map_response(response: Response) -> JsonValue {
|
|
|
match response {
|
|
|
Response::Okay(path) => path.into(),
|
|
@@ -54,3 +58,28 @@ pub fn save(
|
|
|
)?;
|
|
|
Ok(())
|
|
|
}
|
|
|
+
|
|
|
+/// Shows a message in a dialog.
|
|
|
+pub fn message(title: String, message: String) {
|
|
|
+ message_dialog(message, title);
|
|
|
+}
|
|
|
+
|
|
|
+/// Shows a dialog with a yes/no question.
|
|
|
+pub fn ask(
|
|
|
+ webview: &mut Webview,
|
|
|
+ title: String,
|
|
|
+ message: String,
|
|
|
+ callback: String,
|
|
|
+ error: String,
|
|
|
+) -> crate::Result<()> {
|
|
|
+ crate::execute_promise_sync(
|
|
|
+ webview,
|
|
|
+ move || match ask_dialog(message, title) {
|
|
|
+ DialogSelection::Yes => Ok(true),
|
|
|
+ _ => Ok(false),
|
|
|
+ },
|
|
|
+ callback,
|
|
|
+ error,
|
|
|
+ )?;
|
|
|
+ Ok(())
|
|
|
+}
|