File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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>
You can’t perform that action at this time.
0 commit comments