2025-02-21 13:13:35 +03:00
|
|
|
using System;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.VisualTree;
|
2025-02-22 12:19:42 +03:00
|
|
|
using Plombir;
|
2025-02-21 13:13:35 +03:00
|
|
|
using LauncherGUI.ViewModels;
|
2025-02-21 16:09:06 +03:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Runtime.InteropServices;
|
2025-02-21 13:13:35 +03:00
|
|
|
|
|
|
|
namespace LauncherGUI.Views;
|
|
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
{
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
DataContext = new MainWindowViewModel();
|
2025-02-21 16:09:06 +03:00
|
|
|
if (DataContext == null) throw new NullReferenceException("Failed to set DataContext for MainWindow");
|
2025-02-21 13:13:35 +03:00
|
|
|
}
|
|
|
|
private async void OnLaunchMinecraftClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
|
|
|
|
var button = sender as Button;
|
|
|
|
if (button == null) return;
|
|
|
|
|
|
|
|
var root = button.GetVisualRoot() as MainWindow;
|
|
|
|
if (root == null) return;
|
2025-02-22 12:19:42 +03:00
|
|
|
|
2025-02-21 13:13:35 +03:00
|
|
|
var vm = DataContext as MainWindowViewModel;
|
2025-02-21 16:09:06 +03:00
|
|
|
await LauncherUtils.CreateMinecraftInstance(vm, root);
|
2025-02-22 12:19:42 +03:00
|
|
|
|
2025-02-21 13:13:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnChooseVersionClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2025-02-21 16:09:06 +03:00
|
|
|
if (sender is not Button button) return;
|
2025-02-21 13:13:35 +03:00
|
|
|
|
2025-02-21 16:09:06 +03:00
|
|
|
if (button.GetVisualRoot() is not MainWindow root) return;
|
2025-02-21 13:13:35 +03:00
|
|
|
|
|
|
|
VersionSelectorWindow selector = new(DataContext as MainWindowViewModel);
|
|
|
|
selector.Show(root);
|
|
|
|
}
|
|
|
|
|
2025-02-21 16:09:06 +03:00
|
|
|
private void OnCogPressed(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is not Image img) return;
|
|
|
|
|
|
|
|
if (img.GetVisualRoot() is not MainWindow root) return;
|
|
|
|
|
|
|
|
SettingsWindow settings = new(DataContext as MainWindowViewModel);
|
|
|
|
settings.Show(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGitlabPressed(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
string url = "https://gitlab.com/nullmax17/PlombirLauncher";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Process.Start(url);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
// hack because of this: https://github.com/dotnet/corefx/issues/10361
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
{
|
|
|
|
url = url.Replace("&", "^&");
|
|
|
|
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
|
|
|
}
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
{
|
|
|
|
Process.Start("xdg-open", url);
|
|
|
|
}
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
|
{
|
|
|
|
Process.Start("open", url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-25 18:32:24 +03:00
|
|
|
private void OnAccountSettingsPressed(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2025-02-25 22:42:41 +03:00
|
|
|
if (sender is not Image img) return;
|
|
|
|
|
|
|
|
if (img.GetVisualRoot() is not MainWindow root) return;
|
|
|
|
|
|
|
|
SessionManagmentWindow sessionManager = new(DataContext as MainWindowViewModel);
|
|
|
|
sessionManager.Show(root);
|
2025-02-25 18:32:24 +03:00
|
|
|
}
|
|
|
|
|
2025-02-22 12:19:42 +03:00
|
|
|
}
|