Skip to content

fix(updater): defer autoUpdater init to after app.whenReady()#1078

Open
Ghostmonday wants to merge 1 commit into
ValueCell-ai:mainfrom
Ghostmonday:fix/updater-defer-init
Open

fix(updater): defer autoUpdater init to after app.whenReady()#1078
Ghostmonday wants to merge 1 commit into
ValueCell-ai:mainfrom
Ghostmonday:fix/updater-defer-init

Conversation

@Ghostmonday

Copy link
Copy Markdown

Problem

In dev mode (unpackaged Electron), electron-updater's autoUpdater lazy getter crashes at module import time because it calls app.getVersion() via ElectronAppAdapter before app.whenReady(). Since AppUpdater was 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 autoUpdater export from electron-updater is a lazy getter. Accessing any property on it triggers platform-specific updater instantiation (e.g., AppImageUpdater on Linux), which calls app.getVersion(). Before app.whenReady(), app.getVersion() returns undefined, causing a crash.

The constructor was setting autoUpdater.autoDownload, autoUpdater.autoInstallOnAppQuit, autoUpdater.logger, autoUpdater.channel, and calling autoUpdater.setFeedURL() — all of which accessed the lazy getter before app.whenReady().

Fix

  • Moved all autoUpdater property access and configuration from the constructor into a new init() method with an initialized guard.
  • init() is called in electron/main/index.ts after app.whenReady() completes.

Changes

File Change
electron/main/updater.ts Stripped all autoUpdater access from constructor; new init() method with initialized guard
electron/main/index.ts Added appUpdater.init() call before registerUpdateHandlers

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant