feat: improve Windows Toast actions support (#49786)

* feat: improve Windows Toast actions support

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* fix: ensure MSIX compatibility

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* test: add bad clsid format test

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2026-02-18 13:22:10 -05:00
committed by GitHub
parent c7a033dd06
commit 3d475716f4
20 changed files with 1004 additions and 60 deletions

View File

@@ -32,6 +32,8 @@ PCWSTR GetRawAppUserModelID();
bool GetAppUserModelID(ScopedHString* app_id);
void SetAppUserModelID(const std::wstring& name);
bool IsRunningInDesktopBridge();
PCWSTR GetAppToastActivatorCLSID();
void SetAppToastActivatorCLSID(const std::wstring& clsid);
#endif
} // namespace electron

View File

@@ -28,6 +28,11 @@ std::wstring& GetAppUserModelId() {
return *g_app_user_model_id;
}
std::wstring& GetToastActivatorCLSID() {
static base::NoDestructor<std::wstring> g_toast_activator_clsid;
return *g_toast_activator_clsid;
}
std::string GetApplicationName() {
auto* module = GetModuleHandle(nullptr);
std::unique_ptr<FileVersionInfo> info(
@@ -82,4 +87,37 @@ bool IsRunningInDesktopBridge() {
return result;
}
PCWSTR GetAppToastActivatorCLSID() {
if (GetToastActivatorCLSID().empty()) {
GUID guid;
if (SUCCEEDED(::CoCreateGuid(&guid))) {
wchar_t buf[64] = {0};
if (StringFromGUID2(guid, buf, std::size(buf)) > 0)
GetToastActivatorCLSID() = buf;
}
}
return GetToastActivatorCLSID().c_str();
}
void SetAppToastActivatorCLSID(const std::wstring& clsid) {
CLSID parsed;
if (SUCCEEDED(::CLSIDFromString(clsid.c_str(), &parsed))) {
// Normalize formatting.
wchar_t buf[64] = {0};
if (StringFromGUID2(parsed, buf, std::size(buf)) > 0)
GetToastActivatorCLSID() = buf;
} else {
// Try adding braces if user omitted them.
if (!clsid.empty() && clsid.front() != L'{') {
std::wstring with_braces = L"{" + clsid + L"}";
if (SUCCEEDED(::CLSIDFromString(with_braces.c_str(), &parsed))) {
wchar_t buf[64] = {0};
if (StringFromGUID2(parsed, buf, std::size(buf)) > 0)
GetToastActivatorCLSID() = buf;
}
}
}
}
} // namespace electron