mirror of
https://gitlab.com/nullmax17/PlombirLauncher.git
synced 2025-03-15 02:11:11 +03:00
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
using Avalonia.Controls;
|
||
|
using Avalonia.Interactivity;
|
||
|
using Avalonia.VisualTree;
|
||
|
using BlightFlame;
|
||
|
using LauncherGUI.ViewModels;
|
||
|
|
||
|
namespace LauncherGUI.Views;
|
||
|
|
||
|
public partial class LoadingWindow : Window
|
||
|
{
|
||
|
private Launcher ln;
|
||
|
public LoadingWindow(string nickname, string? version = null)
|
||
|
{
|
||
|
ln = new Launcher(nickname, version ?? "1.20.1");
|
||
|
InitializeComponent();
|
||
|
DataContext = new LoadingWindowViewModel();
|
||
|
}
|
||
|
|
||
|
public async Task InitLoading()
|
||
|
{
|
||
|
var viewModel = DataContext as LoadingWindowViewModel;
|
||
|
if (viewModel == null)
|
||
|
{
|
||
|
throw new InvalidOperationException("No DataContext set");
|
||
|
}
|
||
|
Task updateGui = new Task(async () => {
|
||
|
while (ln.DownloadStatus != "Finished!"){
|
||
|
viewModel.Progress = ln.DownloadProgress;
|
||
|
viewModel.LoadingStatus = ln.DownloadStatus;
|
||
|
await Task.Delay(1000);
|
||
|
}
|
||
|
viewModel.Progress = 100;
|
||
|
});
|
||
|
updateGui.Start();
|
||
|
|
||
|
await ln.BuildLauncher();
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public async Task RunMinecraft()
|
||
|
{
|
||
|
await ln.RunLauncher();
|
||
|
}
|
||
|
}
|