// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; 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.Platform.Linux.Converters; using Microsoft.Maui.Storage; using Microsoft.Maui.Platform.Linux.Handlers; using Microsoft.Maui.Controls; using SkiaSharp; 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 type converters for XAML support RegisterTypeConverters(); // Register Linux-specific handlers builder.ConfigureMauiHandlers(handlers => { // Application handler handlers.AddHandler(); // Core controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Layout controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Picker controls handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Progress & Activity handlers.AddHandler(); handlers.AddHandler(); // Image & Graphics handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Collection Views handlers.AddHandler(); handlers.AddHandler(); // Pages & Navigation handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); // Application & Window handlers.AddHandler(); handlers.AddHandler(); }); // Store options for later use builder.Services.AddSingleton(options); return builder; } /// /// Registers custom type converters for Linux platform. /// private static void RegisterTypeConverters() { // Register SkiaSharp type converters for XAML styling support TypeDescriptor.AddAttributes(typeof(SKColor), new TypeConverterAttribute(typeof(SKColorTypeConverter))); TypeDescriptor.AddAttributes(typeof(SKRect), new TypeConverterAttribute(typeof(SKRectTypeConverter))); TypeDescriptor.AddAttributes(typeof(SKSize), new TypeConverterAttribute(typeof(SKSizeTypeConverter))); TypeDescriptor.AddAttributes(typeof(SKPoint), new TypeConverterAttribute(typeof(SKPointTypeConverter))); } } /// /// 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; } }