// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.ApplicationModel.Communication; using Microsoft.Maui.ApplicationModel.DataTransfer; using Microsoft.Maui.Hosting; using Microsoft.Maui.Platform.Linux.Services; using Microsoft.Maui.Storage; using Microsoft.Maui.Platform.Linux.Handlers; using Microsoft.Maui.Controls; namespace Microsoft.Maui.Platform.Linux.Hosting; /// /// Extension methods for configuring MAUI applications for Linux. /// public static class LinuxMauiAppBuilderExtensions { /// /// Configures the MAUI application to run on Linux. /// public static MauiAppBuilder UseLinux(this MauiAppBuilder builder) { return builder.UseLinux(configure: null); } /// /// Configures the MAUI application to run on Linux with options. /// public static MauiAppBuilder UseLinux(this MauiAppBuilder builder, Action? configure) { var options = new LinuxApplicationOptions(); configure?.Invoke(options); // Register platform services builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); // Register Linux-specific handlers builder.ConfigureMauiHandlers(handlers => { // Phase 1 - MVP controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Phase 2 - Input controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Phase 2 - Image & Graphics handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Phase 3 - Collection Views handlers.AddHandler(); // Phase 4 - Pages & Navigation handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Phase 5 - Advanced Controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Phase 7 - Additional Controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Window handler handlers.AddHandler(); }); // Store options for later use builder.Services.AddSingleton(options); return builder; } } /// /// Handler registration extensions. /// public static class HandlerMappingExtensions { /// /// Adds a handler for the specified view type. /// public static IMauiHandlersCollection AddHandler( this IMauiHandlersCollection handlers) where TView : class where THandler : class { handlers.AddHandler(typeof(TView), typeof(THandler)); return handlers; } }