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

PreventDefault on Close event stops function #80

Closed
peerjollux opened this issue Jan 24, 2019 · 7 comments
Closed

PreventDefault on Close event stops function #80

peerjollux opened this issue Jan 24, 2019 · 7 comments

Comments

@peerjollux
Copy link

When using event.preventDefault() or after touching the event variable within in the Close event, it stops running.

For example:

browserWindow.on("close", function() {
    console.log("This does show up");
    event.preventDefault()
    console.log("This does NOT show up");
})

or:

browserWindow.on("close", function() {
    console.log("This does show up");
    const test = event;
    console.log("This does NOT show up");
})

Any idea how to solve this? Thanks

@robintindale
Copy link
Contributor

is event actually defined? maybe it's just silently crashing

@mathieudutour
Copy link
Member

mathieudutour commented Jan 24, 2019

That's the issue I think yes. Debugging delegate is a bit of a pain because it doesn't show anything.

Maybe we should wrap the handlers in a try/catch by default 🤔 Would there be any unwanted side effects?

@robintindale
Copy link
Contributor

I can't think of any. The classic objection is performance, but I think it barely makes any difference and newer v8 can optimise around it.

@peerjollux
Copy link
Author

is event actually defined? maybe it's just silently crashing

You are right, I didn't set event as param. I've tried to set is as param before and console.log it but this was crashing Sketch. That's why I unset it.

I just found out it was actually sketch-dev-tools that was crashing

@peerjollux
Copy link
Author

I'm using the following code now. Now it does not stop the the function, but it also does not close the window. Any idea why?

  browserWindow.on("close", event => {
    event.preventDefault();
    console.log('this does show up');
  });

@nadavkaner
Copy link

nadavkaner commented Nov 28, 2019

I can't find a way to prevent from the window to close
I tried doing this

browserWindow.on("close", event => {
    event.preventDefault();
  });

But the window is still being closed, I'm trying to override the close button to just hide the window and not close it, is it possible?

@mathieudutour
Copy link
Member

closing in favour of #136

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

No branches or pull requests

4 participants