Skip to content

AutoUpdater

github-actions[bot] edited this page Oct 15, 2025 · 2 revisions

Handle application updates and installation processes.

Overview

The Electron.AutoUpdater API provides comprehensive functionality for handling application updates, including checking for updates, downloading, and installation. It supports multiple update providers and platforms with automatic update capabilities.

Key Methods

Update Checking

CheckForUpdatesAsync()

Returns: UpdateCheckResult with information about available updates.

Description: Asks the server whether there is an update.

CheckForUpdatesAndNotifyAsync()

Returns: UpdateCheckResult with information about available updates.

Description: Asks the server whether there is an update and notifies the user if an update is available.

Update Management

DownloadUpdateAsync()

Returns: Path to downloaded file.

Description: Start downloading update manually. Use this method if AutoDownload option is set to false.

QuitAndInstall(bool, bool)

Parameters:

  • isSilent (optional) - Windows-only: Runs the installer in silent mode. Defaults to false
  • isForceRunAfter - Run the app after finish even on silent install. Not applicable for macOS

Description: Restarts the app and installs the update after it has been downloaded. Should only be called after update-downloaded has been emitted.

Configuration

GetFeedURLAsync()

Returns: Feed URL.

Description: Get the current feed URL.

Properties

AutoDownload

Type: bool

Description: Whether to automatically download an update when it is found. Default is true.

AutoInstallOnAppQuit

Type: bool

Description: Whether to automatically install a downloaded update on app quit. Applicable only on Windows and Linux.

AllowPrerelease

Type: bool

Description: GitHub provider only. Whether to allow update to pre-release versions. Defaults to true if application version contains prerelease components.

FullChangelog

Type: bool

Description: GitHub provider only. Get all release notes (from current version to latest), not just the latest. Default is false.

AllowDowngrade

Type: bool

Description: Whether to allow version downgrade. Default is false.

UpdateConfigPath

Type: string

Description: For test only. Configuration path for updates.

CurrentVersionAsync

Type: Task

Returns: The current application version.

Description: Get the current application version.

ChannelAsync

Type: Task

Returns: The update channel.

Description: Get the update channel. Not applicable for GitHub.

RequestHeadersAsync

Type: Task<Dictionary<string, string>>

Returns: The request headers.

Description: Get the current request headers.

Events

OnError

Description: Emitted when there is an error while updating.

OnCheckingForUpdate

Description: Emitted when checking if an update has started.

OnUpdateAvailable

Description: Emitted when there is an available update. The update is downloaded automatically if AutoDownload is true.

OnUpdateNotAvailable

Description: Emitted when there is no available update.

OnDownloadProgress

Description: Emitted on download progress.

OnUpdateDownloaded

Description: Emitted on download complete.

Usage Examples

Basic Auto-Update Setup

// Configure auto-updater
Electron.AutoUpdater.AutoDownload = true;
Electron.AutoUpdater.AutoInstallOnAppQuit = true;

// Check for updates
var updateCheck = await Electron.AutoUpdater.CheckForUpdatesAsync();
if (updateCheck.UpdateInfo != null)
{
    Console.WriteLine($"Update available: {updateCheck.UpdateInfo.Version}");
}

Manual Update Management

// Disable auto-download for manual control
Electron.AutoUpdater.AutoDownload = false;

// Check for updates
var result = await Electron.AutoUpdater.CheckForUpdatesAsync();
if (result.UpdateInfo != null)
{
    Console.WriteLine($"Update found: {result.UpdateInfo.Version}");

    // Ask user confirmation
    var confirmResult = await Electron.Dialog.ShowMessageBoxAsync(
        "Update Available",
        $"Version {result.UpdateInfo.Version} is available. Download now?");

    if (confirmResult.Response == 1) // Yes
    {
        // Download update manually
        var downloadPath = await Electron.AutoUpdater.DownloadUpdateAsync();
        Console.WriteLine($"Downloaded to: {downloadPath}");

        // Install update
        Electron.AutoUpdater.QuitAndInstall();
    }
}

Update Event Handling

// Handle update events
Electron.AutoUpdater.OnCheckingForUpdate += () =>
{
    Console.WriteLine("Checking for updates...");
};

Electron.AutoUpdater.OnUpdateAvailable += (updateInfo) =>
{
    Console.WriteLine($"Update available: {updateInfo.Version}");
};

Electron.AutoUpdater.OnUpdateNotAvailable += (updateInfo) =>
{
    Console.WriteLine("No updates available");
};

Electron.AutoUpdater.OnDownloadProgress += (progressInfo) =>
{
    Console.WriteLine($"Download progress: {progressInfo.Percent}%");
};

Electron.AutoUpdater.OnUpdateDownloaded += (updateInfo) =>
{
    Console.WriteLine($"Update downloaded: {updateInfo.Version}");

    // Show notification to user
    Electron.Notification.Show(new NotificationOptions
    {
        Title = "Update Downloaded",
        Body = $"Version {updateInfo.Version} is ready to install.",
        Actions = new[]
        {
            new NotificationAction { Text = "Install Now", Type = NotificationActionType.Button },
            new NotificationAction { Text = "Later", Type = NotificationActionType.Button }
        }
    });
};

Electron.AutoUpdater.OnError += (error) =>
{
    Console.WriteLine($"Update error: {error}");
    Electron.Dialog.ShowErrorBox("Update Error", $"Failed to update: {error}");
};

GitHub Provider Configuration

// Configure for GitHub releases
Electron.AutoUpdater.AllowPrerelease = true; // Allow pre-release versions
Electron.AutoUpdater.FullChangelog = true;  // Get full changelog
Electron.AutoUpdater.AllowDowngrade = false; // Prevent downgrades

// Set request headers if needed
Electron.AutoUpdater.RequestHeaders = new Dictionary<string, string>
{
    ["Authorization"] = "token your-github-token",
    ["User-Agent"] = "MyApp-Updater"
};

Update Installation

// Install update immediately
if (updateDownloaded)
{
    Electron.AutoUpdater.QuitAndInstall();
}

// Silent install (Windows only)
Electron.AutoUpdater.QuitAndInstall(isSilent: true, isForceRunAfter: true);

Version Management

// Get current version
var currentVersion = await Electron.AutoUpdater.CurrentVersionAsync;
Console.WriteLine($"Current version: {currentVersion}");

// Get update channel
var channel = await Electron.AutoUpdater.ChannelAsync;
Console.WriteLine($"Update channel: {channel}");

// Set custom feed URL
// Note: This would typically be configured in electron-builder.json
var feedUrl = await Electron.AutoUpdater.GetFeedURLAsync();
Console.WriteLine($"Feed URL: {feedUrl}");

Related APIs

Additional Resources

Clone this wiki locally