-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workaround Squirrel.Mac wedging app restart after failed update check #629
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and | |||||||||
limitations under the License. | ||||||||||
*/ | ||||||||||
|
||||||||||
import { autoUpdater, ipcMain } from "electron"; | ||||||||||
import { app, autoUpdater, ipcMain } from "electron"; | ||||||||||
|
||||||||||
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000; | ||||||||||
const INITIAL_UPDATE_DELAY_MS = 30 * 1000; | ||||||||||
|
@@ -26,15 +26,45 @@ function installUpdate(): void { | |||||||||
autoUpdater.quitAndInstall(); | ||||||||||
} | ||||||||||
|
||||||||||
function pollForUpdates(): void { | ||||||||||
// Workaround for Squirrel.Mac wedging auto-restart if latest check for update failed | ||||||||||
// From https://github.com/vector-im/element-web/issues/12433#issuecomment-1508995119 | ||||||||||
async function safeCheckForUpdate(): Promise<void> { | ||||||||||
if (process.platform === "darwin") { | ||||||||||
const feedUrl = autoUpdater.getFeedURL(); | ||||||||||
// On Mac if the user has already downloaded an update but not installed it and | ||||||||||
// we check again and no additional new update is available the app ends up in a | ||||||||||
// bad state and doesn't restart after installing any updates that are downloaded. | ||||||||||
// To avoid this we check manually whether an update is available and call the | ||||||||||
// autoUpdater.checkForUpdates() when something new is there. | ||||||||||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
try { | ||||||||||
const res = await global.fetch(feedUrl); | ||||||||||
const { currentRelease } = await res.json(); | ||||||||||
const latestVersionDownloaded = latestUpdateDownloaded.releaseName; | ||||||||||
console.info( | ||||||||||
`Latest version from release download: ${currentRelease} (current: ${app.getVersion()}, most recent downloaded ${latestVersionDownloaded}})`, | ||||||||||
); | ||||||||||
if (currentRelease === app.getVersion() || currentRelease === latestVersionDownloaded) { | ||||||||||
ipcChannelSendUpdateStatus(false); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
return; | ||||||||||
} | ||||||||||
} catch (err) { | ||||||||||
console.error(`Error checking for updates ${feedUrl}`, err); | ||||||||||
ipcChannelSendUpdateStatus(false); | ||||||||||
return; | ||||||||||
} | ||||||||||
} | ||||||||||
autoUpdater.checkForUpdates(); | ||||||||||
} | ||||||||||
|
||||||||||
async function pollForUpdates(): Promise<void> { | ||||||||||
try { | ||||||||||
// If we've already got a new update downloaded, then stop trying to check for new ones, as according to the doc | ||||||||||
// at https://github.com/electron/electron/blob/main/docs/api/auto-updater.md#autoupdatercheckforupdates | ||||||||||
// we'll just keep re-downloading the same update. | ||||||||||
// As a hunch, this might also be causing https://github.com/vector-im/element-web/issues/12433 | ||||||||||
// due to the update checks colliding with the pending install somehow | ||||||||||
if (!latestUpdateDownloaded) { | ||||||||||
autoUpdater.checkForUpdates(); | ||||||||||
await safeCheckForUpdate(); | ||||||||||
} else { | ||||||||||
console.log("Skipping update check as download already present"); | ||||||||||
global.mainWindow?.webContents.send("update-downloaded", latestUpdateDownloaded); | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long sentence is long. Punctuation ftw.