From 6401190ec2e4af39b6aa777005df635b4d227c4a Mon Sep 17 00:00:00 2001 From: James Crutchley Date: Sat, 5 Oct 2024 10:34:56 -0700 Subject: [PATCH] Add initial support for Multiple Windows on MacOS --- .../CommunityToolkit.Maui.Sample/App.xaml.cs | 19 ++++++++++++++++++- .../Platforms/MacCatalyst/Info.plist | 17 +++++++++++++++++ .../Platforms/MacCatalyst/SceneDelegate.cs | 12 ++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/SceneDelegate.cs diff --git a/samples/CommunityToolkit.Maui.Sample/App.xaml.cs b/samples/CommunityToolkit.Maui.Sample/App.xaml.cs index 9b356596ed..ea121ffd44 100644 --- a/samples/CommunityToolkit.Maui.Sample/App.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/App.xaml.cs @@ -7,7 +7,24 @@ public partial class App : Application public App() { InitializeComponent(); - MainPage = new AppShell(); } + +#if MACCATALYST + protected override Window CreateWindow(IActivationState? activationState) + { + Window window = base.CreateWindow(activationState); + window.Destroying += (object? sender, EventArgs args) => + { + if (Current?.Windows?.Count - 1 == 0) + { + // Exit the app when the last window closes + // This ensures app closes when last window closes on Mac + Environment.Exit(0); + } + }; + return window; + } + +#endif } \ No newline at end of file diff --git a/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/Info.plist b/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/Info.plist index c342a6fa06..4544a6c5ca 100644 --- a/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/Info.plist +++ b/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/Info.plist @@ -24,6 +24,23 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + __MAUI_DEFAULT_SCENE_CONFIGURATION__ + UISceneDelegateClassName + SceneDelegate + + + + XSAppIconAssets Assets.xcassets/appicon.appiconset NSSpeechRecognitionUsageDescription diff --git a/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/SceneDelegate.cs b/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/SceneDelegate.cs new file mode 100644 index 0000000000..051eaf832e --- /dev/null +++ b/samples/CommunityToolkit.Maui.Sample/Platforms/MacCatalyst/SceneDelegate.cs @@ -0,0 +1,12 @@ +using System; +using Foundation; +using Microsoft.Maui; +using ObjCRuntime; +using UIKit; + +namespace CommunityToolkit.Maui.Sample.Platforms.MacCatalyst; + +[Register("SceneDelegate")] +public class SceneDelegate : MauiUISceneDelegate +{ +}