2023-05-11 23:11:39 -04:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using SPTInstaller.Controllers;
|
|
|
|
|
using SPTInstaller.Helpers;
|
|
|
|
|
using SPTInstaller.Interfaces;
|
|
|
|
|
using SPTInstaller.Models;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.ViewModels;
|
|
|
|
|
|
|
|
|
|
public class InstallViewModel : ViewModelBase
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
private IProgressableTask _currentTask;
|
|
|
|
|
public IProgressableTask CurrentTask
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
get => _currentTask;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _currentTask, value);
|
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public ObservableCollection<InstallerTaskBase> MyTasks { get; set; } = new(ServiceHelper.GetAll<InstallerTaskBase>());
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public InstallViewModel(IScreen host) : base(host)
|
|
|
|
|
{
|
|
|
|
|
var installer = ServiceHelper.Get<InstallController>();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
installer.TaskChanged += (sender, task) => CurrentTask = task;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
var result = await installer.RunTasks();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
NavigateTo(new MessageViewModel(HostScreen, result));
|
|
|
|
|
});
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|