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.
This commit is contained in:
Svallinn 2021-06-16 04:36:15 +01:00
parent 65df233e8a
commit 0551ce44f2
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
2 changed files with 9 additions and 24 deletions

View File

@ -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', () => {

View File

@ -403,8 +403,8 @@ export default Vue.extend({
},
setBoundsOnClose: function () {
window.onbeforeunload = (e) => {
ipcRenderer.send('setBounds')
window.onbeforeunload = () => {
ipcRenderer.sendSync('setBounds')
}
},