Skip to content

Commit 3071fc5

Browse files
authored
Handle dialog reject (Cancel) on wasm (#266)
1 parent 9435444 commit 3071fc5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/backend/wasm.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a> WasmDialog<'a> {
188188
name,
189189
data,
190190
} => {
191-
js_sys::Promise::new(&mut |res, _rej| {
191+
js_sys::Promise::new(&mut |res, rej| {
192192
// Moved to keep closure as FnMut
193193
let output = element.clone();
194194
let file_name = name.clone();
@@ -198,10 +198,18 @@ impl<'a> WasmDialog<'a> {
198198
.unwrap();
199199
}) as Box<dyn FnMut()>);
200200

201+
let reject_promise = Closure::wrap(Box::new(move || {
202+
rej.call1(&JsValue::undefined(), &JsValue::from(true))
203+
.unwrap();
204+
}) as Box<dyn FnMut()>);
205+
201206
// Resolve the promise once the user clicks the download link or the button.
202207
output.set_onclick(Some(resolve_promise.as_ref().unchecked_ref()));
203208
ok_button.set_onclick(Some(resolve_promise.as_ref().unchecked_ref()));
209+
cancel_button.set_onclick(Some(reject_promise.as_ref().unchecked_ref()));
210+
204211
resolve_promise.forget();
212+
reject_promise.forget();
205213

206214
let set_download_link = move |in_array: &[u8], name: &str| {
207215
// See <https://stackoverflow.com/questions/69556755/web-sysurlcreate-object-url-with-blobblob-not-formatting-binary-data-co>

0 commit comments

Comments
 (0)