From 0551ce44f2911743175046de944da858904929ca Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Wed, 16 Jun 2021 04:36:15 +0100 Subject: [PATCH] Main+Renderer: Enforce synchronous messages on `setBounds` channel This should fix an issue where, when closing the app, an error window would very occasionally pop up declaring that 'getNormalBounds' was called on an undefined variable. --- src/main/index.js | 29 +++++++---------------------- src/renderer/App.js | 4 ++-- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 910d205c3..046756748 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -294,33 +294,18 @@ function runApp() { } // Save closing window bounds & maximized status - ipcMain.on('setBounds', (_e, data) => { + ipcMain.on('setBounds', (event) => { const value = { ...mainWindow.getNormalBounds(), maximized: mainWindow.isMaximized() } - settingsDb.findOne({ - _id: 'bounds' - }, function (err, doc) { - if (err) { - return - } - if (doc !== null) { - settingsDb.update({ - _id: 'bounds' - }, { - $set: { - value - } - }, {}) - } else { - settingsDb.insert({ - _id: 'bounds', - value - }) - } - }) + settingsDb.update( + { _id: 'bounds' }, + { _id: 'bounds', value }, + { upsert: true }, + () => { event.returnValue = 0 } + ) }) ipcMain.on('appReady', () => { diff --git a/src/renderer/App.js b/src/renderer/App.js index fed5bf3a6..1880c59d9 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -403,8 +403,8 @@ export default Vue.extend({ }, setBoundsOnClose: function () { - window.onbeforeunload = (e) => { - ipcRenderer.send('setBounds') + window.onbeforeunload = () => { + ipcRenderer.sendSync('setBounds') } },