Skip to content

Commit 4f11398

Browse files
authored
Fix manual update checks not working after being dismissed (element-hq#388)
1 parent 62046fa commit 4f11398

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/updater.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ function installUpdate(): void {
2828

2929
function pollForUpdates(): void {
3030
try {
31-
// If we've already got a new update downloaded, then stop
32-
// trying to check for new ones, as according to the doc
31+
// If we've already got a new update downloaded, then stop trying to check for new ones, as according to the doc
3332
// at https://github.com/electron/electron/blob/main/docs/api/auto-updater.md#autoupdatercheckforupdates
3433
// we'll just keep re-downloading the same update.
35-
// As a hunch, this might also be causing
36-
// https://github.com/vector-im/element-web/issues/12433
37-
// due to the update checks colliding with the pending install
38-
// somehow
34+
// As a hunch, this might also be causing https://github.com/vector-im/element-web/issues/12433
35+
// due to the update checks colliding with the pending install somehow
3936
if (!latestUpdateDownloaded) {
4037
autoUpdater.checkForUpdates();
4138
} else {
4239
console.log("Skipping update check as download already present");
40+
global.mainWindow?.webContents.send('update-downloaded', latestUpdateDownloaded);
4341
}
4442
} catch (e) {
4543
console.log('Couldn\'t check for update', e);
@@ -51,7 +49,7 @@ export function start(updateBaseUrl: string): void {
5149
updateBaseUrl = updateBaseUrl + '/';
5250
}
5351
try {
54-
let url;
52+
let url: string;
5553
// For reasons best known to Squirrel, the way it checks for updates
5654
// is completely different between macOS and windows. On macOS, it
5755
// hits a URL that either gives it a 200 with some json or
@@ -76,7 +74,7 @@ export function start(updateBaseUrl: string): void {
7674

7775
if (url) {
7876
console.log(`Update URL: ${url}`);
79-
autoUpdater.setFeedURL(url);
77+
autoUpdater.setFeedURL({ url });
8078
// We check for updates ourselves rather than using 'updater' because we need to
8179
// do it in the main process (and we don't really need to check every 10 minutes:
8280
// every hour should be just fine for a desktop app)
@@ -97,8 +95,7 @@ ipcMain.on('install_update', installUpdate);
9795
ipcMain.on('check_updates', pollForUpdates);
9896

9997
function ipcChannelSendUpdateStatus(status: boolean | string): void {
100-
if (!global.mainWindow) return;
101-
global.mainWindow.webContents.send('check_updates', status);
98+
global.mainWindow?.webContents.send('check_updates', status);
10299
}
103100

104101
interface ICachedUpdate {
@@ -117,8 +114,7 @@ autoUpdater.on('update-available', function() {
117114
// the only time we will get `update-not-available` if `latestUpdateDownloaded` is already set
118115
// is if the user used the Manual Update check and there is no update newer than the one we
119116
// have downloaded, so show it to them as the latest again.
120-
if (!global.mainWindow) return;
121-
global.mainWindow.webContents.send('update-downloaded', latestUpdateDownloaded);
117+
global.mainWindow?.webContents.send('update-downloaded', latestUpdateDownloaded);
122118
} else {
123119
ipcChannelSendUpdateStatus(false);
124120
}
@@ -127,8 +123,7 @@ autoUpdater.on('update-available', function() {
127123
});
128124

129125
autoUpdater.on('update-downloaded', (ev, releaseNotes, releaseName, releaseDate, updateURL) => {
130-
if (!global.mainWindow) return;
131126
// forward to renderer
132127
latestUpdateDownloaded = { releaseNotes, releaseName, releaseDate, updateURL };
133-
global.mainWindow.webContents.send('update-downloaded', latestUpdateDownloaded);
128+
global.mainWindow?.webContents.send('update-downloaded', latestUpdateDownloaded);
134129
});

0 commit comments

Comments
 (0)