11using System ;
22using System . Collections . Generic ;
3- using System . IO ;
43using System . Threading . Tasks ;
54using Avalonia . Collections ;
65using Avalonia . Controls ;
76using CommunityToolkit . Mvvm . ComponentModel ;
87using CommunityToolkit . Mvvm . Input ;
98using Markdown . Avalonia ;
9+ using Microsoft . Extensions . Logging ;
1010using SRAFrontend . Controls ;
11- using SRAFrontend . Localization ;
1211using SRAFrontend . Models ;
1312using SRAFrontend . Services ;
1413using SRAFrontend . utilities ;
@@ -25,27 +24,27 @@ public partial class MainWindowViewModel : ViewModelBase
2524 private readonly AnnouncementService _announcementService ;
2625 private readonly SettingsService _settingsService ;
2726 private readonly UpdateService _updateService ;
27+ private readonly ILogger _logger ;
2828
2929 [ ObservableProperty ] private string _lightModeText =
3030 SukiTheme . GetInstance ( ) . ActiveBaseTheme . ToString ( ) == "Light" ? "\uE472 " : "\uE330 " ;
3131
3232 [ ObservableProperty ] private bool _titleBarVisible = true ;
3333
3434 public MainWindowViewModel ( IEnumerable < PageViewModel > pages , ISukiToastManager toastManager ,
35- AnnouncementService announcementService , SettingsService settingsService , UpdateService updateService )
35+ AnnouncementService announcementService , SettingsService settingsService , UpdateService updateService , ILogger < MainWindowViewModel > logger )
3636 {
3737 _announcementService = announcementService ;
3838 Pages = new AvaloniaList < PageViewModel > ( pages ) ;
3939 ToastManager = toastManager ;
4040 _settingsService = settingsService ;
4141 _updateService = updateService ;
42+ _logger = logger ;
4243 _ = CheckForUpdates ( ) ;
4344 }
4445
4546 public ISukiToastManager ToastManager { get ; init ; }
4647
47- public string Greeting { get ; } = Resources . GreetingText ;
48-
4948 public IAvaloniaReadOnlyList < PageViewModel > Pages { get ; }
5049
5150 public void SwitchLightMode ( )
@@ -154,18 +153,25 @@ private async Task DownloadUpdateAsync(VersionResponse versionResponse)
154153 }
155154 catch ( Exception e )
156155 {
157- Console . WriteLine ( e ) ;
156+ _logger . LogError ( e , "Error downloading update" ) ;
157+ ToastManager . Dismiss ( toast ) ;
158+ ToastManager . CreateToast ( )
159+ . WithTitle ( "Update Failed" )
160+ . WithContent ( $ "Failed to download update: { e . Message } ")
161+ . Dismiss ( ) . After ( TimeSpan . FromSeconds ( 5 ) )
162+ . Dismiss ( ) . ByClicking ( )
163+ . Queue ( ) ;
158164 return ;
159165 }
160166
161167 ToastManager . Dismiss ( toast ) ;
162168 ToastManager . CreateToast ( )
163169 . WithTitle ( "Download Complete" )
164- . WithContent ( "Update package will be unzip within 3 seconds." )
170+ . WithContent ( $ "Update package will be unzip to { Environment . CurrentDirectory } within 3 seconds.")
165171 . Dismiss ( ) . After ( TimeSpan . FromSeconds ( 3 ) )
166172 . Dismiss ( ) . ByClicking ( )
167173 . Queue ( ) ;
168174 await Task . Delay ( 3000 ) ;
169- UnzipUtil . Unzip ( result , Path . GetDirectoryName ( Environment . CurrentDirectory ) ! ) ;
175+ UnzipUtil . Unzip ( result , Environment . CurrentDirectory ) ;
170176 }
171177}
0 commit comments