Skip to content

Commit

Permalink
Move jumplist creation to background thread (#7978)
Browse files Browse the repository at this point in the history
Move jumplist creation to a background thread, as it
does not need to be on the main thread

Closes #7791
  • Loading branch information
PankajBhojwani authored Oct 23, 2020
1 parent 293ad27 commit 4f39e8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/cascadia/TerminalApp/Jumplist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ static std::wstring_view _getExePath()
// - settings - The settings object to update the jumplist with.
// Return Value:
// - <none>
HRESULT Jumplist::UpdateJumplist(const CascadiaSettings& settings) noexcept
winrt::fire_and_forget Jumplist::UpdateJumplist(const CascadiaSettings& settings) noexcept
{
// make sure to capture the settings _before_ the co_await
const auto strongSettings = settings;

co_await winrt::resume_background();

try
{
auto jumplistInstance = winrt::create_instance<ICustomDestinationList>(CLSID_DestinationList, CLSCTX_ALL);
Expand All @@ -131,24 +136,22 @@ HRESULT Jumplist::UpdateJumplist(const CascadiaSettings& settings) noexcept

// It's easier to clear the list and re-add everything. The settings aren't
// updated often, and there likely isn't a huge amount of items to add.
RETURN_IF_FAILED(jumplistItems->Clear());
THROW_IF_FAILED(jumplistItems->Clear());

// Update the list of profiles.
RETURN_IF_FAILED(_updateProfiles(jumplistItems.get(), settings.Profiles().GetView()));
THROW_IF_FAILED(_updateProfiles(jumplistItems.get(), strongSettings.Profiles().GetView()));

// TODO GH#1571: Add items from the future customizable new tab dropdown as well.
// This could either replace the default profiles, or be added alongside them.

// Add the items to the jumplist Task section.
// The Tasks section is immutable by the user, unlike the destinations
// section that can have its items pinned and removed.
RETURN_IF_FAILED(jumplistInstance->AddUserTasks(jumplistItems.get()));

RETURN_IF_FAILED(jumplistInstance->CommitList());
THROW_IF_FAILED(jumplistInstance->AddUserTasks(jumplistItems.get()));

return S_OK;
THROW_IF_FAILED(jumplistInstance->CommitList());
}
CATCH_RETURN();
CATCH_LOG();
}

// Method Description:
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/Jumplist.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct IShellLinkW;
class Jumplist
{
public:
static HRESULT UpdateJumplist(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) noexcept;
static winrt::fire_and_forget UpdateJumplist(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) noexcept;

private:
[[nodiscard]] static HRESULT _updateProfiles(IObjectCollection* jumplistItems, winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Terminal::Settings::Model::Profile> profiles) noexcept;
Expand Down

0 comments on commit 4f39e8e

Please sign in to comment.