From 84f1dc75b210acc59bce8c1735a55e64566d2fe8 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 11 Oct 2023 19:18:39 -0700 Subject: [PATCH] Some reformatting --- Avalonia.Maui/AvaloniaAppBuilderExtensions.cs | 64 +++++++++---------- AvaloniaMauiHybrid.sln | 14 ++-- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Avalonia.Maui/AvaloniaAppBuilderExtensions.cs b/Avalonia.Maui/AvaloniaAppBuilderExtensions.cs index d6fc066..5f3d334 100644 --- a/Avalonia.Maui/AvaloniaAppBuilderExtensions.cs +++ b/Avalonia.Maui/AvaloniaAppBuilderExtensions.cs @@ -22,7 +22,7 @@ namespace Avalonia.Maui; public static class AvaloniaAppBuilderExtensions { #if ANDROID - public static AppBuilder UseMaui(this AppBuilder appBuilder, global::Android.App.Activity activity, Action? configure = null) + public static AppBuilder UseMaui(this AppBuilder appBuilder, global::Android.App.Activity activity, Action? configure = null) where TMauiApplication : Microsoft.Maui.Controls.Application #elif IOS public static AppBuilder UseMaui(this AppBuilder appBuilder, IUIApplicationDelegate applicationDelegate, Action? configure = null) @@ -35,14 +35,14 @@ public static AppBuilder UseMaui(this AppBuilder appBuilder, A return appBuilder .AfterSetup(appBuilder => { - var builder = MauiApp.CreateBuilder() - .UseMauiEmbedding(); - + var builder = MauiApp.CreateBuilder() + .UseMauiEmbedding(); + builder.Services.AddSingleton(appBuilder.Instance!) #if ANDROID - .AddSingleton(activity.Application!) - .AddSingleton(activity) - .AddSingleton(activity) + .AddSingleton(activity.Application!) + .AddSingleton(activity) + .AddSingleton(activity) #elif IOS .AddSingleton(applicationDelegate ?? UIApplication.SharedApplication.Delegate) .AddSingleton(static p => p.GetService()!.GetWindow()) @@ -50,7 +50,7 @@ public static AppBuilder UseMaui(this AppBuilder appBuilder, A .AddSingleton(); configure?.Invoke(builder); - + var mauiApp = builder.Build(); InitializeMauiEmbeddingApp(mauiApp); }); @@ -58,16 +58,16 @@ public static AppBuilder UseMaui(this AppBuilder appBuilder, A private static void InitializeMauiEmbeddingApp(this MauiApp mauiApp) { - var iApp = mauiApp.Services.GetRequiredService(); + var iApp = mauiApp.Services.GetRequiredService(); #if ANDROID - var window = mauiApp.Services.GetRequiredService (); - var scope = mauiApp.Services.CreateScope(); - var platformApplication = window.Application!; - var services = scope.ServiceProvider; - var rootContext = new MauiContext(scope.ServiceProvider, window); + var window = mauiApp.Services.GetRequiredService(); + var scope = mauiApp.Services.CreateScope(); + var platformApplication = window.Application!; + var services = scope.ServiceProvider; + var rootContext = new MauiContext(scope.ServiceProvider, window); - Microsoft.Maui.ApplicationModel.Platform.Init(window, null); + Microsoft.Maui.ApplicationModel.Platform.Init(window, null); #else var rootContext = new MauiContext(mauiApp.Services); var services = mauiApp.Services; @@ -87,28 +87,28 @@ private static void InitializeMauiEmbeddingApp(this MauiApp mauiApp) #endif #endif - var scopedServices = rootContext.Services.GetServices(); - foreach (var service in scopedServices) - { - service.Initialize(rootContext.Services); - } + var scopedServices = rootContext.Services.GetServices(); + foreach (var service in scopedServices) + { + service.Initialize(rootContext.Services); + } - platformApplication.SetApplicationHandler(iApp, rootContext); - IPlatformApplication.Current = new EmbeddingApplication(services, iApp); + platformApplication.SetApplicationHandler(iApp, rootContext); + IPlatformApplication.Current = new EmbeddingApplication(services, iApp); - if (iApp is Microsoft.Maui.Controls.Application { Handler.MauiContext: not null } app - && iApp.Windows is List windows) - { - var virtualWindow = CreateVirtualWindow(app, window); - windows.Add(virtualWindow); - } + if (iApp is Microsoft.Maui.Controls.Application { Handler.MauiContext: not null } app + && iApp.Windows is List windows) + { + var virtualWindow = CreateVirtualWindow(app, window); + windows.Add(virtualWindow); + } } - + private static Window CreateVirtualWindow(Microsoft.Maui.Controls.Application app, PlatformWindow? window) { #if ANDROID - var services = app.Handler!.MauiContext!.Services; - var context = new MauiContext(services, services.GetRequiredService()); + var services = app.Handler!.MauiContext!.Services; + var context = new MauiContext(services, services.GetRequiredService()); #else var context = app.Handler.MauiContext; #endif @@ -125,6 +125,6 @@ private static Window CreateVirtualWindow(Microsoft.Maui.Controls.Application ap virtualWindow.Page = new ContentPage(); return virtualWindow; } - + private record EmbeddingApplication(IServiceProvider Services, IApplication Application) : IPlatformApplication; } \ No newline at end of file diff --git a/AvaloniaMauiHybrid.sln b/AvaloniaMauiHybrid.sln index e89e6e3..cc11067 100644 --- a/AvaloniaMauiHybrid.sln +++ b/AvaloniaMauiHybrid.sln @@ -20,11 +20,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AvaloniaSample", "AvaloniaS EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{31E88003-6C5B-41F7-8A36-CBFE095CA760}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaSample", "AvaloniaSample\AvaloniaSample\AvaloniaSample.csproj", "{5B52DC9E-B2D8-444E-8CA7-102FD762675F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaSample", "AvaloniaSample\AvaloniaSample\AvaloniaSample.csproj", "{5B52DC9E-B2D8-444E-8CA7-102FD762675F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaSample.Android", "AvaloniaSample\AvaloniaSample.Android\AvaloniaSample.Android.csproj", "{3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaSample.Android", "AvaloniaSample\AvaloniaSample.Android\AvaloniaSample.Android.csproj", "{3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaSample.iOS", "AvaloniaSample\AvaloniaSample.iOS\AvaloniaSample.iOS.csproj", "{E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaSample.iOS", "AvaloniaSample\AvaloniaSample.iOS\AvaloniaSample.iOS.csproj", "{E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -48,19 +48,18 @@ Global {5B52DC9E-B2D8-444E-8CA7-102FD762675F}.Release|Any CPU.Build.0 = Release|Any CPU {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}.Release|Any CPU.ActiveCfg = Release|Any CPU {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A}.Release|Any CPU.Build.0 = Release|Any CPU {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2803DA96-B1F5-490A-A82B-82C073DE4767} - EndGlobalSection GlobalSection(NestedProjects) = preSolution {D2634557-8A3C-4062-9480-3C6A5A4CC147} = {31E88003-6C5B-41F7-8A36-CBFE095CA760} {10E5B37C-47D1-498B-AD9D-9A281064C091} = {31E88003-6C5B-41F7-8A36-CBFE095CA760} @@ -68,4 +67,7 @@ Global {3CFDDDE4-C90B-48FF-8C95-50F96909BF5A} = {10E5B37C-47D1-498B-AD9D-9A281064C091} {E92818E3-6BFA-4C9E-9481-3BECBACAFF0A} = {10E5B37C-47D1-498B-AD9D-9A281064C091} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2803DA96-B1F5-490A-A82B-82C073DE4767} + EndGlobalSection EndGlobal