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
MacCatalyst app launches multiple windows if previous launch had multiple windows open #10939
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
This is a "feature" of macOS, but will need to see why if the app was already running and the code for saving things is not specified it still felt the need to restore windows... Maybe just the act of overriding things causes this... @Redth any gut feelings on things to look at first? |
There's a few things happening here and I don't think there's actually a bug, but rather a few misunderstandings of how things work. First of all, MacCatalyst is a bit tough to test some of these states in because what you're effectively doing in the repro here by launching the app and then debugging in visual studio is causing the existing instance of the app to be forcefully terminated, in which case each MAUI Window instance doesn't have the opportunity to gracefully save out its state so that it can properly restore the window next launch. One thing I could see us doing is potentially trying to provide access to the window state sooner than just in the Next, in order to properly handle multi window scenarios successfully on both MacCatalyst and iPad, you need to do a couple of things:
The tricky part here is that on MacCatalyst and iPadOS, the OS may ask you to restore a given Scene at any time, even if you did not initiate the window create call yourself. This history can persist across process boundaries too. When this happens you can't really say 'no', and you will need to return a window of some type. What you do have control over is the state persisted when your window goes into the background, so be sure you save out enough information to rebuild a given window when asked. |
Looking more closely at MAUI's scene delegate implementation, I don't see how you would actually be able to persist state in the case where the app is forcefully terminated. My guess is that some apps might do better in these cases because they might have multiple scene identifiers registered, so at least they might know the type of window they will be opening. It's also possible to more proactively save out your own state however you choose to do so. You might keep a state of the active 'stack' of windows for example and their states once they are opened, and then as you are asked to CreateWindow you could 'pop' window state off your stack and arbitrarily assign windows to own that state. I don't think there's much more we can reasonably easily do at the moment to mitigate forceful process terminations not having saved state in such a global fashion, and if that becomes critically important for someone's app, they will need to invest a bit more in proactive state management. |
Description
Under MacCatalyst if your app can launch multiple windows then upon relaunch (ex after a crash) then the app will reload with the same number of windows, all of which are a copy of the initial launch window.
As you can see here we have 3 windows. The main window has 2 buttons, the other 2 are blank
After launching the app under visual studio you can see that it reopened with 3 windows, all being the starting window
Steps to Reproduce
Create a sample MAUI app that can launch Multi windows
Build in visual studio
Launch app from macCatalyst build folder
Open Multiple windows
Leave app open
Launch app via Visual Studio
You will see the app open with multiple windows
Link to public reproduction project repository
https://github.com/hjharvey-MSFT/MauiMultiWindowSample
Version with bug
6.0.419
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
MacCatalyst
Did you find any workaround?
Override the App.cs Create window method. Check if a window exists, if it does, then close it
this ensures that only 1 window is open on launch, but it isnt ideal. I would prefer a way to block the window from being created to begin with, or stop it at the Scene delegate level, but nothing else I tried worked.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: