Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,29 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
__assume(false);
}

// When running without package identity, set an explicit AppUserModelID so
// that toast notifications (and other shell features like taskbar grouping)
// work correctly. We include a hash of the executable path to prevent
// crosstalk between different portable/unpackaged installations — the same
// isolation strategy used for the single-instance mutex above.
if (!IsPackaged())
{
std::wstring aumid;
#if defined(WT_BRANDING_RELEASE)
aumid = L"Microsoft.WindowsTerminal";
#elif defined(WT_BRANDING_PREVIEW)
aumid = L"Microsoft.WindowsTerminalPreview";
#elif defined(WT_BRANDING_CANARY)
aumid = L"Microsoft.WindowsTerminalCanary";
#else
aumid = L"Microsoft.WindowsTerminalDev";
#endif
const auto path = wil::QueryFullProcessImageNameW<std::wstring>();
const auto hash = til::hash(path);
fmt::format_to(std::back_inserter(aumid), FMT_COMPILE(L".{:016x}"), hash);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do on x86? just have a bunch of 0s in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

til::hash returns a size_t, so {:016x} would have the first 8 digits be 0s.

That said, I added the #ifdef _WIN64 branches for consistency with the other places that's done in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this up, before the GetCurrentProcessToken block, couldn't you just use the windowClassName as an argument to SetCurrentProcessExplicitAppUserModelID?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this! We wouldn't be able to use the windowClassName as the AUMID because it can't contain spaces (reference).

That said, I can reuse the ifdefs to set the aumid, IsPackaged() check, and hash. Making the change now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also just remove the spaces from the window class! It bears no real meaning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with having them be separate for now.

LOG_IF_FAILED(SetCurrentProcessExplicitAppUserModelID(aumid.c_str()));
}

_app = winrt::TerminalApp::App{};
_app.Logic().ReloadSettings();

Expand Down
Loading