Files
2026-08-22 19:11:00 +03:00

124 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
using WinUI3Localizer;
using WinWARP.Core.Services;
using WinWARP.Core.ViewModels;
using WinWARP.Core.ViewModels.ConfigSettings;
using WinWARP.Core.ViewModels.Settings;
using WinWARP.Ui.Services;
using WinWARP.Ui.Views;
using WinWARP.Ui.Views.Settings;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace WinWARP.Ui;
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
public static IServiceProvider Services
{
get;
private set;
}
private Window? _window;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
Services = ConfigureServices();
}
/// <summary>
/// Configures the services for dependency injection.
/// </summary>
/// <returns></returns>
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
var navigationService = new NavigationService();
navigationService.Configure(typeof(HomeViewModel), typeof(HomePage));
navigationService.Configure(typeof(SettingsViewModel), typeof(SettingsPage));
navigationService.Configure(typeof(SubsSettingsViewModel), typeof(SubsSettingsPage));
navigationService.Configure(typeof(ConfigSettingsViewModel), typeof(ConfigSettingsPage));
navigationService.Configure(typeof(GeneralSettingsViewModel), typeof(GeneralSettingsPage));
navigationService.Configure(typeof(UpdateSettingsViewModel), typeof(UpdateSettingsPage));
navigationService.Configure(typeof(InboundSettingsViewModel), typeof(InboundSettingsPage));
navigationService.Configure(typeof(RoutingSettingsViewModel), typeof(RoutingSettingsPage));
navigationService.Configure(typeof(DnsSettingsViewModel), typeof(DnsSettingsPage));
navigationService.Configure(typeof(TlsSettingsViewModel), typeof(TlsSettingsPage));
navigationService.Configure(typeof(WarpSettingsViewModel), typeof(WarpSettingsPage));
services.AddSingleton<ILocalizationService, LocalizationService>();
services.AddSingleton<INavigationService>(navigationService);
// ViewModels
services.AddTransient<HomeViewModel>();
services.AddTransient<SettingsViewModel>();
services.AddTransient<SubsSettingsViewModel>();
services.AddTransient<ConfigSettingsViewModel>();
services.AddSingleton<MainViewModel>();
services.AddTransient<DnsSettingsViewModel>();
services.AddTransient<GeneralSettingsViewModel>();
services.AddTransient<InboundSettingsViewModel>();
services.AddTransient<RoutingSettingsViewModel>();
services.AddTransient<TlsSettingsViewModel>();
services.AddTransient<WarpSettingsViewModel>();
// Views
services.AddTransient<MainWindow>();
return services.BuildServiceProvider();
}
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var stringsFolderPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Strings");
ILocalizer localizer = await new LocalizerBuilder()
.AddStringResourcesFolderForLanguageDictionaries(stringsFolderPath)
.SetOptions(options =>
{
options.DefaultLanguage = "en-US";
})
.Build();
_window = Services.GetRequiredService<MainWindow>();
_window.Activate();
}
}