Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for Multiple Windows on MacOS #2260

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion samples/CommunityToolkit.Maui.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@ public partial class App : Application
public App(AppShell appShell)
{
InitializeComponent();

this.appShell = appShell;
}

#if MACCATALYST
protected override Window CreateWindow(IActivationState? activationState)
{
Window window = base.CreateWindow(activationState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, e.g., on Windows the call is new Window(appShell) and on Mac Catalyst it is base.CreateWindow(activationState).

Is this by design that appShell is not passed in? Again honest question.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a correct thing to do though? I honestly don't know hence the question.

I ask primarily because of this https://superuser.com/questions/53935/getting-mac-os-x-applications-to-close-after-last-window-closed/53940#53940 answer.

}
};
return window;
}

#else
protected override Window CreateWindow(IActivationState? activationState) => new(appShell);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>__MAUI_DEFAULT_SCENE_CONFIGURATION__</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
<key>NSSpeechRecognitionUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
}