diff --git a/dep/nuget/packages.config b/dep/nuget/packages.config index ffa247ab5d9..0a62482b487 100644 --- a/dep/nuget/packages.config +++ b/dep/nuget/packages.config @@ -2,7 +2,6 @@ - diff --git a/scratch/ScratchIslandApp/SampleApp/App.cpp b/scratch/ScratchIslandApp/SampleApp/App.cpp index 5a2ae523f61..2b1df560e6c 100644 --- a/scratch/ScratchIslandApp/SampleApp/App.cpp +++ b/scratch/ScratchIslandApp/SampleApp/App.cpp @@ -12,19 +12,12 @@ using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Controls; using namespace winrt::Windows::UI::Xaml::Navigation; +namespace xaml = ::winrt::Windows::UI::Xaml; + namespace winrt::SampleApp::implementation { App::App() { - // This is the same trick that Initialize() is about to use to figure out whether we're coming - // from a UWP context or from a Win32 context - // See https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/blob/52611c57d89554f357f281d0c79036426a7d9257/Microsoft.Toolkit.Win32.UI.XamlApplication/XamlApplication.cpp#L42 - const auto dispatcherQueue = ::winrt::Windows::System::DispatcherQueue::GetForCurrentThread(); - if (dispatcherQueue) - { - _isUwp = true; - } - Initialize(); // Disable XAML's automatic backplating of text when in High Contrast @@ -33,6 +26,44 @@ namespace winrt::SampleApp::implementation HighContrastAdjustment(::winrt::Windows::UI::Xaml::ApplicationHighContrastAdjustment::None); } + void App::Initialize() + { + const auto dispatcherQueue = winrt::Windows::System::DispatcherQueue::GetForCurrentThread(); + if (!dispatcherQueue) + { + _windowsXamlManager = xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); + } + else + { + _isUwp = true; + } + } + + void App::Close() + { + if (_bIsClosed) + { + return; + } + + _bIsClosed = true; + + if (_windowsXamlManager) + { + _windowsXamlManager.Close(); + } + _windowsXamlManager = nullptr; + + Exit(); + { + MSG msg = {}; + while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) + { + ::DispatchMessageW(&msg); + } + } + } + SampleAppLogic App::Logic() { static SampleAppLogic logic; diff --git a/scratch/ScratchIslandApp/SampleApp/App.h b/scratch/ScratchIslandApp/SampleApp/App.h index fb6235d7538..9debfd86a25 100644 --- a/scratch/ScratchIslandApp/SampleApp/App.h +++ b/scratch/ScratchIslandApp/SampleApp/App.h @@ -12,12 +12,22 @@ namespace winrt::SampleApp::implementation { public: App(); + void Initialize(); + void Close(); void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&); + bool IsDisposed() const + { + return _bIsClosed; + } + SampleApp::SampleAppLogic Logic(); private: bool _isUwp = false; + winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _windowsXamlManager = nullptr; + winrt::Windows::Foundation::Collections::IVector _providers = winrt::single_threaded_vector(); + bool _bIsClosed = false; }; } diff --git a/scratch/ScratchIslandApp/SampleApp/App.idl b/scratch/ScratchIslandApp/SampleApp/App.idl index e51a73332fc..9a8e1affed0 100644 --- a/scratch/ScratchIslandApp/SampleApp/App.idl +++ b/scratch/ScratchIslandApp/SampleApp/App.idl @@ -7,10 +7,12 @@ namespace SampleApp { // ADD ARBITRARY APP LOGIC TO SampleAppLogic.idl, NOT HERE. // This is for XAML platform setup only. - [default_interface] runtimeclass App : Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication + [default_interface] runtimeclass App : Windows.UI.Xaml.Application, Windows.Foundation.IClosable { App(); SampleAppLogic Logic { get; }; + + Boolean IsDisposed { get; }; } } diff --git a/scratch/ScratchIslandApp/SampleApp/App.xaml b/scratch/ScratchIslandApp/SampleApp/App.xaml index c6a2328f41a..42a5ee18884 100644 --- a/scratch/ScratchIslandApp/SampleApp/App.xaml +++ b/scratch/ScratchIslandApp/SampleApp/App.xaml @@ -2,20 +2,19 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> - + - + @@ -67,5 +66,5 @@ - - + + diff --git a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj index 8e06424ce8f..478fbeac206 100644 --- a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj +++ b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj @@ -20,7 +20,6 @@ true - true @@ -128,6 +127,16 @@ false false + + + true + false + $(TargetPlatformMoniker) + $(TargetPlatformDisplayName) + CppWinRTImplicitlyExpandTargetPlatform + True + + diff --git a/scratch/ScratchIslandApp/SampleApp/dll/SampleApp.vcxproj b/scratch/ScratchIslandApp/SampleApp/dll/SampleApp.vcxproj index f1a5c8968bf..105ac1cf4bf 100644 --- a/scratch/ScratchIslandApp/SampleApp/dll/SampleApp.vcxproj +++ b/scratch/ScratchIslandApp/SampleApp/dll/SampleApp.vcxproj @@ -13,7 +13,6 @@ true - true diff --git a/scratch/ScratchIslandApp/SampleApp/pch.h b/scratch/ScratchIslandApp/SampleApp/pch.h index ba01e45e453..dbb486ab751 100644 --- a/scratch/ScratchIslandApp/SampleApp/pch.h +++ b/scratch/ScratchIslandApp/SampleApp/pch.h @@ -46,7 +46,6 @@ #include "winrt/Windows.UI.Xaml.Markup.h" #include "winrt/Windows.UI.ViewManagement.h" -#include #include #include #include diff --git a/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj b/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj index 4d9ec0ab83f..cff561b9608 100644 --- a/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj +++ b/src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj @@ -23,7 +23,6 @@ - true diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp index 4d7e5f93763..138d4a7d249 100644 --- a/src/cascadia/TerminalApp/App.cpp +++ b/src/cascadia/TerminalApp/App.cpp @@ -12,19 +12,12 @@ using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Controls; using namespace winrt::Windows::UI::Xaml::Navigation; +namespace xaml = ::winrt::Windows::UI::Xaml; + namespace winrt::TerminalApp::implementation { App::App() { - // This is the same trick that Initialize() is about to use to figure out whether we're coming - // from a UWP context or from a Win32 context - // See https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/blob/52611c57d89554f357f281d0c79036426a7d9257/Microsoft.Toolkit.Win32.UI.XamlApplication/XamlApplication.cpp#L42 - const auto dispatcherQueue = ::winrt::Windows::System::DispatcherQueue::GetForCurrentThread(); - if (dispatcherQueue) - { - _isUwp = true; - } - Initialize(); // Disable XAML's automatic backplating of text when in High Contrast @@ -33,12 +26,50 @@ namespace winrt::TerminalApp::implementation HighContrastAdjustment(::winrt::Windows::UI::Xaml::ApplicationHighContrastAdjustment::None); } + void App::Initialize() + { + const auto dispatcherQueue = winrt::Windows::System::DispatcherQueue::GetForCurrentThread(); + if (!dispatcherQueue) + { + _windowsXamlManager = xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); + } + else + { + _isUwp = true; + } + } + AppLogic App::Logic() { static AppLogic logic; return logic; } + void App::Close() + { + if (_bIsClosed) + { + return; + } + + _bIsClosed = true; + + if (_windowsXamlManager) + { + _windowsXamlManager.Close(); + } + _windowsXamlManager = nullptr; + + Exit(); + { + MSG msg = {}; + while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) + { + ::DispatchMessageW(&msg); + } + } + } + /// /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. diff --git a/src/cascadia/TerminalApp/App.h b/src/cascadia/TerminalApp/App.h index 259d317553b..830c762f178 100644 --- a/src/cascadia/TerminalApp/App.h +++ b/src/cascadia/TerminalApp/App.h @@ -5,6 +5,7 @@ #include "App.g.h" #include "App.base.h" +#include namespace winrt::TerminalApp::implementation { @@ -13,11 +14,22 @@ namespace winrt::TerminalApp::implementation public: App(); void OnLaunched(const Windows::ApplicationModel::Activation::LaunchActivatedEventArgs&); + void Initialize(); TerminalApp::AppLogic Logic(); + void Close(); + + bool IsDisposed() const + { + return _bIsClosed; + } + private: bool _isUwp = false; + winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _windowsXamlManager = nullptr; + winrt::Windows::Foundation::Collections::IVector _providers = winrt::single_threaded_vector(); + bool _bIsClosed = false; }; } diff --git a/src/cascadia/TerminalApp/App.idl b/src/cascadia/TerminalApp/App.idl index 5e000c5a182..516442148cd 100644 --- a/src/cascadia/TerminalApp/App.idl +++ b/src/cascadia/TerminalApp/App.idl @@ -7,10 +7,12 @@ namespace TerminalApp { // ADD ARBITRARY APP LOGIC TO AppLogic.idl, NOT HERE. // This is for XAML platform setup only. - [default_interface] runtimeclass App : Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication + [default_interface] runtimeclass App : Windows.UI.Xaml.Application, Windows.Foundation.IClosable { App(); AppLogic Logic { get; }; + + Boolean IsDisposed { get; }; } } diff --git a/src/cascadia/TerminalApp/App.xaml b/src/cascadia/TerminalApp/App.xaml index 3da02dff31a..36a3a1be075 100644 --- a/src/cascadia/TerminalApp/App.xaml +++ b/src/cascadia/TerminalApp/App.xaml @@ -2,20 +2,19 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> - + - + @@ -202,5 +201,5 @@ - - + + diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 511152775f2..6123f0de1c3 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -19,7 +19,6 @@ true - true true @@ -382,6 +381,14 @@ false false + + true + false + $(TargetPlatformMoniker) + $(TargetPlatformDisplayName) + CppWinRTImplicitlyExpandTargetPlatform + True + diff --git a/src/cascadia/TerminalApp/dll/TerminalApp.vcxproj b/src/cascadia/TerminalApp/dll/TerminalApp.vcxproj index ea5aa2c2bc7..3bee808b96b 100644 --- a/src/cascadia/TerminalApp/dll/TerminalApp.vcxproj +++ b/src/cascadia/TerminalApp/dll/TerminalApp.vcxproj @@ -14,7 +14,6 @@ true - true true diff --git a/src/cascadia/TerminalApp/pch.h b/src/cascadia/TerminalApp/pch.h index 9946783ab83..a7805b89a4a 100644 --- a/src/cascadia/TerminalApp/pch.h +++ b/src/cascadia/TerminalApp/pch.h @@ -50,7 +50,6 @@ #include #include -#include #include #include #include diff --git a/src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj b/src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj index 1172c8bab45..cd555c70499 100644 --- a/src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj +++ b/src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj @@ -18,7 +18,6 @@ true - true true true true diff --git a/src/common.nugetversions.props b/src/common.nugetversions.props index 76c1de8a65d..c6945b5d5eb 100644 --- a/src/common.nugetversions.props +++ b/src/common.nugetversions.props @@ -6,9 +6,6 @@ - - - $(MSBuildThisFileDirectory)..\packages\Microsoft.Taef.10.60.210621002 diff --git a/src/common.nugetversions.targets b/src/common.nugetversions.targets index 08a695e8156..78c37d86330 100644 --- a/src/common.nugetversions.targets +++ b/src/common.nugetversions.targets @@ -40,9 +40,6 @@ - - - @@ -79,10 +76,6 @@ - - - -