Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webContents‘s will-prevent-unload event is helpless for true use #24994

Open
xland opened this issue Aug 17, 2020 · 3 comments
Open

webContents‘s will-prevent-unload event is helpless for true use #24994

xland opened this issue Aug 17, 2020 · 3 comments

Comments

@xland
Copy link
Contributor

@xland xland commented Aug 17, 2020

When developers use webContents‘s will-prevent-unload event,
They want to ask the user to confirm something most of the time.
Like this:

win.webContents.on('will-prevent-unload', event => {
    let choice = dialog.showMessageBoxSync({
      title:'do you want to close',
      buttons:['cancel','yes']
    });
    if(choice === 1)  event.preventDefault();
    //...
  })

Actually,They can not use dialog.showMessageBoxSync,
because dialog.showMessageBoxSync is synchronous,
It will block the main process event loop, and cause some unpredictable problems.

But They can not use the asynchronous method dialog.showMessageBox either,
because dialog.showMessageBox can not prevent the will-prevent-unload event
Code:

  win.webContents.on('will-prevent-unload', async event => {
    let choice = await dialog.showMessageBox({
      title:'do you want to close',
      buttons:['cancel','yes']
    });
    if(choice === 1) event.preventDefault();  //this code is useless
    //...
  })
@zcbenz zcbenz added the bug 🐞 label Aug 19, 2020
@zcbenz
Copy link
Member

@zcbenz zcbenz commented Aug 19, 2020

I agree the API design is wrong. We should provide a callback to pass the result asynchronously.

@SimplyAhmazing
Copy link

@SimplyAhmazing SimplyAhmazing commented Aug 24, 2020

@zcbenz I'm new to contributing to Electron, so I'd like to work on this

@aboutdevz
Copy link

@aboutdevz aboutdevz commented Aug 25, 2020

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.