-
Notifications
You must be signed in to change notification settings - Fork 0
AutoUpdater
Handle application updates and installation processes.
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.
Returns: UpdateCheckResult with information about available updates.
Description: Asks the server whether there is an update.
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.
Returns: Path to downloaded file.
Description: Start downloading update manually. Use this method if AutoDownload option is set to false.
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.
Returns: Feed URL.
Description: Get the current feed URL.
Type: bool
Description: Whether to automatically download an update when it is found. Default is true.
Type: bool
Description: Whether to automatically install a downloaded update on app quit. Applicable only on Windows and Linux.
Type: bool
Description: GitHub provider only. Whether to allow update to pre-release versions. Defaults to true if application version contains prerelease components.
Type: bool
Description: GitHub provider only. Get all release notes (from current version to latest), not just the latest. Default is false.
Type: bool
Description: Whether to allow version downgrade. Default is false.
Type: string
Description: For test only. Configuration path for updates.
Type: Task
Returns: The current application version.
Description: Get the current application version.
Type: Task
Returns: The update channel.
Description: Get the update channel. Not applicable for GitHub.
Type: Task<Dictionary<string, string>>
Returns: The request headers.
Description: Get the current request headers.
Description: Emitted when there is an error while updating.
Description: Emitted when checking if an update has started.
Description: Emitted when there is an available update. The update is downloaded automatically if AutoDownload is true.
Description: Emitted when there is no available update.
Description: Emitted on download progress.
Description: Emitted on download complete.
// 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}");
}// 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();
}
}// 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}");
};// 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"
};// Install update immediately
if (updateDownloaded)
{
Electron.AutoUpdater.QuitAndInstall();
}
// Silent install (Windows only)
Electron.AutoUpdater.QuitAndInstall(isSilent: true, isForceRunAfter: true);// 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}");- Electron.App - Application lifecycle events during updates
- Electron.Notification - Notify users about update status
- Electron.Dialog - Show update confirmation dialogs
- Electron AutoUpdater Documentation - Official Electron auto-updater API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.