nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 280 forks source link

BrowserWindow.close() and app.close() does nothing when `frame: false` is set #1232

Closed sadtaco closed 3 years ago

sadtaco commented 3 years ago

Describe the bug BrowserWindow.close() and app.close() works fine when frame: true is set, or left to default. ctrl+w closes. alt+f4 closes. However once I set frame: false on BrowserWindow config, none of these work and the only way to close it is through the Task Manager (in Windows), closing the shell/VSCode it's launched from, or by re-running the electron:serve script.

To Reproduce Follow the quick-start guide @ https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/#installation on top of the basic vue3 hello world quickstart. I forget if electron-builder creates the hello world itself or not but it's simply vue create hello-world for that. Replace the boilerplate background.js and App.vue created above with the pastes in https://pastebin.com/VW9JchnM Add the /src/components/App-titlebar.vue and /src/preloader.js from that same paste. Run electron:serve Try and close the window...

If you change frame to true you'll find the close buttons and hotkeys all work fine, however.

Expected behavior Close button and hotkeys should all work to close it.

Environment (please complete the following information):

sadtaco commented 3 years ago

After further digging, the close is only prevented with inspector/devtools open. If I close those first, everything works normally. However, that is not how it works with the non-vue electron quickstart guide. In that case, I can still close with devtools open.

I did also find an almost duplicate https://github.com/electron/electron/issues/25012 except for, as noted above, I'm NOT having the same issue of being unable to alt+f4 or ctrl+w with dev tools open in a basic electron example from their quickstart guide.

The same win.on('close', () => { if (win.webContents.isDevToolsOpened()) { win.webContents.closeDevTools() } }) workaround does work here.