Use Promise in "will-download" and block UI


#1

I use Mac OS。I hope to detect the existence of this file in the download directory, if there is no normal download, if there is prompted to re-download and open the directory to choose from.

I use two promises, which are used to detect the existence of this file on the disk, and the prompt exists to allow users to choose to re-download or open.

In the end it did not work, but the main thread’s log is the same as expected. I wrote a simple demo for testing:
https://github.com/lif3ng/electron-download-block-demo

thanks very much :pray:


#2

it looks like you are going to override the default download dialog behabior, isn’t it?

you may need to call event.preventDefault() to not use default behavior.

see in https://github.com/electron/electron/blob/master/docs/api/session.md#event-will-download


#3

I use the dialog to refine the configuration of downloadItem,not override.
Need to use downloadItem setSavePath, cancel……


#4

I got your point now. from your example code, the default save dialog will be show up during the checking file existing due to it does not wait for promise until it is resolved.

from my knowledge, It is the event emiting. I don’t think you can use promise here.

You may need to implement custome dialog.
for ex,