title: Electron.js prevent windows close conditionally
body: <p>I want to ask user if he really want to close an electron app.</p>
  
  <p>Accordingly <a href="https://electronjs.org/docs/api/browser-window#event-close" rel="nofollow noreferrer">to docs</a> - I've tried:</p>
  
  <pre><code>window.onbeforeunload = (e) =&gt; {
    const answer = confirm('Do you want to close the application?');
    e.returnValue = answer;
    if (answer) { window.close(); }
  };
  </code></pre>
  
  <p>But my app still closes no matter what user choose.
  How to prevent close an Electron app conditionally?</p>