11using ElectronNET . API . Entities ;
22using Newtonsoft . Json . Linq ;
33using System ;
4- using System . Collections . Generic ;
5- using System . Text ;
6- using System . Threading ;
74using System . Threading . Tasks ;
85
96namespace ElectronNET . API
@@ -13,6 +10,181 @@ namespace ElectronNET.API
1310 /// </summary>
1411 public sealed class AutoUpdater
1512 {
13+ /// <summary>
14+ /// Emitted when there is an error while updating.
15+ /// </summary>
16+ public event Action < string > OnError
17+ {
18+ add
19+ {
20+ if ( _error == null )
21+ {
22+ BridgeConnector . Socket . On ( "autoUpdater-error" + GetHashCode ( ) , ( message ) =>
23+ {
24+ _error ( message . ToString ( ) ) ;
25+ } ) ;
26+
27+ BridgeConnector . Socket . Emit ( "register-autoUpdater-error-event" , GetHashCode ( ) ) ;
28+ }
29+ _error += value ;
30+ }
31+ remove
32+ {
33+ _error -= value ;
34+
35+ if ( _error == null )
36+ BridgeConnector . Socket . Off ( "autoUpdater-error" + GetHashCode ( ) ) ;
37+ }
38+ }
39+
40+ private event Action < string > _error ;
41+
42+ /// <summary>
43+ /// Emitted when checking if an update has started.
44+ /// </summary>
45+ public event Action OnCheckingForUpdate
46+ {
47+ add
48+ {
49+ if ( _checkingForUpdate == null )
50+ {
51+ BridgeConnector . Socket . On ( "autoUpdater-checking-for-update" + GetHashCode ( ) , ( ) =>
52+ {
53+ _checkingForUpdate ( ) ;
54+ } ) ;
55+
56+ BridgeConnector . Socket . Emit ( "register-autoUpdater-checking-for-update-event" , GetHashCode ( ) ) ;
57+ }
58+ _checkingForUpdate += value ;
59+ }
60+ remove
61+ {
62+ _checkingForUpdate -= value ;
63+
64+ if ( _checkingForUpdate == null )
65+ BridgeConnector . Socket . Off ( "autoUpdater-checking-for-update" + GetHashCode ( ) ) ;
66+ }
67+ }
68+
69+ private event Action _checkingForUpdate ;
70+
71+ /// <summary>
72+ /// Emitted when there is an available update.
73+ /// The update is downloaded automatically if AutoDownload is true.
74+ /// </summary>
75+ public event Action < UpdateInfo > OnUpdateAvailable
76+ {
77+ add
78+ {
79+ if ( _updateAvailable == null )
80+ {
81+ BridgeConnector . Socket . On ( "autoUpdater-update-available" + GetHashCode ( ) , ( updateInfo ) =>
82+ {
83+ _updateAvailable ( JObject . Parse ( updateInfo . ToString ( ) ) . ToObject < UpdateInfo > ( ) ) ;
84+ } ) ;
85+
86+ BridgeConnector . Socket . Emit ( "register-autoUpdater-update-available-event" , GetHashCode ( ) ) ;
87+ }
88+ _updateAvailable += value ;
89+ }
90+ remove
91+ {
92+ _updateAvailable -= value ;
93+
94+ if ( _updateAvailable == null )
95+ BridgeConnector . Socket . Off ( "autoUpdater-update-available" + GetHashCode ( ) ) ;
96+ }
97+ }
98+
99+ private event Action < UpdateInfo > _updateAvailable ;
100+
101+ /// <summary>
102+ /// Emitted when there is no available update.
103+ /// </summary>
104+ public event Action < UpdateInfo > OnUpdateNotAvailable
105+ {
106+ add
107+ {
108+ if ( _updateNotAvailable == null )
109+ {
110+ BridgeConnector . Socket . On ( "autoUpdater-update-not-available" + GetHashCode ( ) , ( updateInfo ) =>
111+ {
112+ _updateNotAvailable ( JObject . Parse ( updateInfo . ToString ( ) ) . ToObject < UpdateInfo > ( ) ) ;
113+ } ) ;
114+
115+ BridgeConnector . Socket . Emit ( "register-autoUpdater-update-not-available-event" , GetHashCode ( ) ) ;
116+ }
117+ _updateNotAvailable += value ;
118+ }
119+ remove
120+ {
121+ _updateNotAvailable -= value ;
122+
123+ if ( _updateNotAvailable == null )
124+ BridgeConnector . Socket . Off ( "autoUpdater-update-not-available" + GetHashCode ( ) ) ;
125+ }
126+ }
127+
128+ private event Action < UpdateInfo > _updateNotAvailable ;
129+
130+ /// <summary>
131+ /// Emitted on download progress.
132+ /// </summary>
133+ public event Action < ProgressInfo > OnDownloadProgress
134+ {
135+ add
136+ {
137+ if ( _downloadProgress == null )
138+ {
139+ BridgeConnector . Socket . On ( "autoUpdater-download-progress" + GetHashCode ( ) , ( progressInfo ) =>
140+ {
141+ _downloadProgress ( JObject . Parse ( progressInfo . ToString ( ) ) . ToObject < ProgressInfo > ( ) ) ;
142+ } ) ;
143+
144+ BridgeConnector . Socket . Emit ( "register-autoUpdater-download-progress-event" , GetHashCode ( ) ) ;
145+ }
146+ _downloadProgress += value ;
147+ }
148+ remove
149+ {
150+ _downloadProgress -= value ;
151+
152+ if ( _downloadProgress == null )
153+ BridgeConnector . Socket . Off ( "autoUpdater-download-progress" + GetHashCode ( ) ) ;
154+ }
155+ }
156+
157+ private event Action < ProgressInfo > _downloadProgress ;
158+
159+ /// <summary>
160+ /// Emitted on download complete.
161+ /// </summary>
162+ public event Action < UpdateInfo > OnUpdateDownloaded
163+ {
164+ add
165+ {
166+ if ( _updateDownloaded == null )
167+ {
168+ BridgeConnector . Socket . On ( "autoUpdater-update-downloaded" + GetHashCode ( ) , ( updateInfo ) =>
169+ {
170+ _updateDownloaded ( JObject . Parse ( updateInfo . ToString ( ) ) . ToObject < UpdateInfo > ( ) ) ;
171+ } ) ;
172+
173+ BridgeConnector . Socket . Emit ( "register-autoUpdater-update-downloaded-event" , GetHashCode ( ) ) ;
174+ }
175+ _updateDownloaded += value ;
176+ }
177+ remove
178+ {
179+ _updateDownloaded -= value ;
180+
181+ if ( _updateDownloaded == null )
182+ BridgeConnector . Socket . Off ( "autoUpdater-update-downloaded" + GetHashCode ( ) ) ;
183+ }
184+ }
185+
186+ private event Action < UpdateInfo > _updateDownloaded ;
187+
16188 private static AutoUpdater _autoUpdater ;
17189 private static object _syncRoot = new object ( ) ;
18190
0 commit comments