From 2ce31100413d13bc4755765a9cddcf642fe6fe39 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Sat, 3 Jul 2021 03:43:49 +0100 Subject: [PATCH] Main: Move window bounds persistence logic over to the main process --- src/main/index.js | 33 +++++++++++++++++---------------- src/renderer/App.js | 7 ------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index fa59908a..38381e95 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -252,6 +252,23 @@ function runApp() { newWindow.focus() }) + newWindow.once('close', async () => { + if (BrowserWindow.getAllWindows().length !== 1) { + return + } + + const value = { + ...newWindow.getNormalBounds(), + maximized: newWindow.isMaximized() + } + + await settingsDb.update( + { _id: 'bounds' }, + { _id: 'bounds', value }, + { upsert: true } + ) + }) + newWindow.once('closed', () => { const allWindows = BrowserWindow.getAllWindows() if (allWindows.length !== 0 && newWindow === mainWindow) { @@ -264,22 +281,6 @@ function runApp() { }) } - // Save closing window bounds & maximized status - ipcMain.on('setBounds', async (event) => { - const value = { - ...mainWindow.getNormalBounds(), - maximized: mainWindow.isMaximized() - } - - await settingsDb.update( - { _id: 'bounds' }, - { _id: 'bounds', value }, - { upsert: true } - ) - - event.returnValue = 0 - }) - ipcMain.on('appReady', () => { if (startupUrl) { mainWindow.webContents.send('openUrl', startupUrl) diff --git a/src/renderer/App.js b/src/renderer/App.js index e44fdace..563e5d16 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -103,7 +103,6 @@ export default Vue.extend({ this.activateKeyboardShortcuts() this.openAllLinksExternally() this.enableOpenUrl() - this.setBoundsOnClose() await this.checkExternalPlayer() } @@ -380,12 +379,6 @@ export default Vue.extend({ ipcRenderer.send('appReady') }, - setBoundsOnClose: function () { - window.onbeforeunload = () => { - ipcRenderer.sendSync('setBounds') - } - }, - ...mapMutations([ 'setInvidiousInstancesList' ]),