Skip to content

Commit

Permalink
Backport the DefTerm SUI stability fix from #13160
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Jun 30, 2022
1 parent 9165c00 commit 78cda41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <shellapi.h>
#include <shlwapi.h>
#include <til/latch.h>

using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings;
Expand Down Expand Up @@ -1120,12 +1121,27 @@ void CascadiaSettings::CurrentDefaultTerminal(const Model::DefaultTerminal& term
// but in the future it might be worthwhile to change the code to use list indices instead.
void CascadiaSettings::_refreshDefaultTerminals()
{
if (!_defaultTerminals)
if (_defaultTerminals)
{
auto [defaultTerminals, defaultTerminal] = DefaultTerminal::Available();
_defaultTerminals = winrt::single_threaded_observable_vector(std::move(defaultTerminals));
_currentDefaultTerminal = std::move(defaultTerminal);
return;
}

// This is an extract of extractValueFromTaskWithoutMainThreadAwait
// as DefaultTerminal::Available creates the exact same issue.
std::pair<std::vector<Model::DefaultTerminal>, Model::DefaultTerminal> result{ {}, nullptr };
til::latch latch{ 1 };

std::ignore = [&]() -> winrt::fire_and_forget {
const auto cleanup = wil::scope_exit([&]() {
latch.count_down();
});
co_await winrt::resume_background();
result = DefaultTerminal::Available();
}();

latch.wait();
_defaultTerminals = winrt::single_threaded_observable_vector(std::move(result.first));
_currentDefaultTerminal = std::move(result.second);
}

void CascadiaSettings::ExportFile(winrt::hstring path, winrt::hstring content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ static auto extractValueFromTaskWithoutMainThreadAwait(TTask&& task) -> decltype
til::latch latch{ 1 };

const auto _ = [&]() -> winrt::fire_and_forget {
const auto cleanup = wil::scope_exit([&]() {
latch.count_down();
});
co_await winrt::resume_background();
finalVal.emplace(co_await task);
latch.count_down();
}();

latch.wait();
Expand Down

0 comments on commit 78cda41

Please sign in to comment.