@@ -16,95 +16,31 @@ public sealed class AutoUpdater
1616 /// <summary>
1717 /// Whether to automatically download an update when it is found. (Default is true)
1818 /// </summary>
19- public Task < bool > IsAutoDownloadEnabledAsync ( )
20- {
21- var taskCompletionSource = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
22-
23- BridgeConnector . On < bool > ( "autoUpdater-autoDownload-get-reply" , ( result ) =>
24- {
25- BridgeConnector . Off ( "autoUpdater-autoDownload-get-reply" ) ;
26- taskCompletionSource . SetResult ( result ) ;
27- } ) ;
28-
29- BridgeConnector . Emit ( "autoUpdater-autoDownload-get" ) ;
30-
31- return taskCompletionSource . Task ;
32- }
19+ public Task < bool > IsAutoDownloadEnabledAsync ( ) => BridgeConnector . OnResult < bool > ( "autoUpdater-autoDownload-get" , "autoUpdater-autoDownload-get-reply" ) ;
3320
3421 /// <summary>
3522 /// Whether to automatically install a downloaded update on app quit (if `QuitAndInstall` was not called before).
3623 ///
3724 /// Applicable only on Windows and Linux.
3825 /// </summary>
39- public Task < bool > IsAutoInstallOnAppQuitEnabledAsync ( )
40- {
41- var taskCompletionSource = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
42-
43- BridgeConnector . On < bool > ( "autoUpdater-autoInstallOnAppQuit-get-reply" , ( result ) =>
44- {
45- BridgeConnector . Off ( "autoUpdater-autoInstallOnAppQuit-get-reply" ) ;
46- taskCompletionSource . SetResult ( result ) ;
47- } ) ;
48-
49- BridgeConnector . Emit ( "autoUpdater-autoInstallOnAppQuit-get" ) ;
50-
51- return taskCompletionSource . Task ;
52- }
26+ public Task < bool > IsAutoInstallOnAppQuitEnabledAsync ( ) => BridgeConnector . OnResult < bool > ( "autoUpdater-autoInstallOnAppQuit-get" , "autoUpdater-autoInstallOnAppQuit-get-reply" ) ;
5327
5428 /// <summary>
5529 /// *GitHub provider only.* Whether to allow update to pre-release versions.
5630 /// Defaults to "true" if application version contains prerelease components (e.g. "0.12.1-alpha.1", here "alpha" is a prerelease component), otherwise "false".
5731 ///
5832 /// If "true", downgrade will be allowed("allowDowngrade" will be set to "true").
5933 /// </summary>
60- public Task < bool > IsAllowPrereleaseEnabledAsync ( )
61- {
62- var taskCompletionSource = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
63-
64- BridgeConnector . On < bool > ( "autoUpdater-allowPrerelease-get-reply" , ( result ) =>
65- {
66- BridgeConnector . Off ( "autoUpdater-allowPrerelease-get-reply" ) ;
67- taskCompletionSource . SetResult ( result ) ;
68- } ) ;
69-
70- BridgeConnector . Emit ( "autoUpdater-allowPrerelease-get" ) ;
71-
72- return taskCompletionSource . Task ;
73- }
34+ public Task < bool > IsAllowPrereleaseEnabledAsync ( ) => BridgeConnector . OnResult < bool > ( "autoUpdater-allowPrerelease-get" , "autoUpdater-allowPrerelease-get-reply" ) ;
7435
7536 /// <summary>
7637 /// *GitHub provider only.*
7738 /// Get all release notes (from current version to latest), not just the latest (Default is false).
7839 /// </summary>
79- public Task < bool > IsFullChangeLogEnabledAsync ( )
80- {
81- var taskCompletionSource = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
82-
83- BridgeConnector . On < bool > ( "autoUpdater-fullChangelog-get-reply" , ( result ) =>
84- {
85- BridgeConnector . Off ( "autoUpdater-fullChangelog-get-reply" ) ;
86- taskCompletionSource . SetResult ( result ) ;
87- } ) ;
88-
89- BridgeConnector . Emit ( "autoUpdater-fullChangelog-get" ) ;
90-
91- return taskCompletionSource . Task ;
92- }
93-
94- public Task < bool > IsAllowDowngradeEnabledAsync ( )
95- {
96- var taskCompletionSource = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
97-
98- BridgeConnector . On < bool > ( "autoUpdater-allowDowngrade-get-reply" , ( result ) =>
99- {
100- BridgeConnector . Off ( "autoUpdater-allowDowngrade-get-reply" ) ;
101- taskCompletionSource . SetResult ( result ) ;
102- } ) ;
40+ public Task < bool > IsFullChangeLogEnabledAsync ( ) => BridgeConnector . OnResult < bool > ( "autoUpdater-fullChangelog-get" , "autoUpdater-fullChangelog-get-reply" ) ;
10341
104- BridgeConnector . Emit ( "autoUpdater-allowDowngrade-get" ) ;
105-
106- return taskCompletionSource . Task ;
107- }
42+ public Task < bool > IsAllowDowngradeEnabledAsync ( ) => BridgeConnector . OnResult < bool > ( "autoUpdater-allowDowngrade-get" , "autoUpdater-allowDowngrade-get-reply" ) ;
43+
10844
10945 /// <summary>
11046 /// Whether to automatically download an update when it is found. (Default is true)
@@ -172,72 +108,23 @@ public bool AllowDowngrade
172108 /// <summary>
173109 /// For test only.
174110 /// </summary>
175- public Task < string > GetUpdateConfigPathAsync ( )
176- {
177- var taskCompletionSource = new TaskCompletionSource < string > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
178-
179- BridgeConnector . On < string > ( "autoUpdater-updateConfigPath-get-reply" , ( result ) =>
180- {
181- BridgeConnector . Off ( "autoUpdater-updateConfigPath-get-reply" ) ;
182- taskCompletionSource . SetResult ( result . ToString ( ) ) ;
183- } ) ;
184-
185- BridgeConnector . Emit ( "autoUpdater-updateConfigPath-get" ) ;
186-
187- return taskCompletionSource . Task ;
188- }
111+ public Task < string > GetUpdateConfigPathAsync ( ) => BridgeConnector . OnResult < string > ( "autoUpdater-updateConfigPath-get" , "autoUpdater-updateConfigPath-get-reply" ) ;
189112
190113 /// <summary>
191114 /// The current application version
192115 /// </summary>
193- public Task < SemVer > GetCurrentVersionAsync ( )
194- {
195- var taskCompletionSource = new TaskCompletionSource < SemVer > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
196-
197- BridgeConnector . On < SemVer > ( "autoUpdater-currentVersion-get-reply" , ( version ) =>
198- {
199- BridgeConnector . Off ( "autoUpdater-currentVersion-get-reply" ) ;
200- taskCompletionSource . SetResult ( version ) ;
201- } ) ;
202- BridgeConnector . Emit ( "autoUpdater-currentVersion-get" ) ;
203-
204- return taskCompletionSource . Task ;
205- }
116+ public Task < SemVer > GetCurrentVersionAsync ( ) => BridgeConnector . OnResult < SemVer > ( "autoUpdater-updateConcurrentVersionfigPath-get" , "autoUpdater-currentVersion-get-reply" ) ;
206117
207118 /// <summary>
208119 /// Get the update channel. Not applicable for GitHub.
209120 /// Doesn’t return channel from the update configuration, only if was previously set.
210121 /// </summary>
211- public Task < string > GetChannelAsync ( )
212- {
213- var taskCompletionSource = new TaskCompletionSource < string > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
214-
215- BridgeConnector . On < string > ( "autoUpdater-channel-get-reply" , ( result ) =>
216- {
217- BridgeConnector . Off ( "autoUpdater-channel-get-reply" ) ;
218- taskCompletionSource . SetResult ( result . ToString ( ) ) ;
219- } ) ;
220- BridgeConnector . Emit ( "autoUpdater-channel-get" ) ;
221-
222- return taskCompletionSource . Task ;
223- }
224-
225-
122+ public Task < string > GetChannelAsync ( ) => BridgeConnector . OnResult < string > ( "autoUpdater-channel-get" , "autoUpdater-channel-get-reply" ) ;
226123
227124 /// <summary>
228125 /// The request headers.
229126 /// </summary>
230- public Task < Dictionary < string , string > > GetRequestHeadersAsync ( )
231- {
232- var taskCompletionSource = new TaskCompletionSource < Dictionary < string , string > > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
233- BridgeConnector . On < Dictionary < string , string > > ( "autoUpdater-requestHeaders-get-reply" , ( headers ) =>
234- {
235- BridgeConnector . Off ( "autoUpdater-requestHeaders-get-reply" ) ;
236- taskCompletionSource . SetResult ( headers ) ;
237- } ) ;
238- BridgeConnector . Emit ( "autoUpdater-requestHeaders-get" ) ;
239- return taskCompletionSource . Task ;
240- }
127+ public Task < Dictionary < string , string > > GetRequestHeadersAsync ( ) => BridgeConnector . OnResult < Dictionary < string , string > > ( "autoUpdater-requestHeaders-get" , "autoUpdater-requestHeaders-get-reply" ) ;
241128
242129 /// <summary>
243130 /// The request headers.
@@ -246,7 +133,7 @@ public Dictionary<string, string> RequestHeaders
246133 {
247134 set
248135 {
249- BridgeConnector . Emit ( "autoUpdater-requestHeaders-set" , JObject . FromObject ( value , _jsonSerializer ) ) ;
136+ BridgeConnector . Emit ( "autoUpdater-requestHeaders-set" , value ) ;
250137 }
251138 }
252139
@@ -581,10 +468,5 @@ public Task<string> GetFeedURLAsync()
581468
582469 return taskCompletionSource . Task ;
583470 }
584-
585- private readonly JsonSerializer _jsonSerializer = new JsonSerializer ( )
586- {
587- ContractResolver = new CamelCasePropertyNamesContractResolver ( )
588- } ;
589471 }
590472}
0 commit comments