2024-12-21 13:11:30 +03:00
|
|
|
using System;
|
2025-02-02 19:34:15 +03:00
|
|
|
using System.Globalization;
|
2025-01-14 22:10:16 +03:00
|
|
|
using System.Linq;
|
2024-12-18 12:37:00 +03:00
|
|
|
using Avalonia;
|
2025-01-16 21:07:50 +03:00
|
|
|
using Avalonia.Controls;
|
2024-12-18 12:37:00 +03:00
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
|
using Avalonia.Data.Core.Plugins;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
2024-12-21 13:11:30 +03:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-05-05 20:43:28 +03:00
|
|
|
using Nebula.Launcher.MessageBox;
|
2025-03-14 17:08:35 +03:00
|
|
|
using Nebula.Launcher.ViewModels.ContentView;
|
2024-12-18 12:37:00 +03:00
|
|
|
using Nebula.Launcher.Views;
|
2025-01-05 17:05:23 +03:00
|
|
|
using Nebula.Shared;
|
2024-12-18 12:37:00 +03:00
|
|
|
|
|
|
|
|
namespace Nebula.Launcher;
|
|
|
|
|
|
2025-01-14 22:10:16 +03:00
|
|
|
public class App : Application
|
2024-12-18 12:37:00 +03:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
|
{
|
2025-05-05 20:43:28 +03:00
|
|
|
if (!Program.IsNewInstance)
|
|
|
|
|
{
|
|
|
|
|
IMessageContainerProvider? provider = null;
|
|
|
|
|
switch (ApplicationLifetime)
|
|
|
|
|
{
|
|
|
|
|
case IClassicDesktopStyleApplicationLifetime desktop:
|
|
|
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
|
|
|
desktop.MainWindow = new MessageWindow(out provider);
|
|
|
|
|
break;
|
|
|
|
|
case ISingleViewApplicationLifetime singleViewPlatform:
|
|
|
|
|
singleViewPlatform.MainView = new MessageView(out provider);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
provider?.ShowMessage("Launcher is already running.","hey shithead!");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 21:07:50 +03:00
|
|
|
if (Design.IsDesignMode)
|
2024-12-18 12:37:00 +03:00
|
|
|
{
|
2025-01-16 21:07:50 +03:00
|
|
|
switch (ApplicationLifetime)
|
|
|
|
|
{
|
|
|
|
|
case IClassicDesktopStyleApplicationLifetime desktop:
|
|
|
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
|
|
|
desktop.MainWindow = new MainWindow();
|
|
|
|
|
break;
|
|
|
|
|
case ISingleViewApplicationLifetime singleViewPlatform:
|
|
|
|
|
singleViewPlatform.MainView = new MainView();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
|
services.AddAvaloniaServices();
|
|
|
|
|
services.AddServices();
|
|
|
|
|
services.AddViews();
|
2025-03-14 17:08:35 +03:00
|
|
|
services.AddTransient<DecompilerContentView>();
|
2025-01-16 21:07:50 +03:00
|
|
|
|
|
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
switch (ApplicationLifetime)
|
|
|
|
|
{
|
|
|
|
|
case IClassicDesktopStyleApplicationLifetime desktop:
|
|
|
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
|
|
|
desktop.MainWindow = serviceProvider.GetService<MainWindow>();
|
|
|
|
|
break;
|
|
|
|
|
case ISingleViewApplicationLifetime singleViewPlatform:
|
|
|
|
|
singleViewPlatform.MainView = serviceProvider.GetRequiredService<MainView>();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-12-18 12:37:00 +03:00
|
|
|
}
|
2025-01-16 21:07:50 +03:00
|
|
|
|
2024-12-18 12:37:00 +03:00
|
|
|
|
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisableAvaloniaDataAnnotationValidation()
|
|
|
|
|
{
|
|
|
|
|
// Get an array of plugins to remove
|
|
|
|
|
var dataValidationPluginsToRemove =
|
|
|
|
|
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
|
|
|
|
|
|
|
|
|
// remove each entry found
|
2025-01-14 22:10:16 +03:00
|
|
|
foreach (var plugin in dataValidationPluginsToRemove) BindingPlugins.DataValidators.Remove(plugin);
|
2024-12-18 12:37:00 +03:00
|
|
|
}
|
|
|
|
|
}
|