1
1
using System . Diagnostics ;
2
2
using System . Threading . Tasks ;
3
3
using System . Windows . Input ;
4
-
4
+ using ApplicationNameUpperCamelCase . Views ;
5
5
using Avalonia . Controls ;
6
6
using Avalonia . Threading ;
7
7
8
8
using Nullinside . Api . Common . Desktop ;
9
9
10
10
using ReactiveUI ;
11
11
12
- using SiteMonitor . Views ;
13
-
14
- namespace SiteMonitor . ViewModels ;
12
+ namespace ApplicationNameUpperCamelCase . ViewModels ;
15
13
16
14
/// <summary>
17
15
/// The view model for the <seealso cref="NewVersionWindow" /> class.
18
16
/// </summary>
19
17
public class NewVersionWindowViewModel : ViewModelBase {
18
+ /// <summary>
19
+ /// True if updating the application currently, false otherwise.
20
+ /// </summary>
21
+ private bool _isUpdating ;
22
+
20
23
/// <summary>
21
24
/// The local version of the software.
22
25
/// </summary>
@@ -36,12 +39,12 @@ public class NewVersionWindowViewModel : ViewModelBase {
36
39
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
37
40
/// </summary>
38
41
public NewVersionWindowViewModel ( ) {
39
- OpenBrowser = ReactiveCommand . Create ( LaunchBrowser ) ;
42
+ UpdateSoftware = ReactiveCommand . Create ( StartUpdateSoftware ) ;
40
43
CloseWindow = ReactiveCommand . Create < Window > ( CloseWindowCommand ) ;
41
44
42
45
Task . Factory . StartNew ( async ( ) => {
43
46
GithubLatestReleaseJson ? version =
44
- await GitHubUpdateManager . GetLatestVersion ( "nullinside-development-group" , "nullinside-site-monitor " ) ;
47
+ await GitHubUpdateManager . GetLatestVersion ( "nullinside-development-group" , "ApplicationNameUpperCamelCase " ) ;
45
48
46
49
if ( null == version ) {
47
50
return ;
@@ -69,9 +72,17 @@ public string? ServerVersion {
69
72
}
70
73
71
74
/// <summary>
72
- /// A command to open the browser window at the current update's location .
75
+ /// True if updating the application currently, false otherwise .
73
76
/// </summary>
74
- public ICommand OpenBrowser { get ; }
77
+ public bool IsUpdating {
78
+ get => _isUpdating ;
79
+ set => this . RaiseAndSetIfChanged ( ref _isUpdating , value ) ;
80
+ }
81
+
82
+ /// <summary>
83
+ /// A command to update the software.
84
+ /// </summary>
85
+ public ICommand UpdateSoftware { get ; }
75
86
76
87
/// <summary>
77
88
/// A command to close the current window.
@@ -89,11 +100,16 @@ private void CloseWindowCommand(Window self) {
89
100
/// <summary>
90
101
/// Launches the web browser at the new release page.
91
102
/// </summary>
92
- private void LaunchBrowser ( ) {
93
- if ( string . IsNullOrWhiteSpace ( _newVersionUrl ) ) {
94
- return ;
95
- }
96
-
97
- Process . Start ( "explorer" , _newVersionUrl ) ;
103
+ private void StartUpdateSoftware ( ) {
104
+ IsUpdating = true ;
105
+ GitHubUpdateManager . PrepareUpdate ( )
106
+ . ContinueWith ( _ => {
107
+ if ( string . IsNullOrWhiteSpace ( _newVersionUrl ) ) {
108
+ return ;
109
+ }
110
+
111
+ Process . Start ( "explorer" , _newVersionUrl ) ;
112
+ GitHubUpdateManager . ExitApplicationToUpdate ( ) ;
113
+ } ) . ConfigureAwait ( false ) ;
98
114
}
99
115
}
0 commit comments