11using System . Diagnostics ;
22using System . Threading . Tasks ;
33using System . Windows . Input ;
4-
4+ using ApplicationNameUpperCamelCase . Views ;
55using Avalonia . Controls ;
66using Avalonia . Threading ;
77
88using Nullinside . Api . Common . Desktop ;
99
1010using ReactiveUI ;
1111
12- using SiteMonitor . Views ;
13-
14- namespace SiteMonitor . ViewModels ;
12+ namespace ApplicationNameUpperCamelCase . ViewModels ;
1513
1614/// <summary>
1715/// The view model for the <seealso cref="NewVersionWindow" /> class.
1816/// </summary>
1917public class NewVersionWindowViewModel : ViewModelBase {
18+ /// <summary>
19+ /// True if updating the application currently, false otherwise.
20+ /// </summary>
21+ private bool _isUpdating ;
22+
2023 /// <summary>
2124 /// The local version of the software.
2225 /// </summary>
@@ -36,12 +39,12 @@ public class NewVersionWindowViewModel : ViewModelBase {
3639 /// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
3740 /// </summary>
3841 public NewVersionWindowViewModel ( ) {
39- OpenBrowser = ReactiveCommand . Create ( LaunchBrowser ) ;
42+ UpdateSoftware = ReactiveCommand . Create ( StartUpdateSoftware ) ;
4043 CloseWindow = ReactiveCommand . Create < Window > ( CloseWindowCommand ) ;
4144
4245 Task . Factory . StartNew ( async ( ) => {
4346 GithubLatestReleaseJson ? version =
44- await GitHubUpdateManager . GetLatestVersion ( "nullinside-development-group" , "nullinside-site-monitor " ) ;
47+ await GitHubUpdateManager . GetLatestVersion ( "nullinside-development-group" , "ApplicationNameUpperCamelCase " ) ;
4548
4649 if ( null == version ) {
4750 return ;
@@ -69,9 +72,17 @@ public string? ServerVersion {
6972 }
7073
7174 /// <summary>
72- /// A command to open the browser window at the current update's location .
75+ /// True if updating the application currently, false otherwise .
7376 /// </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 ; }
7586
7687 /// <summary>
7788 /// A command to close the current window.
@@ -89,11 +100,16 @@ private void CloseWindowCommand(Window self) {
89100 /// <summary>
90101 /// Launches the web browser at the new release page.
91102 /// </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 ) ;
98114 }
99115}
0 commit comments