Skip to content

Commit

Permalink
Replace deprecated await winrt::apartment_context pattern (#15725)
Browse files Browse the repository at this point in the history
Replace deprecated winrt::apartment_context pattern

I only found 2 instances of this pattern in use and one of them was
actually already replaced but the `co_await winrt::apartment_context`
code was still there.

Tested both window renaming and opening terminal with persisted layouts.
Both still work.

Closes #12982
  • Loading branch information
jamespack committed Jul 20, 2023
1 parent 0e90b85 commit 7fba298
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,6 @@ winrt::fire_and_forget AppHost::_peasantNotifyActivateWindow()
// - The window layout as a json string.
winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> AppHost::_GetWindowLayoutAsync()
{
winrt::apartment_context peasant_thread;

winrt::hstring layoutJson = L"";
// Use the main thread since we are accessing controls.
co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher());
Expand All @@ -974,9 +972,6 @@ winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> AppHost::_GetWindowL
}
CATCH_LOG()

// go back to give the result to the peasant.
co_await peasant_thread;

co_return layoutJson;
}

Expand Down Expand Up @@ -1052,9 +1047,6 @@ void AppHost::_DisplayWindowId(const winrt::Windows::Foundation::IInspectable& /
winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Foundation::IInspectable /*sender*/,
const winrt::TerminalApp::RenameWindowRequestedArgs args)
{
// Capture calling context.
winrt::apartment_context ui_thread;

// Switch to the BG thread - anything x-proc must happen on a BG thread
co_await winrt::resume_background();

Expand All @@ -1064,12 +1056,9 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou

_peasant.RequestRename(requestArgs);

// Switch back to the UI thread. Setting the WindowName needs to happen
// on the UI thread, because it'll raise a PropertyChanged event
co_await ui_thread;

if (requestArgs.Succeeded())
{
co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher());
_windowLogic.WindowName(args.ProposedName());
}
else
Expand Down

0 comments on commit 7fba298

Please sign in to comment.