fix(updater): defer autoUpdater init to after app.whenReady()#1078
Open
Ghostmonday wants to merge 1 commit into
Open
fix(updater): defer autoUpdater init to after app.whenReady()#1078Ghostmonday wants to merge 1 commit into
Ghostmonday wants to merge 1 commit into
Conversation
electron-updater's autoUpdater is a lazy getter — accessing any property (.autoDownload, .logger, .on(), etc.) triggers AppImageUpdater instantiation which calls app.getVersion() via ElectronAppAdapter. In dev/unpackaged mode, app.getVersion() returns undefined before app.whenReady(), crashing the app at module import time. Changes: - updater.ts: move ALL autoUpdater configuration from constructor into new init() method (autoDownload, autoInstallOnAppQuit, logger, event listeners, feed URL setup). Constructor only sets up EventEmitter error handler. - index.ts: call appUpdater.init() inside initialize() (which runs after app.whenReady()), right before registerUpdateHandlers(). init() guards against double-initialization via the 'initialized' flag.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
In dev mode (unpackaged Electron),
electron-updater'sautoUpdaterlazy getter crashes at module import time because it callsapp.getVersion()viaElectronAppAdapterbeforeapp.whenReady(). SinceAppUpdaterwas instantiated as a module-level singleton (export const appUpdater = new AppUpdater()), the crash happened during module initialization, preventing the app from starting in dev mode.Root Cause
The
autoUpdaterexport fromelectron-updateris a lazy getter. Accessing any property on it triggers platform-specific updater instantiation (e.g., AppImageUpdater on Linux), which callsapp.getVersion(). Beforeapp.whenReady(),app.getVersion()returnsundefined, causing a crash.The constructor was setting
autoUpdater.autoDownload,autoUpdater.autoInstallOnAppQuit,autoUpdater.logger,autoUpdater.channel, and callingautoUpdater.setFeedURL()— all of which accessed the lazy getter beforeapp.whenReady().Fix
autoUpdaterproperty access and configuration from the constructor into a newinit()method with aninitializedguard.init()is called inelectron/main/index.tsafterapp.whenReady()completes.Changes
electron/main/updater.tsautoUpdateraccess from constructor; newinit()method with initialized guardelectron/main/index.tsappUpdater.init()call beforeregisterUpdateHandlers