Skip to content

Commit

Permalink
fix(auto-updater): skipped updates return now correct update to UI
Browse files Browse the repository at this point in the history
(cherry picked from commit c1daedd)
  • Loading branch information
keraf authored and tsusanka committed Apr 14, 2021
1 parent 95311f1 commit 1baa8ce
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/suite-desktop/src-electron/modules/auto-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ const init = ({ mainWindow, store }: Dependencies) => {
});

autoUpdater.on('update-available', ({ version, releaseDate }) => {
// Reset manual check flag
isManualCheck = false;

const shouldSkip = updateSettings.skipVersion === version;
if (shouldSkip) {
logger.warn('auto-updater', [
'Update is available but was skipped:',
`- Update version: ${version}`,
`- Skip version: ${updateSettings.skipVersion}`,
]);

mainWindow.webContents.send('update/skip', version);
return;
}

Expand All @@ -83,13 +88,13 @@ const init = ({ mainWindow, store }: Dependencies) => {
]);

latestVersion = { version, releaseDate, isManualCheck };
mainWindow.webContents.send(`update/${shouldSkip ? 'skip' : 'available'}`, latestVersion);
mainWindow.webContents.send('update/available', latestVersion);
});

autoUpdater.on('update-not-available', ({ version, releaseDate }) => {
// Reset manual check flag
isManualCheck = false;
});

autoUpdater.on('update-not-available', ({ version, releaseDate }) => {
logger.info('auto-updater', [
'No new update is available:',
`- Last version: ${version}`,
Expand All @@ -99,9 +104,6 @@ const init = ({ mainWindow, store }: Dependencies) => {

latestVersion = { version, releaseDate, isManualCheck };
mainWindow.webContents.send('update/not-available', latestVersion);

// Reset manual check flag
isManualCheck = false;
});

autoUpdater.on('error', err => {
Expand Down Expand Up @@ -138,6 +140,7 @@ const init = ({ mainWindow, store }: Dependencies) => {
logger.info('auto-updater', `Update checking request (manual: ${b2t(isManualCheck)})`);
autoUpdater.checkForUpdates();
});

ipcMain.on('update/download', () => {
logger.info('auto-updater', 'Download requested');
mainWindow.webContents.send('update/downloading', {
Expand All @@ -152,6 +155,7 @@ const init = ({ mainWindow, store }: Dependencies) => {
.then(() => logger.info('auto-updater', 'Update downloaded'))
.catch(() => logger.info('auto-updater', 'Update cancelled'));
});

ipcMain.on('update/install', () => {
logger.info('auto-updater', 'Installation request');

Expand All @@ -162,11 +166,13 @@ const init = ({ mainWindow, store }: Dependencies) => {

autoUpdater.quitAndInstall();
});

ipcMain.on('update/cancel', () => {
logger.info('auto-updater', 'Cancel update request');
mainWindow.webContents.send('update/available', latestVersion);
updateCancellationToken.cancel();
});

ipcMain.on('update/skip', (_, version) => {
logger.info('auto-updater', `Skip version (${version}) request`);
mainWindow.webContents.send('update/skip', version);
Expand Down

0 comments on commit 1baa8ce

Please sign in to comment.