// 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.Controls; using Microsoft.Maui.Devices; using Microsoft.Maui.Dispatching; using Microsoft.Maui.Hosting; using Microsoft.Maui.Networking; using Microsoft.Maui.Platform.Linux.Converters; using Microsoft.Maui.Platform.Linux.Dispatching; using Microsoft.Maui.Platform.Linux.Handlers; using Microsoft.Maui.Platform.Linux.Services; using Microsoft.Maui.Storage; using SkiaSharp; namespace Microsoft.Maui.Platform.Linux.Hosting; public static class LinuxMauiAppBuilderExtensions { public static MauiAppBuilder UseLinux(this MauiAppBuilder builder) { return builder.UseLinux(null); } public static MauiAppBuilder UseLinux(this MauiAppBuilder builder, Action? configure) { var options = new LinuxApplicationOptions(); configure?.Invoke(options); // Register dispatcher provider builder.Services.TryAddSingleton(LinuxDispatcherProvider.Instance); // Register device services builder.Services.TryAddSingleton(DeviceInfoService.Instance); builder.Services.TryAddSingleton(DeviceDisplayService.Instance); builder.Services.TryAddSingleton(AppInfoService.Instance); builder.Services.TryAddSingleton(ConnectivityService.Instance); // 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 theming and accessibility services builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); // Register accessibility service builder.Services.TryAddSingleton(_ => AccessibilityServiceFactory.Instance); // Register input method service builder.Services.TryAddSingleton(_ => InputMethodServiceFactory.Instance); // Register font fallback manager builder.Services.TryAddSingleton(_ => FontFallbackManager.Instance); // Register additional Linux-specific services builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); // Register GTK host service builder.Services.TryAddSingleton(_ => GtkHostService.Instance); // 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(); 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(); // Web - use GtkWebViewHandler handlers.AddHandler(); // Collection Views handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); 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; } private static void RegisterTypeConverters() { 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))); } }