2026-10-15 01:14:44 +02:00
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
|
|
|
|
|
|
using MeWeb.App.Services;
|
|
|
|
|
using MeWeb.App.ViewModels;
|
|
|
|
|
using MeWeb.App.Views;
|
2026-10-15 04:39:03 +02:00
|
|
|
using MeWeb.Core.Net;
|
2026-10-15 01:14:44 +02:00
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace MeWeb.App;
|
|
|
|
|
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
|
|
|
|
public static IServiceProvider Services { get; private set; }
|
|
|
|
|
|
2026-10-15 04:39:03 +02:00
|
|
|
public static IPlatform Platform { get; set; } = new SystemPlatform();
|
|
|
|
|
|
2026-10-15 01:14:44 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
#if DEBUG
|
|
|
|
|
this.AttachDeveloperTools();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
|
{
|
2026-10-15 04:39:03 +02:00
|
|
|
Services = new ServiceCollection().AddMeWebApp(Platform).BuildServiceProvider();
|
2026-10-15 01:14:44 +02:00
|
|
|
var stored = AppSettings.Read();
|
|
|
|
|
Localizer.Instance.SetLanguage(Languages.Find(stored.Language) ?? Languages.ForCulture(System.Globalization.CultureInfo.CurrentUICulture));
|
|
|
|
|
|
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
|
desktop.MainWindow = new MainWindow { Content = CreateMainView() };
|
|
|
|
|
else if (ApplicationLifetime is IActivityApplicationLifetime activity)
|
|
|
|
|
activity.MainViewFactory = CreateMainView;
|
|
|
|
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime single)
|
|
|
|
|
single.MainView = CreateMainView();
|
|
|
|
|
|
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Control CreateMainView() => new MainView { DataContext = Services.GetRequiredService<MainViewModel>() };
|
|
|
|
|
}
|