From 334c9103229076bcf57052a378856281fe8c8d2a Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 2 Oct 2024 17:28:26 +0200 Subject: [PATCH 1/2] fix: Do not destroy the singleton Window for single-window targets --- .../BaseWindowImplementation.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Window/Implementations/BaseWindowImplementation.cs b/src/Uno.UI/UI/Xaml/Window/Implementations/BaseWindowImplementation.cs index bd64a80fb2..54c2eb8614 100644 --- a/src/Uno.UI/UI/Xaml/Window/Implementations/BaseWindowImplementation.cs +++ b/src/Uno.UI/UI/Xaml/Window/Implementations/BaseWindowImplementation.cs @@ -80,7 +80,7 @@ internal abstract class BaseWindowImplementation : IWindowImplementation public virtual void Activate() { - if (_isClosed) + if (NativeWindowFactory.SupportsMultipleWindows && _isClosed) { throw new InvalidOperationException("Cannot reactivate a closed window."); } @@ -318,10 +318,18 @@ internal abstract class BaseWindowImplementation : IWindowImplementation // Window.PrepareToClose(); - // set these to null before marking window as closed as they fail if called after m_bIsClosed is set - // because they check if window is closed already - Window.SetTitleBar(null); - Window.Content = null; + if (NativeWindowFactory.SupportsMultipleWindows) + { + // set these to null before marking window as closed as they fail if called after m_bIsClosed is set + // because they check if window is closed already + Window.SetTitleBar(null); + Window.Content = null; + } + else + { + // Just reset the window to not shown state so it can be reactivated + _wasShown = false; + } // _windowChrome.SetDesktopWindow(null); @@ -336,8 +344,11 @@ internal abstract class BaseWindowImplementation : IWindowImplementation RaiseWindowVisibilityChangedEvent(false); } - // Close native window, cleanup, and unregister from hwnd mapping from DXamlCore - Shutdown(); + if (NativeWindowFactory.SupportsMultipleWindows) + { + // Close native window, cleanup, and unregister from hwnd mapping from DXamlCore + Shutdown(); + } return true; } From ff0b18352abd8ec4889163f4119b7ea26ce410d9 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 2 Oct 2024 17:40:29 +0200 Subject: [PATCH 2/2] test: Add a manual test for single window close --- .../SingleWindowClose.xaml | 16 +++++++++ .../SingleWindowClose.xaml.cs | 35 +++++++++++++++++++ .../UITests.Shared/UITests.Shared.projitems | 9 ++++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml create mode 100644 src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml.cs diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml b/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml new file mode 100644 index 0000000000..0d0c1726a2 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml @@ -0,0 +1,16 @@ + + + + + + diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml.cs new file mode 100644 index 0000000000..28814d4936 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/SingleWindowClose.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Threading.Tasks; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using SamplesApp; +using Uno.Disposables; +using Uno.UI.Common; +using Uno.UI.Samples.Controls; +using Uno.UI.Samples.UITests.Helpers; +using Windows.Graphics; + +#if !WINDOWS_UWP && !WINAPPSDK +using Uno.UI.Xaml; +using Uno.UI.Xaml.Controls; +using WinUICoreServices = Uno.UI.Xaml.Core.CoreServices; +#endif + +namespace UITests.Microsoft_UI_Windowing; + +[Sample( + "Windowing", + IsManualTest = true, + Description = + "- On Android and iOS, try to back out of this app to the main screen and reopen the app via its icon. " + + "You should see the Samples app UI load normally - not a blank screen and the app should also not crash. \r\n" + + "- On Android and iOS, try to back out of this app and then activate it by opening an URI like uno-samples-test:something. " + + "You should see the Samples app UI load normally - not a blank screen and the app should also not crash. ")] +public sealed partial class SingleWindowClose : Page +{ + public SingleWindowClose() + { + this.InitializeComponent(); + } +} diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems index be9dd1c0e3..64187ccf22 100644 --- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems +++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems @@ -42,6 +42,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -5496,6 +5500,9 @@ AppWindowClosing.xaml + + SingleWindowClose.xaml + OverlappedPresenterTests.xaml @@ -9834,4 +9841,4 @@ - + \ No newline at end of file