|
1 | 1 | use super::cmd::{OpenDialogOptions, SaveDialogOptions}; |
2 | | -use crate::api::dialog::{pick_folder, save_file, select, select_multiple, Response}; |
| 2 | +use crate::api::dialog::{ |
| 3 | + ask as ask_dialog, message as message_dialog, pick_folder, save_file, select, select_multiple, |
| 4 | + DialogSelection, Response, |
| 5 | +}; |
3 | 6 | use serde_json::Value as JsonValue; |
4 | 7 | use webview_rust_sys::Webview; |
5 | 8 |
|
6 | 9 | /// maps a dialog response to a JS value to eval |
| 10 | +#[cfg(any(open_dialog, save_dialog))] |
7 | 11 | fn map_response(response: Response) -> JsonValue { |
8 | 12 | match response { |
9 | 13 | Response::Okay(path) => path.into(), |
@@ -54,3 +58,28 @@ pub fn save( |
54 | 58 | )?; |
55 | 59 | Ok(()) |
56 | 60 | } |
| 61 | + |
| 62 | +/// Shows a message in a dialog. |
| 63 | +pub fn message(title: String, message: String) { |
| 64 | + message_dialog(message, title); |
| 65 | +} |
| 66 | + |
| 67 | +/// Shows a dialog with a yes/no question. |
| 68 | +pub fn ask( |
| 69 | + webview: &mut Webview, |
| 70 | + title: String, |
| 71 | + message: String, |
| 72 | + callback: String, |
| 73 | + error: String, |
| 74 | +) -> crate::Result<()> { |
| 75 | + crate::execute_promise_sync( |
| 76 | + webview, |
| 77 | + move || match ask_dialog(message, title) { |
| 78 | + DialogSelection::Yes => Ok(true), |
| 79 | + _ => Ok(false), |
| 80 | + }, |
| 81 | + callback, |
| 82 | + error, |
| 83 | + )?; |
| 84 | + Ok(()) |
| 85 | +} |
0 commit comments