mirror of
https://gitlab.com/nullmax17/PlombirLauncher.git
synced 2025-03-14 18:01:12 +03:00
68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.VisualTree;
|
|
using Plombir;
|
|
using LauncherGUI.ViewModels;
|
|
using System.Threading;
|
|
|
|
namespace LauncherGUI.Views;
|
|
|
|
public partial class LoadingWindow : Window
|
|
{
|
|
private Launcher ln;
|
|
private Task? _buildingTask;
|
|
|
|
// Tokens for controlling download task.
|
|
CancellationTokenSource tokenSource = new CancellationTokenSource();
|
|
public LoadingWindow(string nickname, string? version = null, string? location = null)
|
|
{
|
|
ln = new Launcher(nickname, version ?? "1.20.1", location ?? "./runtime");
|
|
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 ?? "Looking at qubits...";
|
|
await Task.Delay(1000);
|
|
}
|
|
viewModel.Progress = 100;
|
|
});
|
|
|
|
updateGui.Start();
|
|
|
|
|
|
_buildingTask = ln.BuildLauncher(tokenSource.Token);
|
|
|
|
await _buildingTask;
|
|
|
|
|
|
}
|
|
|
|
public async Task RunMinecraft()
|
|
{
|
|
await ln.RunLauncher();
|
|
}
|
|
|
|
private void onStopDownloadClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
tokenSource.Cancel();
|
|
System.Console.WriteLine("Loading disabled gracefully.");
|
|
Close();
|
|
}
|
|
}
|