Skip to content

Commit

Permalink
Fix problem of prevent window close will prevented app.quit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Sep 26, 2017
1 parent c696a11 commit a2469af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ app.on('window-all-closed', () => {
}
});

app.on('before-quit', async event => {
event.preventDefault();
for (const win of BrowserWindow.getAllWindows()) {
win.removeAllListeners('close');
await win.close();
}
process.exit();
});

app.on('ready', async () => {
await installExtensions();

Expand Down
12 changes: 7 additions & 5 deletions electron/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ export const createWindow = ({ iconPath, isPortSettingRequired }) => {
removeUnecessaryTabs(win);
});
win.on('focus', () => onFocus(win));
win.on('close', event => {
event.preventDefault();
win.close = async () => {
store.set('winBounds', win.getBounds());
win.webContents.getZoomLevel(level => store.set('zoomLevel', level));
executeJavaScript(win, 'window.beforeWindowClose()').then(() => {
win.destroy();
});
await executeJavaScript(win, 'window.beforeWindowClose && window.beforeWindowClose()');
win.destroy();
};
win.on('close', event => {
event.preventDefault();
win.close();
});
// Try to fix https://github.com/jhen0409/react-native-debugger/issues/81
// but really not sure because the method works fine on most machines
Expand Down

0 comments on commit a2469af

Please sign in to comment.