Skip to content

Commit

Permalink
Fix autoUpdater Memory Leak (#2608)
Browse files Browse the repository at this point in the history
* divide listener setup and update check

* update changelog
  • Loading branch information
adrastaea authored Oct 10, 2024
1 parent 5bdee6b commit 2f1f448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [unreleased]

### Fixes

* Fixed memory leak associated with autoUpdater ([#2606](https://github.com/TryQuiet/quiet/issues/2606))

## [2.3.1]

### Fixes
Expand Down
22 changes: 12 additions & 10 deletions packages/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,19 @@ const isNetworkError = (errorObject: { message: string }) => {
)
}

export const checkForUpdate = async (win: BrowserWindow) => {
export const checkForUpdate = async () => {
try {
await autoUpdater.checkForUpdates()
} catch (error) {
if (isNetworkError(error)) {
logger.error('Network Error')
logger.warn(`updater: ${error.message}`)
} else {
logger.error('Unknown Error')
logger.error(error == null ? 'unknown' : (error.stack || error).toString())
logger.error(error)
}
}
}

const setupUpdater = async () => {
autoUpdater.on('checking-for-update', () => {
logger.info('updater: checking-for-update')
})
Expand All @@ -285,7 +287,9 @@ export const checkForUpdate = async (win: BrowserWindow) => {
})
autoUpdater.on('update-downloaded', () => {
logger.info('updater: update-downloaded')
win.webContents.send('newUpdateAvailable')
if (isBrowserWindow(mainWindow)) {
mainWindow.webContents.send('newUpdateAvailable')
}
})
autoUpdater.on('before-quit-for-update', () => {
logger.info('updater: before-quit-for-update')
Expand Down Expand Up @@ -505,12 +509,10 @@ app.on('ready', async () => {
}
}

await checkForUpdate(mainWindow)
await setupUpdater()
await checkForUpdate()
setInterval(async () => {
if (!isBrowserWindow(mainWindow)) {
throw new Error(`mainWindow is on unexpected type ${mainWindow}`)
}
await checkForUpdate(mainWindow)
await checkForUpdate()
}, updaterInterval)
})

Expand Down

0 comments on commit 2f1f448

Please sign in to comment.