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; /// /// Provides application-specific behavior to supplement the default Application class. /// public partial class App : Application { public static IServiceProvider Services { get; private set; } private Window? _window; /// /// 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(). /// public App() { InitializeComponent(); Services = ConfigureServices(); } /// /// Configures the services for dependency injection. /// /// 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(); services.AddSingleton(navigationService); // ViewModels services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Views services.AddTransient(); return services.BuildServiceProvider(); } /// /// Invoked when the application is launched. /// /// Details about the launch request and process. 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(); _window.Activate(); } }