Skip to content

Commit 56258d1

Browse files
committed
Add API documentation (AI generated)
1 parent 88766ad commit 56258d1

19 files changed

+3753
-1
lines changed

docs/API/App.md

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

docs/API/AutoUpdater.md

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# Electron.AutoUpdater
2+
3+
Handle application updates and installation processes.
4+
5+
## Overview
6+
7+
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.
8+
9+
## Properties
10+
11+
#### 📋 `bool AllowDowngrade`
12+
Whether to allow version downgrade. Default is false.
13+
14+
#### 📋 `bool AllowPrerelease`
15+
GitHub provider only. Whether to allow update to pre-release versions. Defaults to true if application version contains prerelease components.
16+
17+
#### 📋 `bool AutoDownload`
18+
Whether to automatically download an update when it is found. Default is true.
19+
20+
#### 📋 `bool AutoInstallOnAppQuit`
21+
Whether to automatically install a downloaded update on app quit. Applicable only on Windows and Linux.
22+
23+
#### 📋 `string Channel`
24+
Get the update channel. Not applicable for GitHub. Doesn't return channel from the update configuration, only if was previously set.
25+
26+
#### 📋 `Task<string> ChannelAsync`
27+
Get the update channel. Not applicable for GitHub. Doesn't return channel from the update configuration, only if was previously set.
28+
29+
#### 📋 `Task<SemVer> CurrentVersionAsync`
30+
Get the current application version.
31+
32+
#### 📋 `bool FullChangelog`
33+
GitHub provider only. Get all release notes (from current version to latest), not just the latest. Default is false.
34+
35+
#### 📋 `Dictionary<string, string> RequestHeaders`
36+
The request headers.
37+
38+
#### 📋 `Task<Dictionary<string, string>> RequestHeadersAsync`
39+
Get the current request headers.
40+
41+
#### 📋 `string UpdateConfigPath`
42+
For test only. Configuration path for updates.
43+
44+
## Methods
45+
46+
#### 🧊 `Task<UpdateCheckResult> CheckForUpdatesAndNotifyAsync()`
47+
Asks the server whether there is an update and notifies the user if an update is available.
48+
49+
#### 🧊 `Task<UpdateCheckResult> CheckForUpdatesAsync()`
50+
Asks the server whether there is an update.
51+
52+
#### 🧊 `Task<string> DownloadUpdateAsync()`
53+
Start downloading update manually. Use this method if AutoDownload option is set to false.
54+
55+
**Returns:**
56+
57+
Path to downloaded file.
58+
59+
#### 🧊 `Task<string> GetFeedURLAsync()`
60+
Get the current feed URL.
61+
62+
**Returns:**
63+
64+
Feed URL.
65+
66+
#### 🧊 `void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)`
67+
Restarts the app and installs the update after it has been downloaded. Should only be called after update-downloaded has been emitted.
68+
69+
Note: QuitAndInstall() will close all application windows first and only emit before-quit event on app after that. This is different from the normal quit event sequence.
70+
71+
**Parameters:**
72+
- `isSilent` - Windows-only: Runs the installer in silent mode. Defaults to false
73+
- `isForceRunAfter` - Run the app after finish even on silent install. Not applicable for macOS
74+
75+
## Events
76+
77+
#### `OnCheckingForUpdate`
78+
Emitted when checking if an update has started.
79+
80+
#### `OnDownloadProgress`
81+
Emitted on download progress.
82+
83+
#### `OnError`
84+
Emitted when there is an error while updating.
85+
86+
#### `OnUpdateAvailable`
87+
Emitted when there is an available update. The update is downloaded automatically if AutoDownload is true.
88+
89+
#### `OnUpdateDownloaded`
90+
Emitted on download complete.
91+
92+
#### `OnUpdateNotAvailable`
93+
Emitted when there is no available update.
94+
95+
## Usage Examples
96+
97+
### Basic Auto-Update Setup
98+
99+
```csharp
100+
// Configure auto-updater
101+
Electron.AutoUpdater.AutoDownload = true;
102+
Electron.AutoUpdater.AutoInstallOnAppQuit = true;
103+
104+
// Check for updates
105+
var updateCheck = await Electron.AutoUpdater.CheckForUpdatesAsync();
106+
if (updateCheck.UpdateInfo != null)
107+
{
108+
Console.WriteLine($"Update available: {updateCheck.UpdateInfo.Version}");
109+
}
110+
```
111+
112+
### Manual Update Management
113+
114+
```csharp
115+
// Disable auto-download for manual control
116+
Electron.AutoUpdater.AutoDownload = false;
117+
118+
// Check for updates
119+
var result = await Electron.AutoUpdater.CheckForUpdatesAsync();
120+
if (result.UpdateInfo != null)
121+
{
122+
Console.WriteLine($"Update found: {result.UpdateInfo.Version}");
123+
124+
// Ask user confirmation
125+
var confirmResult = await Electron.Dialog.ShowMessageBoxAsync(
126+
"Update Available",
127+
$"Version {result.UpdateInfo.Version} is available. Download now?");
128+
129+
if (confirmResult.Response == 1) // Yes
130+
{
131+
// Download update manually
132+
var downloadPath = await Electron.AutoUpdater.DownloadUpdateAsync();
133+
Console.WriteLine($"Downloaded to: {downloadPath}");
134+
135+
// Install update
136+
Electron.AutoUpdater.QuitAndInstall();
137+
}
138+
}
139+
```
140+
141+
### Update Event Handling
142+
143+
```csharp
144+
// Handle update events
145+
Electron.AutoUpdater.OnCheckingForUpdate += () =>
146+
{
147+
Console.WriteLine("Checking for updates...");
148+
};
149+
150+
Electron.AutoUpdater.OnUpdateAvailable += (updateInfo) =>
151+
{
152+
Console.WriteLine($"Update available: {updateInfo.Version}");
153+
};
154+
155+
Electron.AutoUpdater.OnUpdateNotAvailable += (updateInfo) =>
156+
{
157+
Console.WriteLine("No updates available");
158+
};
159+
160+
Electron.AutoUpdater.OnDownloadProgress += (progressInfo) =>
161+
{
162+
Console.WriteLine($"Download progress: {progressInfo.Percent}%");
163+
};
164+
165+
Electron.AutoUpdater.OnUpdateDownloaded += (updateInfo) =>
166+
{
167+
Console.WriteLine($"Update downloaded: {updateInfo.Version}");
168+
169+
// Show notification to user
170+
Electron.Notification.Show(new NotificationOptions
171+
{
172+
Title = "Update Downloaded",
173+
Body = $"Version {updateInfo.Version} is ready to install.",
174+
Actions = new[]
175+
{
176+
new NotificationAction { Text = "Install Now", Type = NotificationActionType.Button },
177+
new NotificationAction { Text = "Later", Type = NotificationActionType.Button }
178+
}
179+
});
180+
};
181+
182+
Electron.AutoUpdater.OnError += (error) =>
183+
{
184+
Console.WriteLine($"Update error: {error}");
185+
Electron.Dialog.ShowErrorBox("Update Error", $"Failed to update: {error}");
186+
};
187+
```
188+
189+
### GitHub Provider Configuration
190+
191+
```csharp
192+
// Configure for GitHub releases
193+
Electron.AutoUpdater.AllowPrerelease = true; // Allow pre-release versions
194+
Electron.AutoUpdater.FullChangelog = true; // Get full changelog
195+
Electron.AutoUpdater.AllowDowngrade = false; // Prevent downgrades
196+
197+
// Set request headers if needed
198+
Electron.AutoUpdater.RequestHeaders = new Dictionary<string, string>
199+
{
200+
["Authorization"] = "token your-github-token",
201+
["User-Agent"] = "MyApp-Updater"
202+
};
203+
```
204+
205+
### Update Installation
206+
207+
```csharp
208+
// Install update immediately
209+
if (updateDownloaded)
210+
{
211+
Electron.AutoUpdater.QuitAndInstall();
212+
}
213+
214+
// Silent install (Windows only)
215+
Electron.AutoUpdater.QuitAndInstall(isSilent: true, isForceRunAfter: true);
216+
```
217+
218+
### Version Management
219+
220+
```csharp
221+
// Get current version
222+
var currentVersion = await Electron.AutoUpdater.CurrentVersionAsync;
223+
Console.WriteLine($"Current version: {currentVersion}");
224+
225+
// Get update channel
226+
var channel = await Electron.AutoUpdater.ChannelAsync;
227+
Console.WriteLine($"Update channel: {channel}");
228+
229+
// Set custom feed URL
230+
// Note: This would typically be configured in electron-builder.json
231+
var feedUrl = await Electron.AutoUpdater.GetFeedURLAsync();
232+
Console.WriteLine($"Feed URL: {feedUrl}");
233+
```
234+
235+
## Related APIs
236+
237+
- [Electron.App](App.md) - Application lifecycle events during updates
238+
- [Electron.Notification](Notification.md) - Notify users about update status
239+
- [Electron.Dialog](Dialog.md) - Show update confirmation dialogs
240+
241+
## Additional Resources
242+
243+
- [Electron AutoUpdater Documentation](https://electronjs.org/docs/api/auto-updater) - Official Electron auto-updater API

0 commit comments

Comments
 (0)