mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user