migration
This commit is contained in:
parent
561881c9aa
commit
f133c740e1
55 changed files with 2928 additions and 20 deletions
105
test/Discovery.Loader.Avalonia/ViewModels/MainViewModel.cs
Normal file
105
test/Discovery.Loader.Avalonia/ViewModels/MainViewModel.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
using Avalonia.Threading;
|
||||
using Discovery.Loader.Models;
|
||||
using Discovery.Loader.Services;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Discovery.Loader.ViewModels;
|
||||
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
public string? Text
|
||||
{
|
||||
get => _text;
|
||||
set => this.RaiseAndSetIfChanged(ref _text, value);
|
||||
}
|
||||
|
||||
private string? _text;
|
||||
|
||||
public double Progress
|
||||
{
|
||||
get => _progress;
|
||||
set => this.RaiseAndSetIfChanged(ref _progress, value);
|
||||
}
|
||||
|
||||
private double _progress;
|
||||
|
||||
public async Task InstallAsync(UpdateService updater, Update update)
|
||||
{
|
||||
if (!updater.AppDir.Exists)
|
||||
updater.AppDir.Create();
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = "Install";
|
||||
});
|
||||
|
||||
var download = await updater.DownloadAsync(update, (p) => Task.Run(() =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Progress = p;
|
||||
}, DispatcherPriority.Default, default);
|
||||
}, default));
|
||||
|
||||
if (!download)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = "Failed to install";
|
||||
});
|
||||
|
||||
await Task.Delay(3000);
|
||||
return;
|
||||
}
|
||||
|
||||
updater.Extract();
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(UpdateService updater, Update update)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = "Download Update";
|
||||
});
|
||||
|
||||
var download = await updater.DownloadAsync(update, (p) => Task.Run(() =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Progress = p;
|
||||
}, DispatcherPriority.Default, default);
|
||||
}, default));
|
||||
|
||||
if (!download)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = "Failed to download Update!";
|
||||
});
|
||||
|
||||
await Task.Delay(3000);
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = "Extract Update";
|
||||
});
|
||||
|
||||
updater.Extract();
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
public async Task ErrorAsync(string message)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Text = message;
|
||||
});
|
||||
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue