@@ -10,6 +10,203 @@ namespace ElectronNET.API
1010 /// </summary>
1111 public sealed class AutoUpdater
1212 {
13+ /// <summary>
14+ /// Whether to automatically download an update when it is found. (Default is true)
15+ /// </summary>
16+ public bool AutoDownload
17+ {
18+ get
19+ {
20+ return Task . Run < bool > ( ( ) =>
21+ {
22+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
23+
24+ BridgeConnector . Socket . On ( "autoUpdater-autoDownload-get-reply" , ( result ) =>
25+ {
26+ BridgeConnector . Socket . Off ( "autoUpdater-autoDownload-get-reply" ) ;
27+ taskCompletionSource . SetResult ( ( bool ) result ) ;
28+ } ) ;
29+
30+ BridgeConnector . Socket . Emit ( "autoUpdater-autoDownload-get" ) ;
31+
32+ return taskCompletionSource . Task ;
33+ } ) . Result ;
34+ }
35+ set
36+ {
37+ BridgeConnector . Socket . Emit ( "autoUpdater-autoDownload-set" , value ) ;
38+ }
39+ }
40+
41+ /// <summary>
42+ /// Whether to automatically install a downloaded update on app quit (if `QuitAndInstall` was not called before).
43+ ///
44+ /// Applicable only on Windows and Linux.
45+ /// </summary>
46+ public bool AutoInstallOnAppQuit
47+ {
48+ get
49+ {
50+ return Task . Run < bool > ( ( ) =>
51+ {
52+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
53+
54+ BridgeConnector . Socket . On ( "autoUpdater-autoInstallOnAppQuit-get-reply" , ( result ) =>
55+ {
56+ BridgeConnector . Socket . Off ( "autoUpdater-autoInstallOnAppQuit-get-reply" ) ;
57+ taskCompletionSource . SetResult ( ( bool ) result ) ;
58+ } ) ;
59+
60+ BridgeConnector . Socket . Emit ( "autoUpdater-autoInstallOnAppQuit-get" ) ;
61+
62+ return taskCompletionSource . Task ;
63+ } ) . Result ;
64+ }
65+ set
66+ {
67+ BridgeConnector . Socket . Emit ( "autoUpdater-autoInstallOnAppQuit-set" , value ) ;
68+ }
69+ }
70+
71+ /// <summary>
72+ /// *GitHub provider only.* Whether to allow update to pre-release versions.
73+ /// Defaults to "true" if application version contains prerelease components (e.g. "0.12.1-alpha.1", here "alpha" is a prerelease component), otherwise "false".
74+ ///
75+ /// If "true", downgrade will be allowed("allowDowngrade" will be set to "true").
76+ /// </summary>
77+ public bool AllowPrerelease
78+ {
79+ get
80+ {
81+ return Task . Run < bool > ( ( ) =>
82+ {
83+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
84+
85+ BridgeConnector . Socket . On ( "autoUpdater-allowPrerelease-get-reply" , ( result ) =>
86+ {
87+ BridgeConnector . Socket . Off ( "autoUpdater-allowPrerelease-get-reply" ) ;
88+ taskCompletionSource . SetResult ( ( bool ) result ) ;
89+ } ) ;
90+
91+ BridgeConnector . Socket . Emit ( "autoUpdater-allowPrerelease-get" ) ;
92+
93+ return taskCompletionSource . Task ;
94+ } ) . Result ;
95+ }
96+ set
97+ {
98+ BridgeConnector . Socket . Emit ( "autoUpdater-allowPrerelease-set" , value ) ;
99+ }
100+ }
101+
102+ /// <summary>
103+ /// *GitHub provider only.*
104+ /// Get all release notes (from current version to latest), not just the latest (Default is false).
105+ /// </summary>
106+ public bool FullChangelog
107+ {
108+ get
109+ {
110+ return Task . Run < bool > ( ( ) =>
111+ {
112+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
113+
114+ BridgeConnector . Socket . On ( "autoUpdater-fullChangelog-get-reply" , ( result ) =>
115+ {
116+ BridgeConnector . Socket . Off ( "autoUpdater-fullChangelog-get-reply" ) ;
117+ taskCompletionSource . SetResult ( ( bool ) result ) ;
118+ } ) ;
119+
120+ BridgeConnector . Socket . Emit ( "autoUpdater-fullChangelog-get" ) ;
121+
122+ return taskCompletionSource . Task ;
123+ } ) . Result ;
124+ }
125+ set
126+ {
127+ BridgeConnector . Socket . Emit ( "autoUpdater-fullChangelog-set" , value ) ;
128+ }
129+ }
130+
131+ /// <summary>
132+ /// Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
133+ /// Taken in account only if channel differs (pre-release version component in terms of semantic versioning).
134+ /// Default is false.
135+ /// </summary>
136+ public bool AllowDowngrade
137+ {
138+ get
139+ {
140+ return Task . Run < bool > ( ( ) =>
141+ {
142+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
143+
144+ BridgeConnector . Socket . On ( "autoUpdater-allowDowngrade-get-reply" , ( result ) =>
145+ {
146+ BridgeConnector . Socket . Off ( "autoUpdater-allowDowngrade-get-reply" ) ;
147+ taskCompletionSource . SetResult ( ( bool ) result ) ;
148+ } ) ;
149+
150+ BridgeConnector . Socket . Emit ( "autoUpdater-allowDowngrade-get" ) ;
151+
152+ return taskCompletionSource . Task ;
153+ } ) . Result ;
154+ }
155+ set
156+ {
157+ BridgeConnector . Socket . Emit ( "autoUpdater-allowDowngrade-set" , value ) ;
158+ }
159+ }
160+
161+ /// <summary>
162+ /// For test only.
163+ /// </summary>
164+ public string UpdateConfigPath
165+ {
166+ get
167+ {
168+ return Task . Run < string > ( ( ) =>
169+ {
170+ var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
171+
172+ BridgeConnector . Socket . On ( "autoUpdater-updateConfigPath-get-reply" , ( result ) =>
173+ {
174+ BridgeConnector . Socket . Off ( "autoUpdater-updateConfigPath-get-reply" ) ;
175+ taskCompletionSource . SetResult ( result . ToString ( ) ) ;
176+ } ) ;
177+
178+ BridgeConnector . Socket . Emit ( "autoUpdater-updateConfigPath-get" ) ;
179+
180+ return taskCompletionSource . Task ;
181+ } ) . Result ;
182+ }
183+ }
184+
185+ /// <summary>
186+ /// Get the update channel. Not applicable for GitHub.
187+ /// Doesn’t return channel from the update configuration, only if was previously set.
188+ /// </summary>
189+ public string Channel
190+ {
191+ get
192+ {
193+ return Task . Run < string > ( ( ) =>
194+ {
195+ var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
196+
197+ BridgeConnector . Socket . On ( "autoUpdater-channel-get-reply" , ( result ) =>
198+ {
199+ BridgeConnector . Socket . Off ( "autoUpdater-channel-get-reply" ) ;
200+ taskCompletionSource . SetResult ( result . ToString ( ) ) ;
201+ } ) ;
202+
203+ BridgeConnector . Socket . Emit ( "autoUpdater-channel-get" ) ;
204+
205+ return taskCompletionSource . Task ;
206+ } ) . Result ;
207+ }
208+ }
209+
13210 /// <summary>
14211 /// Emitted when there is an error while updating.
15212 /// </summary>
@@ -264,5 +461,45 @@ public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)
264461 {
265462 BridgeConnector . Socket . Emit ( "autoUpdaterQuitAndInstall" , isSilent , isForceRunAfter ) ;
266463 }
464+
465+ /// <summary>
466+ /// Start downloading update manually. You can use this method if "AutoDownload" option is set to "false".
467+ /// </summary>
468+ /// <returns>Path to downloaded file.</returns>
469+ public Task < string > DownloadUpdateAsync ( )
470+ {
471+ var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
472+ string guid = Guid . NewGuid ( ) . ToString ( ) ;
473+
474+ BridgeConnector . Socket . On ( "autoUpdaterDownloadUpdateComplete" + guid , ( downloadedPath ) =>
475+ {
476+ BridgeConnector . Socket . Off ( "autoUpdaterDownloadUpdateComplete" + guid ) ;
477+ taskCompletionSource . SetResult ( downloadedPath . ToString ( ) ) ;
478+ } ) ;
479+
480+ BridgeConnector . Socket . Emit ( "autoUpdaterDownloadUpdate" , guid ) ;
481+
482+ return taskCompletionSource . Task ;
483+ }
484+
485+ /// <summary>
486+ /// Feed URL.
487+ /// </summary>
488+ /// <returns>Feed URL.</returns>
489+ public Task < string > GetFeedURLAsync ( )
490+ {
491+ var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
492+ string guid = Guid . NewGuid ( ) . ToString ( ) ;
493+
494+ BridgeConnector . Socket . On ( "autoUpdaterGetFeedURLComplete" + guid , ( downloadedPath ) =>
495+ {
496+ BridgeConnector . Socket . Off ( "autoUpdaterGetFeedURLComplete" + guid ) ;
497+ taskCompletionSource . SetResult ( downloadedPath . ToString ( ) ) ;
498+ } ) ;
499+
500+ BridgeConnector . Socket . Emit ( "autoUpdaterGetFeedURL" , guid ) ;
501+
502+ return taskCompletionSource . Task ;
503+ }
267504 }
268505}
0 commit comments