using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using ModpackLauncher.Services;

namespace ModpackLauncher;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        // Clean up any .old launcher left behind by a self-update on a prior run.
        // Best-effort: if the previous process hasn't fully released the handle yet
        // we just retry on the next startup.
        SelfUpdateService.CleanupAfterUpdate();

        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow();
        }

        base.OnFrameworkInitializationCompleted();
    }
}