82 lines
2.2 KiB
C#
Raw Normal View History

2023-05-11 23:11:39 -04:00
using Avalonia;
using ReactiveUI;
2023-05-14 22:35:06 -04:00
using Serilog;
2023-08-25 23:46:11 -04:00
using SPTInstaller.CustomControls;
using SPTInstaller.Helpers;
using SPTInstaller.Interfaces;
2023-08-25 23:46:11 -04:00
using System.Threading.Tasks;
2023-05-11 23:11:39 -04:00
using System.Windows.Input;
namespace SPTInstaller.ViewModels;
public class MessageViewModel : ViewModelBase
2023-05-11 23:11:39 -04:00
{
private bool _HasErrors;
public bool HasErrors
2023-05-11 23:11:39 -04:00
{
get => _HasErrors;
set => this.RaiseAndSetIfChanged(ref _HasErrors, value);
}
private string _Message;
public string Message
{
get => _Message;
set => this.RaiseAndSetIfChanged(ref _Message, value);
}
2023-07-30 16:15:52 -04:00
private bool _showCloseButton;
public bool ShowCloseButton
{
get => _showCloseButton;
set => this.RaiseAndSetIfChanged(ref _showCloseButton, value);
}
2023-08-25 23:46:11 -04:00
private string _cacheInfoText;
public string CacheInfoText
{
get => _cacheInfoText;
set => this.RaiseAndSetIfChanged(ref _cacheInfoText, value);
}
private StatusSpinner.SpinnerState _cacheCheckState;
public StatusSpinner.SpinnerState CacheCheckState
{
get => _cacheCheckState;
set => this.RaiseAndSetIfChanged(ref _cacheCheckState, value);
}
public ICommand CloseCommand { get; set; } = ReactiveCommand.Create(() =>
{
if (Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
2023-05-11 23:11:39 -04:00
{
desktopApp.MainWindow.Close();
2023-05-11 23:11:39 -04:00
}
});
2023-05-11 23:11:39 -04:00
public MessageViewModel(IScreen Host, IResult result, bool showCloseButton = true, bool noLog = false) : base(Host)
{
2023-07-30 16:15:52 -04:00
ShowCloseButton = showCloseButton;
Message = result.Message;
2023-05-11 23:11:39 -04:00
2023-08-25 23:46:11 -04:00
Task.Run(() =>
{
CacheInfoText = "Getting cache size ...";
CacheCheckState = StatusSpinner.SpinnerState.Running;
CacheInfoText = $"Cache Size: {DownloadCacheHelper.GetCacheSizeText()}";
CacheCheckState = StatusSpinner.SpinnerState.OK;
});
if (result.Succeeded)
2023-05-11 23:11:39 -04:00
{
Log.Information(Message);
return;
2023-05-11 23:11:39 -04:00
}
HasErrors = true;
if (!noLog)
Log.Error(Message);
2023-05-11 23:11:39 -04:00
}
}