From 13b2a048f3915fdbade33826628839e39db9067c Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Mon, 18 Nov 2024 17:28:06 +0530 Subject: [PATCH 01/19] testing changes --- WindowsAppRuntime.sln | 17 +++ .../BadgeNotificationManager.cpp | 108 ++++++++++++++++++ .../BadgeNotificationManager.h | 59 ++++++++++ .../BadgeNotifications/BadgeNotifications.idl | 50 ++++++++ .../BadgeNotifications.vcxitems | 22 ++++ .../BaseNotifications.vcxitems | 16 +++ .../WindowsAppRuntime_DLL.vcxproj | 2 + 7 files changed, 274 insertions(+) create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotificationManager.h create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotifications.idl create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems create mode 100644 dev/Notifications/BaseNotifications/BaseNotifications.vcxitems diff --git a/WindowsAppRuntime.sln b/WindowsAppRuntime.sln index 266ae49a34..19b83a4eaf 100644 --- a/WindowsAppRuntime.sln +++ b/WindowsAppRuntime.sln @@ -566,6 +566,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IXP", "IXP", "{7B323048-439 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IXP.TransportPackage.PackageReference", "eng\PackageReference\IXP\IXP.TransportPackage.PackageReference.csproj", "{A949149D-29CA-4AA7-B1ED-0E571B4AD9BB}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notifications", "Notifications", "{43FE6980-3E16-4EF9-A3DE-29B402FB4FAB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BaseNotifications", "BaseNotifications", "{586EA218-74C8-420B-B47E-0B307AA4B82D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BadgeNotifications", "BadgeNotifications", "{50205ED9-0E08-4878-B124-9AC0EBA138D6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BadgeNotifications", "dev\Notifications\BadgeNotifications\BadgeNotifications.vcxitems", "{85D111C7-B720-4E19-A56D-03C87B953983}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseNotifications", "dev\Notifications\BaseNotifications\BaseNotifications.vcxitems", "{2BD7A1BB-D3D8-484F-9180-409D781DCCF9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -2181,6 +2191,11 @@ Global {D5958784-4518-44F1-A518-80514B380ED5} = {E24C263A-DE3E-4844-BA50-842DA5AD7A49} {7B323048-439F-47E9-A3D4-7342C5ADE2A5} = {5C88AE1D-AC20-4A41-9299-1EEA15B80724} {A949149D-29CA-4AA7-B1ED-0E571B4AD9BB} = {7B323048-439F-47E9-A3D4-7342C5ADE2A5} + {43FE6980-3E16-4EF9-A3DE-29B402FB4FAB} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A} + {586EA218-74C8-420B-B47E-0B307AA4B82D} = {43FE6980-3E16-4EF9-A3DE-29B402FB4FAB} + {50205ED9-0E08-4878-B124-9AC0EBA138D6} = {43FE6980-3E16-4EF9-A3DE-29B402FB4FAB} + {85D111C7-B720-4E19-A56D-03C87B953983} = {50205ED9-0E08-4878-B124-9AC0EBA138D6} + {2BD7A1BB-D3D8-484F-9180-409D781DCCF9} = {586EA218-74C8-420B-B47E-0B307AA4B82D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4B3D7591-CFEC-4762-9A07-ABE99938FB77} @@ -2188,6 +2203,7 @@ Global GlobalSection(SharedMSBuildProjectFiles) = preSolution test\inc\inc.vcxitems*{08bc78e0-63c6-49a7-81b3-6afc3deac4de}*SharedItemsImports = 4 dev\PushNotifications\PushNotifications.vcxitems*{103c0c23-7ba8-4d44-a63c-83488e2e3a81}*SharedItemsImports = 9 + dev\Notifications\BaseNotifications\BaseNotifications.vcxitems*{2bd7a1bb-d3d8-484f-9180-409d781dccf9}*SharedItemsImports = 9 dev\EnvironmentManager\API\Microsoft.Process.Environment.vcxitems*{2f3fad1b-d3df-4866-a3a3-c2c777d55638}*SharedItemsImports = 9 dev\OAuth\OAuth.vcxitems*{3e7fd510-8b66-40e7-a80b-780cb8972f83}*SharedItemsImports = 9 test\inc\inc.vcxitems*{412d023e-8635-4ad2-a0ea-e19e08d36915}*SharedItemsImports = 4 @@ -2198,6 +2214,7 @@ Global test\inc\inc.vcxitems*{7c502995-59c3-483b-86ba-815985353633}*SharedItemsImports = 4 dev\ApplicationData\ApplicationData.vcxitems*{7cf52890-56fa-47e2-84fb-68ee274324b6}*SharedItemsImports = 9 dev\BackgroundTask\BackgroundTaskBuilder\BackgroundTaskBuilder.vcxitems*{858fa9a9-f822-4b98-84a1-fe44e2c00a5d}*SharedItemsImports = 9 + dev\Notifications\BadgeNotifications\BadgeNotifications.vcxitems*{85d111c7-b720-4e19-a56d-03c87b953983}*SharedItemsImports = 9 dev\Common\Common.vcxitems*{8828053c-d6ec-4744-8624-f8c676c2d4df}*SharedItemsImports = 9 dev\Licensing\Licensing.vcxitems*{885a43fa-052d-4b0d-a2dc-13ee15796435}*SharedItemsImports = 9 dev\PackageManager\API\PackageManager.vcxitems*{8a9a0c85-65a8-4bca-a49e-45fc4fdbc7d2}*SharedItemsImports = 9 diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp new file mode 100644 index 0000000000..afefb84e95 --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" +#include "BadgeNotificationManager.h" +#include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.cpp" +#include +#include +#include +#include "externs.h" +#include "PushNotificationUtility.h" +#include "AppNotificationUtility.h" +#include +#include +#include +#include "NotificationProperties.h" +#include "NotificationTransientProperties.h" +#include "AppNotification.h" +#include +#include "AppNotificationTelemetry.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std::literals; + +namespace winrt +{ + using namespace winrt::Windows::UI; + using namespace winrt::Windows::Foundation; + using namespace winrt::Windows::Foundation::Collections; + using namespace winrt::Microsoft::Windows::AppNotifications; + using namespace Windows::ApplicationModel::Core; +} + +namespace ToastABI +{ + using namespace ::ABI::Microsoft::Internal::ToastNotifications; + using namespace ::ABI::Windows::Foundation::Collections; +} + +namespace PushNotificationHelpers +{ + using namespace winrt::Microsoft::Windows::PushNotifications::Helpers; +} + +using namespace Microsoft::Windows::AppNotifications::Helpers; +using namespace Microsoft::Windows::AppNotifications::ShellLocalization; + +namespace winrt::Microsoft::Windows::AppNotifications::implementation +{ + BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} + + winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager BadgeNotificationManager::Current() + { + auto appProperties{ winrt::CoreApplication::Properties() }; + + static wil::srwlock lock; + + auto criticalSection{ lock.lock_exclusive() }; + auto storedBadgeNotificationManager{ appProperties.TryLookup(STORED_APPNOTIFICATION_MANAGER_KEY) }; + if (storedBadgeNotificationManager) + { + return storedBadgeNotificationManager.as(); + } + else + { + // Need to clear the RoActivateInstance caching for the PushNotificationLongRunningProcess proxyStub to be found. + ::Microsoft::RoApi::ClearRoActivateInstanceCache(); + + // Store the BadgeNotificationManager in the COM static store + auto BadgeNotificationManager{ winrt::make() }; + appProperties.Insert(STORED_APPNOTIFICATION_MANAGER_KEY, BadgeNotificationManager); + return BadgeNotificationManager; + } + } + + void SetBadgeAsCount(uint32_t notificationCount) + { + return; + } + + void SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) + { + return; + } + + void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue) + { + return; + } + + void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration) + { + return; + } + + void ClearBadge() + { + return; + } +} diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h new file mode 100644 index 0000000000..9371daadff --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation and Contributors. All rights reserved. +// Licensed under the MIT License. + +#pragma once +#include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.h" +#include "externs.h" +#include "ShellLocalization.h" + +namespace winrt::Microsoft::Windows::BadgeNotifications::implementation +{ + struct BadgeNotificationManager : BadgeNotificationManagerT + { + BadgeNotificationManager(); + + static winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager Current(); + + void SetBadgeAsCount(uint32_t notificationCount); + void SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration); + + void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue); + void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration); + + void ClearBadge(); + + private: + wil::srwlock m_lock; + std::wstring m_processName; + std::wstring m_appId; + }; + + struct BadgeNotificationManagerFactory : winrt::implements + { + STDMETHODIMP CreateInstance(_In_opt_ IUnknown* aggregateInterface, _In_ REFIID interfaceId, _Outptr_ VOID** object) noexcept final try + { + RETURN_HR_IF(CLASS_E_NOAGGREGATION, aggregateInterface != nullptr); + return BadgeNotificationManager::Current().as(interfaceId, object); + } + CATCH_RETURN() + + STDMETHODIMP LockServer(BOOL fLock) noexcept final + { + if (fLock) + { + ++winrt::get_module_lock(); + } + else + { + --winrt::get_module_lock(); + } + return S_OK; + } + }; +} +namespace winrt::Microsoft::Windows::BadgeNotifications::factory_implementation +{ + struct BadgeNotificationManager : BadgeNotificationManagerT + { + }; +} diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.idl b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl new file mode 100644 index 0000000000..225a739171 --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +namespace Microsoft.Windows.BadgeNotifications +{ + [contractversion(1)] + apicontract BadgeNotificationsContract {}; + + // Set of predefined glyphs that can be used to represent various statuses or notifications on an application's badge + [contract(BadgeNotificationsContract, 1)] + enum BadgeNotificationGlyph + { + None, // No glyph. A blank tile appears in the badge. + Activity, // A glyph representing an activity + Alarm, // A glyph representing an alarm + Alert, // A glyph representing an alert + Attention, // A glyph representing attention + Available, // A glyph representing availability + Away, // A glyph representing being away + Busy, // A glyph representing being busy + Error, // A glyph representing an error + NewMessage, // A glyph representing a new message + Paused, // A glyph representing being paused + Playing, // A glyph representing playing + Unavailable, // A glyph representing being unavailable + }; + + // The manager class which encompasses all Badge Notification API Functionality + [contract(BadgeNotificationsContract, 1)] + runtimeclass BadgeNotificationManager + { + // Gets a Default instance of a BadgeNotificationManager + static BadgeNotificationManager Current{ get; }; + + // Updates the badge on the app's tile to display a numeric value. + void SetBadgeAsCount(UInt32 notificationCount); + + // Updates the badge on the app's tile to display a numeric value with an expiration time. + void SetBadgeAsCount(UInt32 notificationCount, Windows.Foundation.DateTime expiration); + + // Updates the badge on the app's tile to display a glyph. + void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue); + + // Updates the badge on the app's tile to display a glyph with an expiration time. + void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue, Windows.Foundation.DateTime expiration); + + // Removes the Badge Notifications for the App from Action Center + void ClearBadge(); + } +} diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems new file mode 100644 index 0000000000..6e2c634a77 --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems @@ -0,0 +1,22 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {85d111c7-b720-4e19-a56d-03c87b953983} + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems new file mode 100644 index 0000000000..31b240e924 --- /dev/null +++ b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems @@ -0,0 +1,16 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {2bd7a1bb-d3d8-484f-9180-409d781dccf9} + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + \ No newline at end of file diff --git a/dev/WindowsAppRuntime_DLL/WindowsAppRuntime_DLL.vcxproj b/dev/WindowsAppRuntime_DLL/WindowsAppRuntime_DLL.vcxproj index 62e67cef13..4ffc28bcad 100644 --- a/dev/WindowsAppRuntime_DLL/WindowsAppRuntime_DLL.vcxproj +++ b/dev/WindowsAppRuntime_DLL/WindowsAppRuntime_DLL.vcxproj @@ -102,6 +102,8 @@ + + From 6fc30929fa738857de2b971859f742c1e197d0cc Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Wed, 20 Nov 2024 12:59:56 +0530 Subject: [PATCH 02/19] badge notfication support code changes --- .../NotificationProperties.cpp | 25 +++++ dev/AppNotifications/NotificationProperties.h | 3 + .../NotificationTransientProperties.cpp | 12 +- .../NotificationTransientProperties.h | 5 +- .../BadgeNotifications/BadgeNotification.cpp | 18 +++ .../BadgeNotifications/BadgeNotification.h | 15 +++ .../BadgeNotificationManager.cpp | 20 ++-- .../BadgeNotifications.vcxitems | 15 ++- .../BaseNotifications/BaseNotification.cpp | 103 ++++++++++++++++++ .../BaseNotifications/BaseNotification.h | 47 ++++++++ .../BaseNotificationManager.cpp | 71 ++++++++++++ .../BaseNotificationManager.h | 26 +++++ .../BaseNotifications.vcxitems | 14 ++- dev/PushNotifications/externs.h | 3 +- 14 files changed, 360 insertions(+), 17 deletions(-) create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotification.cpp create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotification.h create mode 100644 dev/Notifications/BaseNotifications/BaseNotification.cpp create mode 100644 dev/Notifications/BaseNotifications/BaseNotification.h create mode 100644 dev/Notifications/BaseNotifications/BaseNotificationManager.cpp create mode 100644 dev/Notifications/BaseNotifications/BaseNotificationManager.h diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index c06167106c..6654396627 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -59,6 +59,31 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa } } +NotificationProperties::NotificationProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) +{ + // Extract payload and convert it from XML to a byte array + auto payloadAsSimpleString = Helpers::WideStringToUtf8String(baseNotification.Payload()); + + m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); + THROW_IF_NULL_ALLOC(m_payload.get()); + CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); + + m_notificationId = baseNotification.Id(); + + m_tag = baseNotification.Tag(); + m_group = baseNotification.Group(); + + m_expiry = winrt::clock::to_file_time(baseNotification.Expiration()); + m_arrivalTime = winrt::clock::to_file_time(winrt::clock::now()); + + m_expiresOnReboot = baseNotification.ExpiresOnReboot(); + + if (baseNotification.Progress() != nullptr) + { + m_toastProgressData = winrt::make_self(baseNotification.Progress()); + } +} + STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_NotificationId(_Out_ unsigned int* notificationId) noexcept { auto lock{ m_lock.lock_shared() }; diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index ec6aaffae9..9073d050bf 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -4,11 +4,14 @@ #pragma once #include +#include "BaseNotification.h" struct NotificationProperties : winrt::implements { NotificationProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification); + NotificationProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification); + STDMETHOD(get_NotificationId)(_Out_ unsigned int* notificationId) noexcept; STDMETHOD(get_Payload)(_Out_ unsigned int* payloadSize, _Out_ byte** payload) noexcept; diff --git a/dev/AppNotifications/NotificationTransientProperties.cpp b/dev/AppNotifications/NotificationTransientProperties.cpp index 80c22e7350..a938e55e0b 100644 --- a/dev/AppNotifications/NotificationTransientProperties.cpp +++ b/dev/AppNotifications/NotificationTransientProperties.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation and Contributors. +// Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. #include "pch.h" @@ -28,6 +28,16 @@ NotificationTransientProperties::NotificationTransientProperties(winrt::AppNotif } } +NotificationTransientProperties::NotificationTransientProperties(_In_ Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) noexcept +{ + m_suppressPopup = baseNotification.SuppressDisplay(); + + if (baseNotification.Priority() == winrt::AppNotificationPriority::High) + { + m_toastNotificationPriority = ToastABI::ToastNotificationPriority::ToastNotificationPriority_High; + } +} + STDMETHODIMP_(HRESULT __stdcall) NotificationTransientProperties::get_OfflineCacheCount(_Out_ unsigned long long* offlineCacheCount) noexcept { *offlineCacheCount = 0; diff --git a/dev/AppNotifications/NotificationTransientProperties.h b/dev/AppNotifications/NotificationTransientProperties.h index 0c45c8e972..fd4e6c81a8 100644 --- a/dev/AppNotifications/NotificationTransientProperties.h +++ b/dev/AppNotifications/NotificationTransientProperties.h @@ -1,14 +1,17 @@ -// Copyright (c) Microsoft Corporation and Contributors. +// Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. #pragma once #include +#include "BaseNotification.h" struct NotificationTransientProperties : winrt::implements { NotificationTransientProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification) noexcept; + NotificationTransientProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) noexcept; + STDMETHOD(get_OfflineCacheCount)(_Out_ unsigned long long* offlineCacheCount) noexcept; STDMETHOD(get_OfflineBundleId)(_Out_ HSTRING* offlineBundleId) noexcept; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.cpp b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp new file mode 100644 index 0000000000..dde9f113c7 --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp @@ -0,0 +1,18 @@ +#include "pch.h" +#include "BadgeNotification.h" + +using namespace Microsoft::Windows::BaseNotifications; + +namespace Microsoft::Windows::BadgeNotifications { + // Default constructor + BadgeNotification::BadgeNotification() : BaseNotification() + { + //set type in base + } + + // Constructor that takes a payload and forwards it to the base class constructor + BadgeNotification::BadgeNotification(winrt::hstring const& payload) : BaseNotification(payload) + { + //set type in base + } +} diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.h b/dev/Notifications/BadgeNotifications/BadgeNotification.h new file mode 100644 index 0000000000..f6550b89fe --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include "BaseNotification.h" + + +namespace Microsoft::Windows::BadgeNotifications +{ + struct BadgeNotification : Microsoft::Windows::BaseNotifications::BaseNotification + { + BadgeNotification(); + + BadgeNotification(winrt::hstring const& payload); + }; +} diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index afefb84e95..714406733b 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -53,7 +53,7 @@ namespace PushNotificationHelpers using namespace Microsoft::Windows::AppNotifications::Helpers; using namespace Microsoft::Windows::AppNotifications::ShellLocalization; -namespace winrt::Microsoft::Windows::AppNotifications::implementation +namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} @@ -64,7 +64,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation static wil::srwlock lock; auto criticalSection{ lock.lock_exclusive() }; - auto storedBadgeNotificationManager{ appProperties.TryLookup(STORED_APPNOTIFICATION_MANAGER_KEY) }; + auto storedBadgeNotificationManager{ appProperties.TryLookup(STORED_BADGENOTIFICATION_MANAGER_KEY) }; if (storedBadgeNotificationManager) { return storedBadgeNotificationManager.as(); @@ -75,33 +75,33 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation ::Microsoft::RoApi::ClearRoActivateInstanceCache(); // Store the BadgeNotificationManager in the COM static store - auto BadgeNotificationManager{ winrt::make() }; - appProperties.Insert(STORED_APPNOTIFICATION_MANAGER_KEY, BadgeNotificationManager); - return BadgeNotificationManager; + auto badgeNotificationManager{ winrt::make() }; + appProperties.Insert(STORED_BADGENOTIFICATION_MANAGER_KEY, badgeNotificationManager); + return badgeNotificationManager; } } - void SetBadgeAsCount(uint32_t notificationCount) + void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount) { return; } - void SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) + void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) { return; } - void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue) + void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue) { return; } - void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration) + void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration) { return; } - void ClearBadge() + void BadgeNotificationManager::ClearBadge() { return; } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems index 6e2c634a77..647129ef8c 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -14,9 +14,18 @@ - + + + + + + + - \ No newline at end of file + + + + diff --git a/dev/Notifications/BaseNotifications/BaseNotification.cpp b/dev/Notifications/BaseNotifications/BaseNotification.cpp new file mode 100644 index 0000000000..b655128298 --- /dev/null +++ b/dev/Notifications/BaseNotifications/BaseNotification.cpp @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" +#include "BaseNotification.h" + +using namespace winrt::Windows::Data::Xml::Dom; + +namespace Microsoft::Windows::BaseNotifications { + BaseNotification::BaseNotification(winrt::hstring const& payload) + { + XmlDocument xmlDocument{}; + + // We call LoadXml to verify the payload is xml + xmlDocument.LoadXml(payload); + m_payload = payload; + } + + winrt::hstring BaseNotification::Tag() const noexcept + { + return m_tag; + } + + void BaseNotification::Tag(winrt::hstring const& tag) + { + m_tag = tag; + } + + winrt::hstring BaseNotification::Group() const noexcept + { + return m_group; + } + + void BaseNotification::Group(winrt::hstring const& group) + { + m_group = group; + } + + uint32_t BaseNotification::Id() const noexcept + { + return m_notificationId; + } + + winrt::hstring BaseNotification::Payload() const noexcept + { + return m_payload; + } + + winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData BaseNotification::Progress() const noexcept + { + return m_progressData; + } + + void BaseNotification::Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& progressData) + { + m_progressData = progressData; + } + + winrt::Windows::Foundation::DateTime BaseNotification::Expiration() const noexcept + { + return m_expirationTime; + } + + void BaseNotification::Expiration(winrt::Windows::Foundation::DateTime const& expirationTime) + { + m_expirationTime = expirationTime; + } + + bool BaseNotification::ExpiresOnReboot() const noexcept + { + return m_expiresOnReboot; + } + + void BaseNotification::ExpiresOnReboot(bool expiresOnReboot) + { + m_expiresOnReboot = expiresOnReboot; + } + + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority BaseNotification::Priority() const noexcept + { + return m_priority; + } + + void BaseNotification::Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& priority) + { + m_priority = priority; + } + + bool BaseNotification::SuppressDisplay() const noexcept + { + return m_suppressDisplay; + } + + void BaseNotification::SuppressDisplay(bool suppressDisplay) + { + m_suppressDisplay = suppressDisplay; + } + + void BaseNotification::Id(uint32_t id) + { + m_notificationId = id; + } +} diff --git a/dev/Notifications/BaseNotifications/BaseNotification.h b/dev/Notifications/BaseNotifications/BaseNotification.h new file mode 100644 index 0000000000..dcfb355d6a --- /dev/null +++ b/dev/Notifications/BaseNotifications/BaseNotification.h @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#pragma once + +#include +#include +#include + +namespace Microsoft::Windows::BaseNotifications { + struct BaseNotification + { + BaseNotification() = default; + + BaseNotification(winrt::hstring const& payload); + winrt::hstring Tag() const noexcept; + void Tag(winrt::hstring const& value); + winrt::hstring Group() const noexcept; + void Group(winrt::hstring const& value); + uint32_t Id() const noexcept; + void Id(uint32_t id); + winrt::hstring Payload() const noexcept; + winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData Progress() const noexcept; + void Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& value); + winrt::Windows::Foundation::DateTime Expiration() const noexcept; + void Expiration(winrt::Windows::Foundation::DateTime const& value); + bool ExpiresOnReboot() const noexcept; + void ExpiresOnReboot(bool value); + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority Priority() const noexcept; + void Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& value); + bool SuppressDisplay() const noexcept; + void SuppressDisplay(bool value); + + protected: + winrt::hstring m_tag{}; + winrt::hstring m_group{}; + uint32_t m_notificationId{ 0 }; + winrt::hstring m_payload{}; + winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData m_progressData{ nullptr }; + winrt::Windows::Foundation::DateTime m_expirationTime{}; + bool m_expiresOnReboot{ false }; + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority + { winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default }; + bool m_suppressDisplay{ false }; + wil::srwlock m_lock; + }; +} diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp new file mode 100644 index 0000000000..33906610ef --- /dev/null +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#include "pch.h" +#include "BaseNotificationManager.h" +#include "BaseNotification.h" +#include +#include +#include "externs.h" +#include "AppNotificationUtility.h" +#include "NotificationProperties.h" +#include "NotificationTransientProperties.h" +#include +#include +#include +#include + +using namespace Microsoft::Windows::AppNotifications::Helpers; +using namespace Microsoft::Windows::AppNotifications::ShellLocalization; + +namespace Microsoft::Windows::BaseNotifications { + BaseNotificationManager::BaseNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {}; + + void BaseNotificationManager::Show(BaseNotification const& notification) + { + /*if (!IsSupported()) + { + return; + } + + auto logTelemetry{ AppNotificationTelemetry::Show::Start( + g_telemetryHelper, + m_appId, + notification.Payload(), + notification.Tag(), + notification.Group()) }; + + THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0);*/ + + /*winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(notification); + + winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationTransientProperties> notificationTransientProperties = winrt::make_self(notification); + + DWORD notificationId = 0; + THROW_IF_FAILED(ToastNotifications_PostToast(m_appId.c_str(), notificationProperties.get(), notificationTransientProperties.get(), ¬ificationId)); + + THROW_HR_IF(E_UNEXPECTED, notificationId == 0); + + implementation::AppNotification* notificationImpl = get_self(notification); + notificationImpl->SetNotificationId(notificationId); + + logTelemetry.Stop();*/ + } + + void BaseNotificationManager::RemoveAllNotification() + { + /*if (!IsSupported()) + { + co_return; + } + + auto strong = get_strong(); + co_await winrt::resume_background(); + + auto logTelemetry{ AppNotificationTelemetry::RemoveAllAsync::Start(g_telemetryHelper, m_appId) };*/ + + THROW_IF_FAILED(ToastNotifications_RemoveAllToastsForApp(m_appId.c_str())); + + /*logTelemetry.Stop();*/ + } +} diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.h b/dev/Notifications/BaseNotifications/BaseNotificationManager.h new file mode 100644 index 0000000000..5f047e3f1b --- /dev/null +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.h @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#pragma once + +#include +#include "externs.h" +#include "ShellLocalization.h" +#include +#include +#include + +namespace Microsoft::Windows::BaseNotifications { + struct BaseNotificationManager + { + BaseNotificationManager(); + + void Show(BaseNotification const& notification); + void RemoveAllNotification(); + + protected: + wil::srwlock m_lock; + std::wstring m_processName; + std::wstring m_appId; + }; +} diff --git a/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems index 31b240e924..4275e6c375 100644 --- a/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems +++ b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems @@ -13,4 +13,16 @@ - \ No newline at end of file + + + + + + + + + + + + + diff --git a/dev/PushNotifications/externs.h b/dev/PushNotifications/externs.h index 14753585fb..87f43c4aef 100644 --- a/dev/PushNotifications/externs.h +++ b/dev/PushNotifications/externs.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation and Contributors. +// Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. #pragma once @@ -10,6 +10,7 @@ inline const winrt::hstring STORED_PUSH_MANAGER_KEY = L"StoredPushManagerKey"; inline const winrt::hstring STORED_APPNOTIFICATION_MANAGER_KEY = L"StoredAppNotificationManagerKey"; +inline const winrt::hstring STORED_BADGENOTIFICATION_MANAGER_KEY = L"StoredBadgeNotificationManagerKey"; inline const DWORD c_receiveArgsTimeoutInMSec{ 2000 }; inline NotificationTelemetryHelper g_telemetryHelper{}; From 876bfbbc216adf4eceeb9787c0ecc01e9abe76fc Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Thu, 21 Nov 2024 15:01:22 +0530 Subject: [PATCH 03/19] badge notfication support code changes --- .../BadgeNotifications/BadgeNotification.h | 1 - .../BadgeNotificationManager.cpp | 59 ++++++++++++++++++- .../BadgeNotificationManager.h | 9 ++- .../BaseNotificationManager.cpp | 11 ++-- .../BaseNotificationManager.h | 2 +- 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.h b/dev/Notifications/BadgeNotifications/BadgeNotification.h index f6550b89fe..fc5a5f5ed9 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotification.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.h @@ -9,7 +9,6 @@ namespace Microsoft::Windows::BadgeNotifications struct BadgeNotification : Microsoft::Windows::BaseNotifications::BaseNotification { BadgeNotification(); - BadgeNotification(winrt::hstring const& payload); }; } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 714406733b..66ede7c934 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -27,6 +27,9 @@ #include #include #include +#include "BaseNotification.h" +#include "BaseNotificationManager.h" +#include "BadgeNotification.h" using namespace std::literals; @@ -37,6 +40,7 @@ namespace winrt using namespace winrt::Windows::Foundation::Collections; using namespace winrt::Microsoft::Windows::AppNotifications; using namespace Windows::ApplicationModel::Core; + using namespace winrt::Microsoft::Windows::BadgeNotifications; } namespace ToastABI @@ -53,9 +57,15 @@ namespace PushNotificationHelpers using namespace Microsoft::Windows::AppNotifications::Helpers; using namespace Microsoft::Windows::AppNotifications::ShellLocalization; +namespace BaseNotifications +{ + using namespace ::Microsoft::Windows::BaseNotifications; +} + namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { - BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} +// BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} + BadgeNotificationManager::BadgeNotificationManager() : BaseNotifications::BaseNotificationManager() {} winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager BadgeNotificationManager::Current() { @@ -83,26 +93,73 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount) { + std::wstring notificationCountString = std::to_wstring(notificationCount); + auto xmlResult{ wil::str_printf(L"", + notificationCountString.c_str()) }; + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications (xmlResult.c_str()); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications); return; } void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) { + std::wstring notificationCountString = std::to_wstring(notificationCount); + auto xmlResult{ wil::str_printf(L"", + notificationCountString.c_str()) }; + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + badgeNotifications.Expiration(expiration); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications); return; } void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue) { + PCWSTR glyphValueString; + GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + auto xmlResult{ wil::str_printf(L"", + glyphValueString) }; + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications); return; } void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration) { + PCWSTR glyphValueString; + GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + auto xmlResult{ wil::str_printf(L"", + glyphValueString) }; + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + badgeNotifications.Expiration(expiration); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications); return; } void BadgeNotificationManager::ClearBadge() { + BaseNotifications::BaseNotificationManager::RemoveAllNotification(); + return; + } + + void BadgeNotificationManager::GetBadgeNotificationGlyphToString(_In_ winrt::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString) + { + static const std::unordered_map enumMapping = { + {winrt::BadgeNotificationGlyph::None, L"none"}, + {winrt::BadgeNotificationGlyph::Activity, L"activity"}, + {winrt::BadgeNotificationGlyph::Alarm, L"alarm"}, + {winrt::BadgeNotificationGlyph::Alert, L"alert"}, + {winrt::BadgeNotificationGlyph::Attention, L"attention"}, + {winrt::BadgeNotificationGlyph::Available, L"available"}, + {winrt::BadgeNotificationGlyph::Away, L"away"}, + {winrt::BadgeNotificationGlyph::Busy, L"busy"}, + {winrt::BadgeNotificationGlyph::Error, L"error"}, + {winrt::BadgeNotificationGlyph::NewMessage, L"newMessage"}, + {winrt::BadgeNotificationGlyph::Paused, L"paused"}, + {winrt::BadgeNotificationGlyph::Playing, L"playing"}, + {winrt::BadgeNotificationGlyph::Unavailable, L"unavailable"} + }; + + *glyphString = enumMapping.at(glyphValue); return; } } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h index 9371daadff..bf607fb8b5 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -5,10 +5,12 @@ #include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.h" #include "externs.h" #include "ShellLocalization.h" +#include "BaseNotification.h" +#include "BaseNotificationManager.h" namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { - struct BadgeNotificationManager : BadgeNotificationManagerT + struct BadgeNotificationManager : BadgeNotificationManagerT, public ::Microsoft::Windows::BaseNotifications::BaseNotificationManager { BadgeNotificationManager(); @@ -23,9 +25,10 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void ClearBadge(); private: - wil::srwlock m_lock; + void GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString); + /*wil::srwlock m_lock; std::wstring m_processName; - std::wstring m_appId; + std::wstring m_appId;*/ }; struct BadgeNotificationManagerFactory : winrt::implements diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp index 33906610ef..7c61f63aad 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp @@ -21,7 +21,7 @@ using namespace Microsoft::Windows::AppNotifications::ShellLocalization; namespace Microsoft::Windows::BaseNotifications { BaseNotificationManager::BaseNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {}; - void BaseNotificationManager::Show(BaseNotification const& notification) + void BaseNotificationManager::Show(BaseNotification& notification) { /*if (!IsSupported()) { @@ -37,7 +37,7 @@ namespace Microsoft::Windows::BaseNotifications { THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0);*/ - /*winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(notification); + winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(notification); winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationTransientProperties> notificationTransientProperties = winrt::make_self(notification); @@ -46,10 +46,11 @@ namespace Microsoft::Windows::BaseNotifications { THROW_HR_IF(E_UNEXPECTED, notificationId == 0); - implementation::AppNotification* notificationImpl = get_self(notification); - notificationImpl->SetNotificationId(notificationId); + /*implementation::AppNotification* notificationImpl = get_self(notification); + notificationImpl->SetNotificationId(notificationId);*/ + notification.Id(notificationId); - logTelemetry.Stop();*/ + /*logTelemetry.Stop();*/ } void BaseNotificationManager::RemoveAllNotification() diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.h b/dev/Notifications/BaseNotifications/BaseNotificationManager.h index 5f047e3f1b..580c8b0a26 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.h +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.h @@ -15,7 +15,7 @@ namespace Microsoft::Windows::BaseNotifications { { BaseNotificationManager(); - void Show(BaseNotification const& notification); + void Show(BaseNotification& notification); void RemoveAllNotification(); protected: From 7d70b87c869c6f860f6077e1a66f3b4d144f374e Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Tue, 26 Nov 2024 13:51:44 +0530 Subject: [PATCH 04/19] badge notfication support code changes --- build/CopyFilesToStagingDir.ps1 | 2 ++ build/NuSpecs/AppxManifest.xml | 5 ++- .../WindowsAppSDK-Nuget-Native.WinRt.props | 6 ++++ .../WindowsAppSDK-Nuget-Native.targets | 8 +++++ .../NotificationProperties.cpp | 13 +++++++ dev/AppNotifications/NotificationProperties.h | 4 +++ .../BadgeNotifications/BadgeNotification.cpp | 10 ++++-- .../BadgeNotificationManager.cpp | 35 ++++++++++++++----- .../BadgeNotificationManager.h | 10 +++--- .../BaseNotifications/BaseNotification.cpp | 10 ++++++ .../BaseNotifications/BaseNotification.h | 5 +++ .../BaseNotificationManager.cpp | 9 ++--- .../BaseNotificationManager.h | 2 +- 13 files changed, 98 insertions(+), 21 deletions(-) diff --git a/build/CopyFilesToStagingDir.ps1 b/build/CopyFilesToStagingDir.ps1 index 3c261aaac2..f73036ee7c 100644 --- a/build/CopyFilesToStagingDir.ps1 +++ b/build/CopyFilesToStagingDir.ps1 @@ -53,6 +53,7 @@ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windo PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppLifecycle.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppNotifications.Builder.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppNotifications.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ +PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.BadgeNotifications.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Management.Deployment.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Media.Capture.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.PushNotifications.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\ @@ -200,6 +201,7 @@ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windo PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppLifecycle.winmd $NugetDir\lib\uap10.0 PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppNotifications.Builder.winmd $NugetDir\lib\uap10.0 PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.AppNotifications.winmd $NugetDir\lib\uap10.0 +PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.BadgeNotifications.winmd $NugetDir\lib\uap10.0 PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Management.Deployment.winmd $NugetDir\lib\uap10.0 PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Media.Capture.winmd $NugetDir\lib\uap10.0 PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.PushNotifications.winmd $NugetDir\lib\uap10.0 diff --git a/build/NuSpecs/AppxManifest.xml b/build/NuSpecs/AppxManifest.xml index e079468216..6dac600300 100644 --- a/build/NuSpecs/AppxManifest.xml +++ b/build/NuSpecs/AppxManifest.xml @@ -1,4 +1,4 @@ - + @@ -111,6 +111,9 @@ + + + diff --git a/build/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props b/build/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props index 88fede76fd..45fe60f31a 100644 --- a/build/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props +++ b/build/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props @@ -75,6 +75,12 @@ $(MSBuildThisFileDirectory)..\..\runtimes\win10-$(_WindowsAppSDKFoundationPlatform)\native\Microsoft.WindowsAppRuntime.dll true + + $(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Windows.BadgeNotifications.winmd + $(MSBuildThisFileDirectory)..\..\runtimes\win10-$(_WindowsAppSDKFoundationPlatform)\native\Microsoft.WindowsAppRuntime.dll + true + diff --git a/build/NuSpecs/WindowsAppSDK-Nuget-Native.targets b/build/NuSpecs/WindowsAppSDK-Nuget-Native.targets index c18bdb650a..506c223359 100644 --- a/build/NuSpecs/WindowsAppSDK-Nuget-Native.targets +++ b/build/NuSpecs/WindowsAppSDK-Nuget-Native.targets @@ -135,6 +135,14 @@ + + + false + Microsoft.WindowsAppRuntime.dll + + + diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index 6654396627..2b3a1e40a1 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -57,6 +57,9 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa m_toastConferencingConfig = winrt::make_self(config); } } + + + m_notificationType = ToastABI::NotificationType::NotificationType_Toast; } NotificationProperties::NotificationProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) @@ -82,6 +85,8 @@ NotificationProperties::NotificationProperties(Microsoft::Windows::BaseNotificat { m_toastProgressData = winrt::make_self(baseNotification.Progress()); } + + m_notificationType = baseNotification.NotificationType(); } STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_NotificationId(_Out_ unsigned int* notificationId) noexcept @@ -189,3 +194,11 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_ToastConferencingCo m_toastConferencingConfig.copy_to(conferencingConfig); return S_OK; } + +STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_NotificationType(_Out_ ToastABI::NotificationType* notificationType) noexcept +{ + auto lock{ m_lock.lock_shared() }; + *notificationType = m_notificationType; + + return S_OK; +} diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index 9073d050bf..81944e93d4 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -36,6 +36,8 @@ struct NotificationProperties : winrt::implements m_toastProgressData{ nullptr }; winrt::com_ptr m_toastConferencingConfig{ nullptr }; + + ABI::Microsoft::Internal::ToastNotifications::NotificationType m_notificationType; }; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.cpp b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp index dde9f113c7..d832423405 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotification.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp @@ -1,18 +1,24 @@ #include "pch.h" #include "BadgeNotification.h" +#include using namespace Microsoft::Windows::BaseNotifications; +namespace ToastABI +{ + using namespace ::ABI::Microsoft::Internal::ToastNotifications; +} + namespace Microsoft::Windows::BadgeNotifications { // Default constructor BadgeNotification::BadgeNotification() : BaseNotification() { - //set type in base + BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Badge); } // Constructor that takes a payload and forwards it to the base class constructor BadgeNotification::BadgeNotification(winrt::hstring const& payload) : BaseNotification(payload) { - //set type in base + BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Badge); } } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 66ede7c934..7bcadb90ee 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -93,22 +93,24 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount) { - std::wstring notificationCountString = std::to_wstring(notificationCount); + /*std::wstring notificationCountString = std::to_wstring(notificationCount); auto xmlResult{ wil::str_printf(L"", notificationCountString.c_str()) }; ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications (xmlResult.c_str()); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + SetBadge(std::to_wstring(notificationCount), nullptr); return; } void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) { - std::wstring notificationCountString = std::to_wstring(notificationCount); + /*std::wstring notificationCountString = std::to_wstring(notificationCount); auto xmlResult{ wil::str_printf(L"", notificationCountString.c_str()) }; ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); badgeNotifications.Expiration(expiration); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + SetBadge(std::to_wstring(notificationCount), &expiration); return; } @@ -116,10 +118,11 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); - auto xmlResult{ wil::str_printf(L"", + /*auto xmlResult{ wil::str_printf(L"", glyphValueString) }; ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + SetBadge(glyphValueString, nullptr); return; } @@ -127,17 +130,18 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); - auto xmlResult{ wil::str_printf(L"", + /*auto xmlResult{ wil::str_printf(L"", glyphValueString) }; ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); badgeNotifications.Expiration(expiration); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + SetBadge(glyphValueString, &expiration); return; } void BadgeNotificationManager::ClearBadge() { - BaseNotifications::BaseNotificationManager::RemoveAllNotification(); + BaseNotifications::BaseNotificationManager::RemoveAllNotification(ToastABI::NotificationType::NotificationType_Badge); return; } @@ -162,4 +166,17 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation *glyphString = enumMapping.at(glyphValue); return; } + + void BadgeNotificationManager::SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration) + { + auto xmlResult = wil::str_printf(L"", value.c_str()); + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + + if (expiration != nullptr) + { + badgeNotifications.Expiration(*expiration); + } + + BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + } } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h index bf607fb8b5..54c4a9fa10 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -16,16 +16,18 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation static winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager Current(); - void SetBadgeAsCount(uint32_t notificationCount); - void SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration); + void SetBadgeAsCount(_In_ uint32_t notificationCount); + void SetBadgeAsCount(_In_ uint32_t notificationCount, _In_ winrt::Windows::Foundation::DateTime expiration); - void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue); - void SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration); + void SetBadgeAsGlyph(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue); + void SetBadgeAsGlyph(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _In_ winrt::Windows::Foundation::DateTime expiration); void ClearBadge(); private: void GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString); + void SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration); +// void GetBadgeNotificationUsingCount(_In_ uint32_t notificationCount, _Out_ ::Microsoft::Windows::BadgeNotifications::BadgeNotification& badgeNotification); /*wil::srwlock m_lock; std::wstring m_processName; std::wstring m_appId;*/ diff --git a/dev/Notifications/BaseNotifications/BaseNotification.cpp b/dev/Notifications/BaseNotifications/BaseNotification.cpp index b655128298..989e9fb152 100644 --- a/dev/Notifications/BaseNotifications/BaseNotification.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotification.cpp @@ -100,4 +100,14 @@ namespace Microsoft::Windows::BaseNotifications { { m_notificationId = id; } + + ::ABI::Microsoft::Internal::ToastNotifications::NotificationType BaseNotification::NotificationType() const noexcept + { + return m_notificationType; + } + + void BaseNotification::NotificationType(::ABI::Microsoft::Internal::ToastNotifications::NotificationType value) + { + m_notificationType = value; + } } diff --git a/dev/Notifications/BaseNotifications/BaseNotification.h b/dev/Notifications/BaseNotifications/BaseNotification.h index dcfb355d6a..136fa71da0 100644 --- a/dev/Notifications/BaseNotifications/BaseNotification.h +++ b/dev/Notifications/BaseNotifications/BaseNotification.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace Microsoft::Windows::BaseNotifications { struct BaseNotification @@ -30,6 +31,8 @@ namespace Microsoft::Windows::BaseNotifications { void Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& value); bool SuppressDisplay() const noexcept; void SuppressDisplay(bool value); + ::ABI::Microsoft::Internal::ToastNotifications::NotificationType NotificationType() const noexcept; + void NotificationType(::ABI::Microsoft::Internal::ToastNotifications::NotificationType value); protected: winrt::hstring m_tag{}; @@ -41,7 +44,9 @@ namespace Microsoft::Windows::BaseNotifications { bool m_expiresOnReboot{ false }; winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority { winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default }; + ::ABI::Microsoft::Internal::ToastNotifications::NotificationType m_notificationType; bool m_suppressDisplay{ false }; + wil::srwlock m_lock; }; } diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp index 7c61f63aad..f0b4816c14 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp @@ -11,6 +11,7 @@ #include "NotificationProperties.h" #include "NotificationTransientProperties.h" #include +//#include #include #include #include @@ -33,9 +34,9 @@ namespace Microsoft::Windows::BaseNotifications { m_appId, notification.Payload(), notification.Tag(), - notification.Group()) }; + notification.Group()) }; */ - THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0);*/ + THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0); winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(notification); @@ -53,7 +54,7 @@ namespace Microsoft::Windows::BaseNotifications { /*logTelemetry.Stop();*/ } - void BaseNotificationManager::RemoveAllNotification() + void BaseNotificationManager::RemoveAllNotification(ABI::Microsoft::Internal::ToastNotifications::NotificationType notificationType) { /*if (!IsSupported()) { @@ -65,7 +66,7 @@ namespace Microsoft::Windows::BaseNotifications { auto logTelemetry{ AppNotificationTelemetry::RemoveAllAsync::Start(g_telemetryHelper, m_appId) };*/ - THROW_IF_FAILED(ToastNotifications_RemoveAllToastsForApp(m_appId.c_str())); + //THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), notificationType)); /*logTelemetry.Stop();*/ } diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.h b/dev/Notifications/BaseNotifications/BaseNotificationManager.h index 580c8b0a26..4c0ca6edf8 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.h +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.h @@ -16,7 +16,7 @@ namespace Microsoft::Windows::BaseNotifications { BaseNotificationManager(); void Show(BaseNotification& notification); - void RemoveAllNotification(); + void RemoveAllNotification(ABI::Microsoft::Internal::ToastNotifications::NotificationType notificationType); protected: wil::srwlock m_lock; From 0ebc3567f0a4fd4f8f702f3366127366b998eeed Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Tue, 26 Nov 2024 15:44:26 +0530 Subject: [PATCH 05/19] badge notfication support code changes --- WindowsAppRuntime.sln | 19 ++++++ ...ndows.BadgeNotifications.Projection.csproj | 59 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 dev/Projections/CS/Microsoft.Windows.BadgeNotifications.Projection/Microsoft.Windows.BadgeNotifications.Projection.csproj diff --git a/WindowsAppRuntime.sln b/WindowsAppRuntime.sln index 19b83a4eaf..d9c55d3f34 100644 --- a/WindowsAppRuntime.sln +++ b/WindowsAppRuntime.sln @@ -576,6 +576,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BadgeNotifications", "dev\N EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseNotifications", "dev\Notifications\BaseNotifications\BaseNotifications.vcxitems", "{2BD7A1BB-D3D8-484F-9180-409D781DCCF9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Windows.BadgeNotifications.Projection", "dev\Projections\CS\Microsoft.Windows.BadgeNotifications.Projection\Microsoft.Windows.BadgeNotifications.Projection.csproj", "{A243A58D-ABD7-4520-8C71-F492247B7B92}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -2012,6 +2014,22 @@ Global {A949149D-29CA-4AA7-B1ED-0E571B4AD9BB}.Release|x64.Build.0 = Release|x64 {A949149D-29CA-4AA7-B1ED-0E571B4AD9BB}.Release|x86.ActiveCfg = Release|x86 {A949149D-29CA-4AA7-B1ED-0E571B4AD9BB}.Release|x86.Build.0 = Release|x86 + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|ARM64.Build.0 = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|x64.ActiveCfg = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|x64.Build.0 = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|x86.ActiveCfg = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Debug|x86.Build.0 = Debug|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|Any CPU.Build.0 = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|ARM64.ActiveCfg = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|ARM64.Build.0 = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|x64.ActiveCfg = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|x64.Build.0 = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|x86.ActiveCfg = Release|Any CPU + {A243A58D-ABD7-4520-8C71-F492247B7B92}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2196,6 +2214,7 @@ Global {50205ED9-0E08-4878-B124-9AC0EBA138D6} = {43FE6980-3E16-4EF9-A3DE-29B402FB4FAB} {85D111C7-B720-4E19-A56D-03C87B953983} = {50205ED9-0E08-4878-B124-9AC0EBA138D6} {2BD7A1BB-D3D8-484F-9180-409D781DCCF9} = {586EA218-74C8-420B-B47E-0B307AA4B82D} + {A243A58D-ABD7-4520-8C71-F492247B7B92} = {716C26A0-E6B0-4981-8412-D14A4D410531} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4B3D7591-CFEC-4762-9A07-ABE99938FB77} diff --git a/dev/Projections/CS/Microsoft.Windows.BadgeNotifications.Projection/Microsoft.Windows.BadgeNotifications.Projection.csproj b/dev/Projections/CS/Microsoft.Windows.BadgeNotifications.Projection/Microsoft.Windows.BadgeNotifications.Projection.csproj new file mode 100644 index 0000000000..5fd9b2a649 --- /dev/null +++ b/dev/Projections/CS/Microsoft.Windows.BadgeNotifications.Projection/Microsoft.Windows.BadgeNotifications.Projection.csproj @@ -0,0 +1,59 @@ + + + net6.0-windows10.0.17763.0 + 10.0.17763.0 + x64;x86;arm64 + AnyCPU + false + + + + true + true + + + + + 8305 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + Microsoft.Windows.BadgeNotifications + 10.0.17763.0 + false + + + + + pdbonly + true + + + + + + + + + + + + + $(OutDir)..\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.BadgeNotifications.winmd + true + + + From b8d3cadc6009cea9cdaf4b3caf79b17c78e090e3 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Tue, 26 Nov 2024 16:41:01 +0530 Subject: [PATCH 06/19] badge notfication support code changes --- ...minalVelocityFeatures-BadgeNotifications.h | 32 +++++++++++++++++++ ...nalVelocityFeatures-BadgeNotifications.xml | 23 +++++++++++++ .../BadgeNotifications/BadgeNotifications.idl | 6 ++-- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 dev/Common/TerminalVelocityFeatures-BadgeNotifications.h create mode 100644 dev/Common/TerminalVelocityFeatures-BadgeNotifications.xml diff --git a/dev/Common/TerminalVelocityFeatures-BadgeNotifications.h b/dev/Common/TerminalVelocityFeatures-BadgeNotifications.h new file mode 100644 index 0000000000..de96769c44 --- /dev/null +++ b/dev/Common/TerminalVelocityFeatures-BadgeNotifications.h @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT IT + +// INPUT FILE: dev\common\TerminalVelocityFeatures-BadgeNotifications.xml +// OPTIONS: -Channel Experimental -Language C++ -Namespace Microsoft.Windows.BadgeNotifications -Path dev\common\TerminalVelocityFeatures-BadgeNotifications.xml -Output dev\common\TerminalVelocityFeatures-BadgeNotifications.h + +#if defined(__midlrt) +namespace features +{ + feature_name Feature_BadgeNotifications = { DisabledByDefault, FALSE }; +} +#endif // defined(__midlrt) + +// Feature constants +#define WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_BADGENOTIFICATIONS_FEATURE_BADGENOTIFICATIONS_ENABLED 1 + +#if defined(__cplusplus) + +namespace Microsoft::Windows::BadgeNotifications +{ + + __pragma(detect_mismatch("ODR_violation_WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_BADGENOTIFICATIONS_FEATURE_BADGENOTIFICATIONS_ENABLED_mismatch", "AlwaysEnabled")) + struct Feature_BadgeNotifications + { + static constexpr bool IsEnabled() { return WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_BADGENOTIFICATIONS_FEATURE_BADGENOTIFICATIONS_ENABLED == 1; } + }; + +} // namespace Microsoft.Windows.BadgeNotifications + +#endif // defined(__cplusplus) diff --git a/dev/Common/TerminalVelocityFeatures-BadgeNotifications.xml b/dev/Common/TerminalVelocityFeatures-BadgeNotifications.xml new file mode 100644 index 0000000000..d88bceb864 --- /dev/null +++ b/dev/Common/TerminalVelocityFeatures-BadgeNotifications.xml @@ -0,0 +1,23 @@ + + + + + + + + + + Feature_BadgeNotifications + Enables Local Badge sourced Notifications for packaged apps on the device + AlwaysEnabled + + Preview + Stable + + + + diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.idl b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl index 225a739171..19c6366aa1 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotifications.idl +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl @@ -1,13 +1,15 @@ // Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. +#include + namespace Microsoft.Windows.BadgeNotifications { [contractversion(1)] apicontract BadgeNotificationsContract {}; // Set of predefined glyphs that can be used to represent various statuses or notifications on an application's badge - [contract(BadgeNotificationsContract, 1)] + [contract(BadgeNotificationsContract, 1), feature(Feature_BadgeNotifications)] enum BadgeNotificationGlyph { None, // No glyph. A blank tile appears in the badge. @@ -26,7 +28,7 @@ namespace Microsoft.Windows.BadgeNotifications }; // The manager class which encompasses all Badge Notification API Functionality - [contract(BadgeNotificationsContract, 1)] + [contract(BadgeNotificationsContract, 1), feature(Feature_BadgeNotifications)] runtimeclass BadgeNotificationManager { // Gets a Default instance of a BadgeNotificationManager From 20f67b562c2cf7564839104ed21f3e59645184f0 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Tue, 26 Nov 2024 18:22:11 +0530 Subject: [PATCH 07/19] badge notfication support code changes --- .../BadgeNotificationManager.cpp | 15 ++++++ .../BadgeNotificationTelemetry.h | 47 +++++++++++++++++++ .../BadgeNotifications.vcxitems | 3 ++ 3 files changed, 65 insertions(+) create mode 100644 dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 7bcadb90ee..46e1fcbcf7 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -30,6 +30,7 @@ #include "BaseNotification.h" #include "BaseNotificationManager.h" #include "BadgeNotification.h" +#include "BadgeNotificationTelemetry.h" using namespace std::literals; @@ -141,7 +142,14 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void BadgeNotificationManager::ClearBadge() { + auto logTelemetry{ BadgeNotificationTelemetry::ClearBadge::Start( + g_telemetryHelper, + m_appId) }; + BaseNotifications::BaseNotificationManager::RemoveAllNotification(ToastABI::NotificationType::NotificationType_Badge); + + logTelemetry.Stop(); + return; } @@ -172,11 +180,18 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation auto xmlResult = wil::str_printf(L"", value.c_str()); ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + auto logTelemetry{ BadgeNotificationTelemetry::SetBadge::Start( + g_telemetryHelper, + m_appId, + badgeNotifications.Payload().c_str()) }; + if (expiration != nullptr) { badgeNotifications.Expiration(*expiration); } BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + + logTelemetry.Stop(); } } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h new file mode 100644 index 0000000000..49ba477a3a --- /dev/null +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include + +DECLARE_TRACELOGGING_CLASS(BadgeNotificationTelemetryProvider, + "Microsoft.WindowsAppSDK.Notifications.BadgeNotificationTelemetry", + // {c9002a02-1594-50ab-07e1-a1b60403db83} + (0xc9002a02, 0x1594, 0x50ab, 0x07, 0xe1, 0xa1, 0xb6, 0x04, 0x03, 0xdb, 0x83)); + +class BadgeNotificationTelemetry : public wil::TraceLoggingProvider +{ + IMPLEMENT_TELEMETRY_CLASS(BadgeNotificationTelemetry, BadgeNotificationTelemetryProvider); + +public: + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadge, PDT_ProductAndServicePerformance); + DEFINE_ACTIVITY_START( + NotificationTelemetryHelper& notificationTelemetryHelper, + std::wstring const& appId, + std::wstring const& payload) noexcept try + { + TraceLoggingClassWriteStart( + SetBadge, + _GENERIC_PARTB_FIELDS_ENABLED, + TraceLoggingWideString(appId.c_str(), "AppId"), + TraceLoggingWideString(payload.c_str(), "PayloadSize"), + TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), + TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); + } + CATCH_LOG() + END_ACTIVITY_CLASS(); + + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(ClearBadge, PDT_ProductAndServicePerformance); + DEFINE_ACTIVITY_START( + NotificationTelemetryHelper& notificationTelemetryHelper, + std::wstring const& appId) noexcept try + { + TraceLoggingClassWriteStart( + ClearBadge, + _GENERIC_PARTB_FIELDS_ENABLED, + TraceLoggingWideString(appId.c_str(), "AppId"), + TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), + TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); + } + CATCH_LOG() + END_ACTIVITY_CLASS(); +}; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems index 647129ef8c..31607097b2 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.vcxitems @@ -25,6 +25,9 @@ + + + From 52706d1c4d05be9e89169ad38f517615d0f764ce Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Wed, 27 Nov 2024 14:46:29 +0530 Subject: [PATCH 08/19] badge notfication support code changes --- dev/AppNotifications/NotificationProperties.h | 3 +- .../BadgeNotificationManager.cpp | 66 ++++--------------- .../BadgeNotificationManager.h | 6 -- .../BaseNotificationManager.cpp | 26 +------- .../BaseNotificationManager.h | 3 - 5 files changed, 17 insertions(+), 87 deletions(-) diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index 81944e93d4..77ebc0c9a3 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -6,7 +6,8 @@ #include #include "BaseNotification.h" -struct NotificationProperties : winrt::implements +struct NotificationProperties : winrt::implements { NotificationProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification); diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 46e1fcbcf7..9fe260665a 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -4,31 +4,10 @@ #include "pch.h" #include "BadgeNotificationManager.h" #include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.cpp" -#include -#include -#include #include "externs.h" -#include "PushNotificationUtility.h" -#include "AppNotificationUtility.h" -#include #include #include -#include "NotificationProperties.h" -#include "NotificationTransientProperties.h" -#include "AppNotification.h" -#include -#include "AppNotificationTelemetry.h" -#include -#include -#include -#include -#include #include -#include -#include -#include -#include "BaseNotification.h" -#include "BaseNotificationManager.h" #include "BadgeNotification.h" #include "BadgeNotificationTelemetry.h" @@ -50,14 +29,6 @@ namespace ToastABI using namespace ::ABI::Windows::Foundation::Collections; } -namespace PushNotificationHelpers -{ - using namespace winrt::Microsoft::Windows::PushNotifications::Helpers; -} - -using namespace Microsoft::Windows::AppNotifications::Helpers; -using namespace Microsoft::Windows::AppNotifications::ShellLocalization; - namespace BaseNotifications { using namespace ::Microsoft::Windows::BaseNotifications; @@ -65,7 +36,6 @@ namespace BaseNotifications namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { -// BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} BadgeNotificationManager::BadgeNotificationManager() : BaseNotifications::BaseNotificationManager() {} winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager BadgeNotificationManager::Current() @@ -94,54 +64,44 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount) { - /*std::wstring notificationCountString = std::to_wstring(notificationCount); - auto xmlResult{ wil::str_printf(L"", - notificationCountString.c_str()) }; - ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications (xmlResult.c_str()); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + SetBadge(std::to_wstring(notificationCount), nullptr); return; } - void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount, winrt::Windows::Foundation::DateTime expiration) + void BadgeNotificationManager::SetBadgeAsCount(uint32_t notificationCount, winrt::DateTime expiration) { - /*std::wstring notificationCountString = std::to_wstring(notificationCount); - auto xmlResult{ wil::str_printf(L"", - notificationCountString.c_str()) }; - ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); - badgeNotifications.Expiration(expiration); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ + THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + SetBadge(std::to_wstring(notificationCount), &expiration); return; } - void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue) + void BadgeNotificationManager::SetBadgeAsGlyph(winrt::BadgeNotificationGlyph glyphValue) { + THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); - /*auto xmlResult{ wil::str_printf(L"", - glyphValueString) }; - ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ SetBadge(glyphValueString, nullptr); return; } - void BadgeNotificationManager::SetBadgeAsGlyph(winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, winrt::Windows::Foundation::DateTime expiration) + void BadgeNotificationManager::SetBadgeAsGlyph(winrt::BadgeNotificationGlyph glyphValue, winrt::DateTime expiration) { + THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); - /*auto xmlResult{ wil::str_printf(L"", - glyphValueString) }; - ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); - badgeNotifications.Expiration(expiration); - BaseNotifications::BaseNotificationManager::Show(badgeNotifications);*/ SetBadge(glyphValueString, &expiration); return; } void BadgeNotificationManager::ClearBadge() { + THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + auto logTelemetry{ BadgeNotificationTelemetry::ClearBadge::Start( g_telemetryHelper, m_appId) }; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h index 54c4a9fa10..8578090dfd 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -4,8 +4,6 @@ #pragma once #include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.h" #include "externs.h" -#include "ShellLocalization.h" -#include "BaseNotification.h" #include "BaseNotificationManager.h" namespace winrt::Microsoft::Windows::BadgeNotifications::implementation @@ -27,10 +25,6 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation private: void GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString); void SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration); -// void GetBadgeNotificationUsingCount(_In_ uint32_t notificationCount, _Out_ ::Microsoft::Windows::BadgeNotifications::BadgeNotification& badgeNotification); - /*wil::srwlock m_lock; - std::wstring m_processName; - std::wstring m_appId;*/ }; struct BadgeNotificationManagerFactory : winrt::implements diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp index f0b4816c14..dcfecca41a 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp @@ -4,8 +4,6 @@ #include "pch.h" #include "BaseNotificationManager.h" #include "BaseNotification.h" -#include -#include #include "externs.h" #include "AppNotificationUtility.h" #include "NotificationProperties.h" @@ -13,8 +11,6 @@ #include //#include #include -#include -#include using namespace Microsoft::Windows::AppNotifications::Helpers; using namespace Microsoft::Windows::AppNotifications::ShellLocalization; @@ -27,14 +23,7 @@ namespace Microsoft::Windows::BaseNotifications { /*if (!IsSupported()) { return; - } - - auto logTelemetry{ AppNotificationTelemetry::Show::Start( - g_telemetryHelper, - m_appId, - notification.Payload(), - notification.Tag(), - notification.Group()) }; */ + }*/ THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0); @@ -47,11 +36,7 @@ namespace Microsoft::Windows::BaseNotifications { THROW_HR_IF(E_UNEXPECTED, notificationId == 0); - /*implementation::AppNotification* notificationImpl = get_self(notification); - notificationImpl->SetNotificationId(notificationId);*/ notification.Id(notificationId); - - /*logTelemetry.Stop();*/ } void BaseNotificationManager::RemoveAllNotification(ABI::Microsoft::Internal::ToastNotifications::NotificationType notificationType) @@ -59,15 +44,8 @@ namespace Microsoft::Windows::BaseNotifications { /*if (!IsSupported()) { co_return; - } - - auto strong = get_strong(); - co_await winrt::resume_background(); - - auto logTelemetry{ AppNotificationTelemetry::RemoveAllAsync::Start(g_telemetryHelper, m_appId) };*/ + }*/ //THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), notificationType)); - - /*logTelemetry.Stop();*/ } } diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.h b/dev/Notifications/BaseNotifications/BaseNotificationManager.h index 4c0ca6edf8..a137146801 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.h +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.h @@ -5,9 +5,6 @@ #include #include "externs.h" -#include "ShellLocalization.h" -#include -#include #include namespace Microsoft::Windows::BaseNotifications { From ba39226d4b0bd8772d5c594d1acc166082cc908e Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Wed, 27 Nov 2024 14:49:43 +0530 Subject: [PATCH 09/19] badge notfication support code changes --- dev/Notifications/BadgeNotifications/BadgeNotification.cpp | 3 +++ dev/Notifications/BadgeNotifications/BadgeNotification.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.cpp b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp index d832423405..32fc89c6fb 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotification.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.cpp @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + #include "pch.h" #include "BadgeNotification.h" #include diff --git a/dev/Notifications/BadgeNotifications/BadgeNotification.h b/dev/Notifications/BadgeNotifications/BadgeNotification.h index fc5a5f5ed9..6a1a1cdbdd 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotification.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotification.h @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + #pragma once #include From 0aae93427e6931a97c9f443060cb3e91e838f983 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Tue, 3 Dec 2024 19:03:31 +0530 Subject: [PATCH 10/19] added copyright header --- .../BadgeNotifications/BadgeNotificationTelemetry.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h index 49ba477a3a..c2ae4b0df8 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + #pragma once #include From 006a6b903f8bbddac94a1fc6a91ea8c699c27d4a Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Wed, 4 Dec 2024 17:44:16 +0530 Subject: [PATCH 11/19] badge clear method --- .../BaseNotifications/BaseNotificationManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp index dcfecca41a..0985db1b6a 100644 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp @@ -9,7 +9,7 @@ #include "NotificationProperties.h" #include "NotificationTransientProperties.h" #include -//#include +#include #include using namespace Microsoft::Windows::AppNotifications::Helpers; @@ -46,6 +46,6 @@ namespace Microsoft::Windows::BaseNotifications { co_return; }*/ - //THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), notificationType)); + THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), notificationType)); } } From 5d2eabd7c84e9f327865b4648fbd7d1cb9fc7181 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Thu, 5 Dec 2024 18:16:35 +0530 Subject: [PATCH 12/19] resolved comments --- .../NotificationProperties.cpp | 21 +++---- dev/AppNotifications/NotificationProperties.h | 4 +- .../NotificationTransientProperties.cpp | 6 +- .../NotificationTransientProperties.h | 4 +- .../BadgeNotificationManager.cpp | 57 +++++++++++++++---- .../BadgeNotificationManager.h | 6 +- .../BaseNotifications/BaseNotification.cpp | 10 ---- .../BaseNotifications/BaseNotification.h | 3 - .../BaseNotificationManager.cpp | 51 ----------------- .../BaseNotificationManager.h | 23 -------- .../BaseNotifications.vcxitems | 6 -- 11 files changed, 64 insertions(+), 127 deletions(-) delete mode 100644 dev/Notifications/BaseNotifications/BaseNotificationManager.cpp delete mode 100644 dev/Notifications/BaseNotifications/BaseNotificationManager.h diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index 2b3a1e40a1..a5b54c7a1a 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -62,31 +62,26 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa m_notificationType = ToastABI::NotificationType::NotificationType_Toast; } -NotificationProperties::NotificationProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) +NotificationProperties::NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification const& badgeNotification) { // Extract payload and convert it from XML to a byte array - auto payloadAsSimpleString = Helpers::WideStringToUtf8String(baseNotification.Payload()); + auto payloadAsSimpleString = Helpers::WideStringToUtf8String(badgeNotification.Payload()); m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); THROW_IF_NULL_ALLOC(m_payload.get()); CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); - m_notificationId = baseNotification.Id(); + m_notificationId = badgeNotification.Id(); - m_tag = baseNotification.Tag(); - m_group = baseNotification.Group(); + m_tag = badgeNotification.Tag(); + m_group = badgeNotification.Group(); - m_expiry = winrt::clock::to_file_time(baseNotification.Expiration()); + m_expiry = winrt::clock::to_file_time(badgeNotification.Expiration()); m_arrivalTime = winrt::clock::to_file_time(winrt::clock::now()); - m_expiresOnReboot = baseNotification.ExpiresOnReboot(); + m_expiresOnReboot = badgeNotification.ExpiresOnReboot(); - if (baseNotification.Progress() != nullptr) - { - m_toastProgressData = winrt::make_self(baseNotification.Progress()); - } - - m_notificationType = baseNotification.NotificationType(); + m_notificationType = badgeNotification.NotificationType(); } STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_NotificationId(_Out_ unsigned int* notificationId) noexcept diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index 77ebc0c9a3..e66bad9991 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -4,14 +4,14 @@ #pragma once #include -#include "BaseNotification.h" +#include "BadgeNotification.h" struct NotificationProperties : winrt::implements { NotificationProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification); - NotificationProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification); + NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification const& badgeNotification); STDMETHOD(get_NotificationId)(_Out_ unsigned int* notificationId) noexcept; diff --git a/dev/AppNotifications/NotificationTransientProperties.cpp b/dev/AppNotifications/NotificationTransientProperties.cpp index a938e55e0b..c11f4f1e33 100644 --- a/dev/AppNotifications/NotificationTransientProperties.cpp +++ b/dev/AppNotifications/NotificationTransientProperties.cpp @@ -28,11 +28,11 @@ NotificationTransientProperties::NotificationTransientProperties(winrt::AppNotif } } -NotificationTransientProperties::NotificationTransientProperties(_In_ Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) noexcept +NotificationTransientProperties::NotificationTransientProperties(_In_ Microsoft::Windows::BadgeNotifications::BadgeNotification const& badgeNotification) noexcept { - m_suppressPopup = baseNotification.SuppressDisplay(); + m_suppressPopup = badgeNotification.SuppressDisplay(); - if (baseNotification.Priority() == winrt::AppNotificationPriority::High) + if (badgeNotification.Priority() == winrt::AppNotificationPriority::High) { m_toastNotificationPriority = ToastABI::ToastNotificationPriority::ToastNotificationPriority_High; } diff --git a/dev/AppNotifications/NotificationTransientProperties.h b/dev/AppNotifications/NotificationTransientProperties.h index fd4e6c81a8..d4f3fd5f20 100644 --- a/dev/AppNotifications/NotificationTransientProperties.h +++ b/dev/AppNotifications/NotificationTransientProperties.h @@ -4,13 +4,13 @@ #pragma once #include -#include "BaseNotification.h" +#include "BadgeNotification.h" struct NotificationTransientProperties : winrt::implements { NotificationTransientProperties(winrt::Microsoft::Windows::AppNotifications::AppNotification const& toastNotification) noexcept; - NotificationTransientProperties(Microsoft::Windows::BaseNotifications::BaseNotification const& baseNotification) noexcept; + NotificationTransientProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification const& badgeNotification) noexcept; STDMETHOD(get_OfflineCacheCount)(_Out_ unsigned long long* offlineCacheCount) noexcept; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 9fe260665a..e6633f1988 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -5,8 +5,12 @@ #include "BadgeNotificationManager.h" #include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.cpp" #include "externs.h" +#include "AppNotificationUtility.h" +#include "NotificationProperties.h" +#include "NotificationTransientProperties.h" #include #include +#include #include #include "BadgeNotification.h" #include "BadgeNotificationTelemetry.h" @@ -29,14 +33,13 @@ namespace ToastABI using namespace ::ABI::Windows::Foundation::Collections; } -namespace BaseNotifications -{ - using namespace ::Microsoft::Windows::BaseNotifications; -} +using namespace Microsoft::Windows::AppNotifications::Helpers; +using namespace Microsoft::Windows::AppNotifications::ShellLocalization; + namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { - BadgeNotificationManager::BadgeNotificationManager() : BaseNotifications::BaseNotificationManager() {} + BadgeNotificationManager::BadgeNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {} winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationManager BadgeNotificationManager::Current() { @@ -84,6 +87,9 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + + THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString == NULL, "Invalid Glyph value"); + SetBadge(glyphValueString, nullptr); return; } @@ -94,6 +100,9 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation PCWSTR glyphValueString; GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + + THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString == NULL, "Invalid Glyph value"); + SetBadge(glyphValueString, &expiration); return; } @@ -106,7 +115,7 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation g_telemetryHelper, m_appId) }; - BaseNotifications::BaseNotificationManager::RemoveAllNotification(ToastABI::NotificationType::NotificationType_Badge); + THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), ToastABI::NotificationType::NotificationType_Badge)); logTelemetry.Stop(); @@ -115,7 +124,7 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void BadgeNotificationManager::GetBadgeNotificationGlyphToString(_In_ winrt::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString) { - static const std::unordered_map enumMapping = { + constexpr static std::pair enumMapping[] = { {winrt::BadgeNotificationGlyph::None, L"none"}, {winrt::BadgeNotificationGlyph::Activity, L"activity"}, {winrt::BadgeNotificationGlyph::Alarm, L"alarm"}, @@ -131,26 +140,50 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation {winrt::BadgeNotificationGlyph::Unavailable, L"unavailable"} }; - *glyphString = enumMapping.at(glyphValue); + auto it = std::find_if(std::begin(enumMapping), std::end(enumMapping), [&](const auto& item) + { + return item.first == glyphValue; + }); + + if (it != std::end(enumMapping)) + { + *glyphString = it->second; + } + else + { + *glyphString = nullptr; + } + return; } void BadgeNotificationManager::SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration) { auto xmlResult = wil::str_printf(L"", value.c_str()); - ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotifications(xmlResult.c_str()); + ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotification(xmlResult.c_str()); auto logTelemetry{ BadgeNotificationTelemetry::SetBadge::Start( g_telemetryHelper, m_appId, - badgeNotifications.Payload().c_str()) }; + badgeNotification.Payload().c_str()) }; if (expiration != nullptr) { - badgeNotifications.Expiration(*expiration); + badgeNotification.Expiration(*expiration); } - BaseNotifications::BaseNotificationManager::Show(badgeNotifications); + THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, badgeNotification.Id() != 0); + + winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(badgeNotification); + + winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationTransientProperties> notificationTransientProperties = winrt::make_self(badgeNotification); + + DWORD notificationId = 0; + THROW_IF_FAILED(ToastNotifications_PostToast(m_appId.c_str(), notificationProperties.get(), notificationTransientProperties.get(), ¬ificationId)); + + THROW_HR_IF(E_UNEXPECTED, notificationId == 0); + + badgeNotification.Id(notificationId); logTelemetry.Stop(); } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h index 8578090dfd..e617ad7bd1 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -4,11 +4,10 @@ #pragma once #include "Microsoft.Windows.BadgeNotifications.BadgeNotificationManager.g.h" #include "externs.h" -#include "BaseNotificationManager.h" namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { - struct BadgeNotificationManager : BadgeNotificationManagerT, public ::Microsoft::Windows::BaseNotifications::BaseNotificationManager + struct BadgeNotificationManager : BadgeNotificationManagerT { BadgeNotificationManager(); @@ -25,6 +24,9 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation private: void GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString); void SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration); + wil::srwlock m_lock; + std::wstring m_processName; + std::wstring m_appId; }; struct BadgeNotificationManagerFactory : winrt::implements diff --git a/dev/Notifications/BaseNotifications/BaseNotification.cpp b/dev/Notifications/BaseNotifications/BaseNotification.cpp index 989e9fb152..decc9a6480 100644 --- a/dev/Notifications/BaseNotifications/BaseNotification.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotification.cpp @@ -46,16 +46,6 @@ namespace Microsoft::Windows::BaseNotifications { return m_payload; } - winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData BaseNotification::Progress() const noexcept - { - return m_progressData; - } - - void BaseNotification::Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& progressData) - { - m_progressData = progressData; - } - winrt::Windows::Foundation::DateTime BaseNotification::Expiration() const noexcept { return m_expirationTime; diff --git a/dev/Notifications/BaseNotifications/BaseNotification.h b/dev/Notifications/BaseNotifications/BaseNotification.h index 136fa71da0..cf231c9f6e 100644 --- a/dev/Notifications/BaseNotifications/BaseNotification.h +++ b/dev/Notifications/BaseNotifications/BaseNotification.h @@ -21,8 +21,6 @@ namespace Microsoft::Windows::BaseNotifications { uint32_t Id() const noexcept; void Id(uint32_t id); winrt::hstring Payload() const noexcept; - winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData Progress() const noexcept; - void Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& value); winrt::Windows::Foundation::DateTime Expiration() const noexcept; void Expiration(winrt::Windows::Foundation::DateTime const& value); bool ExpiresOnReboot() const noexcept; @@ -39,7 +37,6 @@ namespace Microsoft::Windows::BaseNotifications { winrt::hstring m_group{}; uint32_t m_notificationId{ 0 }; winrt::hstring m_payload{}; - winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData m_progressData{ nullptr }; winrt::Windows::Foundation::DateTime m_expirationTime{}; bool m_expiresOnReboot{ false }; winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp b/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp deleted file mode 100644 index 0985db1b6a..0000000000 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation and Contributors. -// Licensed under the MIT License. - -#include "pch.h" -#include "BaseNotificationManager.h" -#include "BaseNotification.h" -#include "externs.h" -#include "AppNotificationUtility.h" -#include "NotificationProperties.h" -#include "NotificationTransientProperties.h" -#include -#include -#include - -using namespace Microsoft::Windows::AppNotifications::Helpers; -using namespace Microsoft::Windows::AppNotifications::ShellLocalization; - -namespace Microsoft::Windows::BaseNotifications { - BaseNotificationManager::BaseNotificationManager() : m_processName(GetCurrentProcessPath()), m_appId(RetrieveNotificationAppId()) {}; - - void BaseNotificationManager::Show(BaseNotification& notification) - { - /*if (!IsSupported()) - { - return; - }*/ - - THROW_HR_IF(WPN_E_NOTIFICATION_POSTED, notification.Id() != 0); - - winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationProperties> notificationProperties = winrt::make_self(notification); - - winrt::com_ptr<::ABI::Microsoft::Internal::ToastNotifications::INotificationTransientProperties> notificationTransientProperties = winrt::make_self(notification); - - DWORD notificationId = 0; - THROW_IF_FAILED(ToastNotifications_PostToast(m_appId.c_str(), notificationProperties.get(), notificationTransientProperties.get(), ¬ificationId)); - - THROW_HR_IF(E_UNEXPECTED, notificationId == 0); - - notification.Id(notificationId); - } - - void BaseNotificationManager::RemoveAllNotification(ABI::Microsoft::Internal::ToastNotifications::NotificationType notificationType) - { - /*if (!IsSupported()) - { - co_return; - }*/ - - THROW_IF_FAILED(WnpNotifications_RemoveAllNotificationsForAppOfType(m_appId.c_str(), notificationType)); - } -} diff --git a/dev/Notifications/BaseNotifications/BaseNotificationManager.h b/dev/Notifications/BaseNotifications/BaseNotificationManager.h deleted file mode 100644 index a137146801..0000000000 --- a/dev/Notifications/BaseNotifications/BaseNotificationManager.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation and Contributors. -// Licensed under the MIT License. - -#pragma once - -#include -#include "externs.h" -#include - -namespace Microsoft::Windows::BaseNotifications { - struct BaseNotificationManager - { - BaseNotificationManager(); - - void Show(BaseNotification& notification); - void RemoveAllNotification(ABI::Microsoft::Internal::ToastNotifications::NotificationType notificationType); - - protected: - wil::srwlock m_lock; - std::wstring m_processName; - std::wstring m_appId; - }; -} diff --git a/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems index 4275e6c375..f8732f5443 100644 --- a/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems +++ b/dev/Notifications/BaseNotifications/BaseNotifications.vcxitems @@ -19,10 +19,4 @@ - - - - - - From de2e9f16d6cb8e4f07badc3ac546d89b215ae98e Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Thu, 5 Dec 2024 19:22:35 +0530 Subject: [PATCH 13/19] app refactoring code --- dev/AppNotifications/AppNotification.cpp | 36 ++++++++++++++----- dev/AppNotifications/AppNotification.h | 21 +++++------ .../NotificationProperties.cpp | 2 +- dev/AppNotifications/NotificationProperties.h | 2 +- .../NotificationTransientProperties.cpp | 2 +- .../NotificationTransientProperties.h | 2 +- .../BaseNotifications/BaseNotification.cpp | 35 +++++++++++++----- .../BaseNotifications/BaseNotification.h | 18 +++++----- 8 files changed, 77 insertions(+), 41 deletions(-) diff --git a/dev/AppNotifications/AppNotification.cpp b/dev/AppNotifications/AppNotification.cpp index d1a15aec90..31a22b3a79 100644 --- a/dev/AppNotifications/AppNotification.cpp +++ b/dev/AppNotifications/AppNotification.cpp @@ -4,21 +4,39 @@ #include "pch.h" #include "AppNotification.h" #include "Microsoft.Windows.AppNotifications.AppNotification.g.cpp" +#include using namespace winrt::Windows::Data::Xml::Dom; +using namespace Microsoft::Windows::BaseNotifications; + +namespace ToastABI +{ + using namespace ::ABI::Microsoft::Internal::ToastNotifications; +} namespace winrt::Microsoft::Windows::AppNotifications::implementation { - AppNotification::AppNotification(hstring const& payload) + AppNotification::AppNotification() : BaseNotification() { - XmlDocument xmlDocument{}; + //XmlDocument xmlDocument{}; - // We call LoadXml to verify the payload is xml - xmlDocument.LoadXml(payload); - m_payload = payload; + //// We call LoadXml to verify the payload is xml + //xmlDocument.LoadXml(payload); + //m_payload = payload; + BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); } - hstring AppNotification::Tag() + AppNotification::AppNotification(hstring const& payload) : BaseNotification(payload) + { + //XmlDocument xmlDocument{}; + + //// We call LoadXml to verify the payload is xml + //xmlDocument.LoadXml(payload); + //m_payload = payload; + BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); + } + + /*hstring AppNotification::Tag() { auto lock{ m_lock.lock_shared() }; return m_tag; @@ -52,7 +70,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation { auto lock{ m_lock.lock_shared() }; return m_payload; - } + }*/ winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData AppNotification::Progress() { @@ -66,7 +84,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation m_progressData = progressData; } - winrt::Windows::Foundation::DateTime AppNotification::Expiration() + /*winrt::Windows::Foundation::DateTime AppNotification::Expiration() { auto lock{ m_lock.lock_shared() }; return m_expirationTime; @@ -112,7 +130,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation { auto lock{ m_lock.lock_exclusive() }; m_suppressDisplay = suppressDisplay; - } + }*/ void AppNotification::SetNotificationId(uint32_t id) { diff --git a/dev/AppNotifications/AppNotification.h b/dev/AppNotifications/AppNotification.h index e48c0fa6e4..1041652c60 100644 --- a/dev/AppNotifications/AppNotification.h +++ b/dev/AppNotifications/AppNotification.h @@ -3,6 +3,7 @@ #pragma once #include "Microsoft.Windows.AppNotifications.AppNotification.g.h" +#include "BaseNotification.h" namespace winrt::Microsoft::Windows::AppNotifications::implementation { @@ -12,27 +13,27 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation virtual void SetNotificationId(uint32_t id) = 0; }; - struct AppNotification : AppNotificationT + struct AppNotification : AppNotificationT, public ::Microsoft::Windows::BaseNotifications::BaseNotification { - AppNotification() = default; + AppNotification(); AppNotification(hstring const& payload); - hstring Tag(); + /* hstring Tag(); void Tag(hstring const& value); hstring Group(); void Group(hstring const& value); uint32_t Id(); - hstring Payload(); + hstring Payload(); */ winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData Progress(); void Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& value); - winrt::Windows::Foundation::DateTime Expiration(); + /*winrt::Windows::Foundation::DateTime Expiration(); void Expiration(winrt::Windows::Foundation::DateTime const& value); bool ExpiresOnReboot(); void ExpiresOnReboot(bool value); winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority Priority(); void Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& value); bool SuppressDisplay(); - void SuppressDisplay(bool value); + void SuppressDisplay(bool value);*/ // IAppNotificationInternal void SetNotificationId(uint32_t id); @@ -41,17 +42,17 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation void ConferencingConfig(winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig const& value); private: - winrt::hstring m_tag{}; + /* winrt::hstring m_tag{}; winrt::hstring m_group{}; uint32_t m_notificationId{ 0 }; - winrt::hstring m_payload{}; + winrt::hstring m_payload{};*/ winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData m_progressData{ nullptr }; - winrt::Windows::Foundation::DateTime m_expirationTime{}; + /*winrt::Windows::Foundation::DateTime m_expirationTime{}; bool m_expiresOnReboot{ false }; winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority { winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default }; bool m_suppressDisplay{ false }; - wil::srwlock m_lock; + wil::srwlock m_lock;*/ winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig m_conferencingConfig{ nullptr }; }; diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index a5b54c7a1a..2c4b396ac7 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -62,7 +62,7 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa m_notificationType = ToastABI::NotificationType::NotificationType_Toast; } -NotificationProperties::NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification const& badgeNotification) +NotificationProperties::NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification &badgeNotification) { // Extract payload and convert it from XML to a byte array auto payloadAsSimpleString = Helpers::WideStringToUtf8String(badgeNotification.Payload()); diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index e66bad9991..d975cc0e97 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -11,7 +11,7 @@ struct NotificationProperties : winrt::implements Date: Fri, 6 Dec 2024 16:08:26 +0530 Subject: [PATCH 14/19] AppNotification Refactoring --- dev/AppNotifications/AppNotification.cpp | 94 ------------------------ dev/AppNotifications/AppNotification.h | 25 ------- 2 files changed, 119 deletions(-) diff --git a/dev/AppNotifications/AppNotification.cpp b/dev/AppNotifications/AppNotification.cpp index 31a22b3a79..95ec873382 100644 --- a/dev/AppNotifications/AppNotification.cpp +++ b/dev/AppNotifications/AppNotification.cpp @@ -18,60 +18,14 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation { AppNotification::AppNotification() : BaseNotification() { - //XmlDocument xmlDocument{}; - - //// We call LoadXml to verify the payload is xml - //xmlDocument.LoadXml(payload); - //m_payload = payload; BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); } AppNotification::AppNotification(hstring const& payload) : BaseNotification(payload) { - //XmlDocument xmlDocument{}; - - //// We call LoadXml to verify the payload is xml - //xmlDocument.LoadXml(payload); - //m_payload = payload; BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); } - /*hstring AppNotification::Tag() - { - auto lock{ m_lock.lock_shared() }; - return m_tag; - } - - void AppNotification::Tag(hstring const& tag) - { - auto lock{ m_lock.lock_exclusive() }; - m_tag = tag; - } - - hstring AppNotification::Group() - { - auto lock{ m_lock.lock_shared() }; - return m_group; - } - - void AppNotification::Group(hstring const& group) - { - auto lock{ m_lock.lock_exclusive() }; - m_group = group; - } - - uint32_t AppNotification::Id() - { - auto lock{ m_lock.lock_shared() }; - return m_notificationId; - } - - hstring AppNotification::Payload() - { - auto lock{ m_lock.lock_shared() }; - return m_payload; - }*/ - winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData AppNotification::Progress() { auto lock{ m_lock.lock_shared() }; @@ -84,54 +38,6 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation m_progressData = progressData; } - /*winrt::Windows::Foundation::DateTime AppNotification::Expiration() - { - auto lock{ m_lock.lock_shared() }; - return m_expirationTime; - } - - void AppNotification::Expiration(winrt::Windows::Foundation::DateTime const& expirationTime) - { - auto lock{ m_lock.lock_exclusive() }; - m_expirationTime = expirationTime; - } - - bool AppNotification::ExpiresOnReboot() - { - auto lock{ m_lock.lock_shared() }; - return m_expiresOnReboot; - } - - void AppNotification::ExpiresOnReboot(bool expiresOnReboot) - { - auto lock{ m_lock.lock_exclusive() }; - m_expiresOnReboot = expiresOnReboot; - } - - winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority AppNotification::Priority() - { - auto lock{ m_lock.lock_shared() }; - return m_priority; - } - - void AppNotification::Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& priority) - { - auto lock{ m_lock.lock_exclusive() }; - m_priority = priority; - } - - bool AppNotification::SuppressDisplay() - { - auto lock{ m_lock.lock_shared() }; - return m_suppressDisplay; - } - - void AppNotification::SuppressDisplay(bool suppressDisplay) - { - auto lock{ m_lock.lock_exclusive() }; - m_suppressDisplay = suppressDisplay; - }*/ - void AppNotification::SetNotificationId(uint32_t id) { auto lock{ m_lock.lock_exclusive() }; diff --git a/dev/AppNotifications/AppNotification.h b/dev/AppNotifications/AppNotification.h index 1041652c60..fa39986823 100644 --- a/dev/AppNotifications/AppNotification.h +++ b/dev/AppNotifications/AppNotification.h @@ -18,22 +18,8 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation AppNotification(); AppNotification(hstring const& payload); - /* hstring Tag(); - void Tag(hstring const& value); - hstring Group(); - void Group(hstring const& value); - uint32_t Id(); - hstring Payload(); */ winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData Progress(); void Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& value); - /*winrt::Windows::Foundation::DateTime Expiration(); - void Expiration(winrt::Windows::Foundation::DateTime const& value); - bool ExpiresOnReboot(); - void ExpiresOnReboot(bool value); - winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority Priority(); - void Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& value); - bool SuppressDisplay(); - void SuppressDisplay(bool value);*/ // IAppNotificationInternal void SetNotificationId(uint32_t id); @@ -42,18 +28,7 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation void ConferencingConfig(winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig const& value); private: - /* winrt::hstring m_tag{}; - winrt::hstring m_group{}; - uint32_t m_notificationId{ 0 }; - winrt::hstring m_payload{};*/ winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData m_progressData{ nullptr }; - /*winrt::Windows::Foundation::DateTime m_expirationTime{}; - bool m_expiresOnReboot{ false }; - winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority - { winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default }; - bool m_suppressDisplay{ false }; - wil::srwlock m_lock;*/ - winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig m_conferencingConfig{ nullptr }; }; } From 2ede38b5270738c47641a95570d9ddc4dd3f934e Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Mon, 9 Dec 2024 13:35:49 +0530 Subject: [PATCH 15/19] Resolved PR comments --- .../NotificationProperties.cpp | 22 +++++++------------ dev/AppNotifications/NotificationProperties.h | 1 + .../BadgeNotificationManager.cpp | 18 ++++++--------- .../BadgeNotificationManager.h | 3 +-- .../BadgeNotifications/BadgeNotifications.idl | 8 +++---- .../BaseNotifications/BaseNotification.cpp | 14 ++++++------ .../PushNotificationUtility.h | 4 ++-- 7 files changed, 30 insertions(+), 40 deletions(-) diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index 2c4b396ac7..370e4e9437 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -28,12 +28,7 @@ namespace Helpers NotificationProperties::NotificationProperties(winrt::AppNotification const& toastNotification) { - // Extract payload and convert it from XML to a byte array - auto payloadAsSimpleString = Helpers::WideStringToUtf8String(toastNotification.Payload()); - - m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); - THROW_IF_NULL_ALLOC(m_payload.get()); - CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); + m_payloadHstring = toastNotification.Payload(); m_notificationId = toastNotification.Id(); @@ -64,12 +59,7 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa NotificationProperties::NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification &badgeNotification) { - // Extract payload and convert it from XML to a byte array - auto payloadAsSimpleString = Helpers::WideStringToUtf8String(badgeNotification.Payload()); - - m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); - THROW_IF_NULL_ALLOC(m_payload.get()); - CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); + m_payloadHstring = badgeNotification.Payload(); m_notificationId = badgeNotification.Id(); @@ -96,13 +86,17 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_Payload(_Out_ unsig { auto lock{ m_lock.lock_shared() }; - size_t tempPayloadSize = m_payload.size(); + auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(m_payloadHstring); + + size_t tempPayloadSize = payloadAsSimpleString.size(); auto tempPayload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(tempPayloadSize)), tempPayloadSize); - CopyMemory(tempPayload.data(), m_payload.get(), tempPayloadSize); + THROW_IF_NULL_ALLOC(tempPayload.get()); + CopyMemory(tempPayload.data(), payloadAsSimpleString.c_str(), tempPayloadSize); *payloadSize = static_cast(tempPayloadSize); *payload = tempPayload.release(); + return S_OK; } CATCH_RETURN() diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index d975cc0e97..2a9f2f2f42 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -45,6 +45,7 @@ struct NotificationProperties : winrt::implements m_payload; + winrt::hstring m_payloadHstring; std::wstring m_tag; std::wstring m_group; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index e6633f1988..921cafc416 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -85,10 +85,9 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); - PCWSTR glyphValueString; - GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + std::wstring glyphValueString = GetBadgeNotificationGlyphToString(glyphValue); - THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString == NULL, "Invalid Glyph value"); + THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString.empty(), "Invalid Glyph value"); SetBadge(glyphValueString, nullptr); return; @@ -98,10 +97,9 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); - PCWSTR glyphValueString; - GetBadgeNotificationGlyphToString(glyphValue, &glyphValueString); + std::wstring glyphValueString = GetBadgeNotificationGlyphToString(glyphValue); - THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString == NULL, "Invalid Glyph value"); + THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString.empty(), "Invalid Glyph value"); SetBadge(glyphValueString, &expiration); return; @@ -122,7 +120,7 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation return; } - void BadgeNotificationManager::GetBadgeNotificationGlyphToString(_In_ winrt::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString) + std::wstring BadgeNotificationManager::GetBadgeNotificationGlyphToString(_In_ winrt::BadgeNotificationGlyph glyphValue) { constexpr static std::pair enumMapping[] = { {winrt::BadgeNotificationGlyph::None, L"none"}, @@ -147,14 +145,12 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation if (it != std::end(enumMapping)) { - *glyphString = it->second; + return std::wstring(it->second); // Return the string directly } else { - *glyphString = nullptr; + return std::wstring(); // Return an empty string if not found } - - return; } void BadgeNotificationManager::SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration) diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h index e617ad7bd1..75c3542112 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.h @@ -22,9 +22,8 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation void ClearBadge(); private: - void GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue, _Out_ PCWSTR* glyphString); + std::wstring GetBadgeNotificationGlyphToString(_In_ winrt::Microsoft::Windows::BadgeNotifications::BadgeNotificationGlyph glyphValue); void SetBadge(_In_ const std::wstring& value, _In_opt_ const winrt::Windows::Foundation::DateTime* expiration); - wil::srwlock m_lock; std::wstring m_processName; std::wstring m_appId; }; diff --git a/dev/Notifications/BadgeNotifications/BadgeNotifications.idl b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl index 19c6366aa1..5f23e83b57 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotifications.idl +++ b/dev/Notifications/BadgeNotifications/BadgeNotifications.idl @@ -34,16 +34,16 @@ namespace Microsoft.Windows.BadgeNotifications // Gets a Default instance of a BadgeNotificationManager static BadgeNotificationManager Current{ get; }; - // Updates the badge on the app's tile to display a numeric value. + // Updates the badge on the app's icon on taskbar to display a numeric value. void SetBadgeAsCount(UInt32 notificationCount); - // Updates the badge on the app's tile to display a numeric value with an expiration time. + // Updates the badge on the app's icon on taskbar to display a numeric value with an expiration time. void SetBadgeAsCount(UInt32 notificationCount, Windows.Foundation.DateTime expiration); - // Updates the badge on the app's tile to display a glyph. + // Updates the badge on the app's icon on taskbar to display a glyph. void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue); - // Updates the badge on the app's tile to display a glyph with an expiration time. + // Updates the badge on the app's icon on taskbar to display a glyph with an expiration time. void SetBadgeAsGlyph(BadgeNotificationGlyph glyphValue, Windows.Foundation.DateTime expiration); // Removes the Badge Notifications for the App from Action Center diff --git a/dev/Notifications/BaseNotifications/BaseNotification.cpp b/dev/Notifications/BaseNotifications/BaseNotification.cpp index 9940225412..732ebd4c8d 100644 --- a/dev/Notifications/BaseNotifications/BaseNotification.cpp +++ b/dev/Notifications/BaseNotifications/BaseNotification.cpp @@ -24,7 +24,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::Tag(winrt::hstring const& tag) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_tag = tag; } @@ -36,7 +36,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::Group(winrt::hstring const& group) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_group = group; } @@ -60,7 +60,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::Expiration(winrt::Windows::Foundation::DateTime const& expirationTime) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_expirationTime = expirationTime; } @@ -72,7 +72,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::ExpiresOnReboot(bool expiresOnReboot) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_expiresOnReboot = expiresOnReboot; } @@ -84,7 +84,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& priority) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_priority = priority; } @@ -96,7 +96,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::SuppressDisplay(bool suppressDisplay) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_suppressDisplay = suppressDisplay; } @@ -114,7 +114,7 @@ namespace Microsoft::Windows::BaseNotifications { void BaseNotification::NotificationType(::ABI::Microsoft::Internal::ToastNotifications::NotificationType value) { - auto lock{ m_lock.lock_shared() }; + auto lock{ m_lock.lock_exclusive() }; m_notificationType = value; } } diff --git a/dev/PushNotifications/PushNotificationUtility.h b/dev/PushNotifications/PushNotificationUtility.h index ae797af578..30d17227fa 100644 --- a/dev/PushNotifications/PushNotificationUtility.h +++ b/dev/PushNotifications/PushNotificationUtility.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation and Contributors. +// Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. #pragma once @@ -23,7 +23,7 @@ namespace winrt::Microsoft::Windows::PushNotifications::Helpers inline constexpr std::wstring_view c_argumentCommandString = L"Arguments"; inline constexpr std::wstring_view c_executableCommandString = L"Executable"; - inline std::string WideStringToUtf8String(_In_ winrt::hstring const& utf16string) + inline std::string WideStringToPayloadUtf8String(_In_ winrt::hstring const& utf16string) { int size = WideCharToMultiByte( CP_UTF8, From 159ce0fcbc541a7a1de8cd1a375dec11abd9443e Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Mon, 9 Dec 2024 14:12:26 +0530 Subject: [PATCH 16/19] Resolved PR comments --- dev/AppNotifications/NotificationProperties.cpp | 13 +++++++++++-- dev/AppNotifications/NotificationProperties.h | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index 370e4e9437..b56187b68b 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -94,7 +94,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_Payload(_Out_ unsig THROW_IF_NULL_ALLOC(tempPayload.get()); CopyMemory(tempPayload.data(), payloadAsSimpleString.c_str(), tempPayloadSize); - *payloadSize = static_cast(tempPayloadSize); + *payloadSize = static_cast(tempPayload.size()); *payload = tempPayload.release(); return S_OK; @@ -105,7 +105,16 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_PayloadSize(_Out_ u { auto lock{ m_lock.lock_shared() }; - *payloadSize = static_cast(m_payload.size()); + auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(m_payloadHstring); + + size_t tempPayloadSize = payloadAsSimpleString.size(); + + auto tempPayload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(tempPayloadSize)), tempPayloadSize); + THROW_IF_NULL_ALLOC(tempPayload.get()); + CopyMemory(tempPayload.data(), payloadAsSimpleString.c_str(), tempPayloadSize); + + *payloadSize = static_cast(tempPayload.size()); + return S_OK; } diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index 2a9f2f2f42..04179ee45c 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -44,7 +44,6 @@ struct NotificationProperties : winrt::implements m_payload; winrt::hstring m_payloadHstring; std::wstring m_tag; From 904db6df2d4ed15dd46f91bcfb8333c0b4f06f57 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Mon, 9 Dec 2024 17:08:37 +0530 Subject: [PATCH 17/19] badge code changes --- .../NotificationProperties.cpp | 35 +++++++++---------- dev/AppNotifications/NotificationProperties.h | 2 +- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/dev/AppNotifications/NotificationProperties.cpp b/dev/AppNotifications/NotificationProperties.cpp index b56187b68b..2dfe21f253 100644 --- a/dev/AppNotifications/NotificationProperties.cpp +++ b/dev/AppNotifications/NotificationProperties.cpp @@ -28,7 +28,12 @@ namespace Helpers NotificationProperties::NotificationProperties(winrt::AppNotification const& toastNotification) { - m_payloadHstring = toastNotification.Payload(); + // Extract payload and convert it from XML to a byte array + auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(toastNotification.Payload()); + + m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); + THROW_IF_NULL_ALLOC(m_payload.get()); + CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); m_notificationId = toastNotification.Id(); @@ -59,7 +64,12 @@ NotificationProperties::NotificationProperties(winrt::AppNotification const& toa NotificationProperties::NotificationProperties(Microsoft::Windows::BadgeNotifications::BadgeNotification &badgeNotification) { - m_payloadHstring = badgeNotification.Payload(); + // Extract payload and convert it from XML to a byte array + auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(badgeNotification.Payload()); + + m_payload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(payloadAsSimpleString.size())), payloadAsSimpleString.size()); + THROW_IF_NULL_ALLOC(m_payload.get()); + CopyMemory(m_payload.data(), payloadAsSimpleString.c_str(), payloadAsSimpleString.size()); m_notificationId = badgeNotification.Id(); @@ -86,17 +96,13 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_Payload(_Out_ unsig { auto lock{ m_lock.lock_shared() }; - auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(m_payloadHstring); - - size_t tempPayloadSize = payloadAsSimpleString.size(); + size_t tempPayloadSize = m_payload.size(); auto tempPayload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(tempPayloadSize)), tempPayloadSize); - THROW_IF_NULL_ALLOC(tempPayload.get()); - CopyMemory(tempPayload.data(), payloadAsSimpleString.c_str(), tempPayloadSize); + CopyMemory(tempPayload.data(), m_payload.get(), tempPayloadSize); - *payloadSize = static_cast(tempPayload.size()); + *payloadSize = static_cast(tempPayloadSize); *payload = tempPayload.release(); - return S_OK; } CATCH_RETURN() @@ -105,16 +111,7 @@ STDMETHODIMP_(HRESULT __stdcall) NotificationProperties::get_PayloadSize(_Out_ u { auto lock{ m_lock.lock_shared() }; - auto payloadAsSimpleString = Helpers::WideStringToPayloadUtf8String(m_payloadHstring); - - size_t tempPayloadSize = payloadAsSimpleString.size(); - - auto tempPayload = wil::unique_cotaskmem_array_ptr(static_cast(CoTaskMemAlloc(tempPayloadSize)), tempPayloadSize); - THROW_IF_NULL_ALLOC(tempPayload.get()); - CopyMemory(tempPayload.data(), payloadAsSimpleString.c_str(), tempPayloadSize); - - *payloadSize = static_cast(tempPayload.size()); - + *payloadSize = static_cast(m_payload.size()); return S_OK; } diff --git a/dev/AppNotifications/NotificationProperties.h b/dev/AppNotifications/NotificationProperties.h index 04179ee45c..d975cc0e97 100644 --- a/dev/AppNotifications/NotificationProperties.h +++ b/dev/AppNotifications/NotificationProperties.h @@ -44,7 +44,7 @@ struct NotificationProperties : winrt::implements m_payload; std::wstring m_tag; std::wstring m_group; From 6e3547676899a4791ae4ec87458d0b35fb564a08 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Wed, 11 Dec 2024 11:21:56 +0530 Subject: [PATCH 18/19] decouple app notification code changes --- dev/AppNotifications/AppNotification.cpp | 98 +++++++++++++++++++++--- dev/AppNotifications/AppNotification.h | 30 +++++++- 2 files changed, 114 insertions(+), 14 deletions(-) diff --git a/dev/AppNotifications/AppNotification.cpp b/dev/AppNotifications/AppNotification.cpp index 95ec873382..d1a15aec90 100644 --- a/dev/AppNotifications/AppNotification.cpp +++ b/dev/AppNotifications/AppNotification.cpp @@ -4,26 +4,54 @@ #include "pch.h" #include "AppNotification.h" #include "Microsoft.Windows.AppNotifications.AppNotification.g.cpp" -#include using namespace winrt::Windows::Data::Xml::Dom; -using namespace Microsoft::Windows::BaseNotifications; - -namespace ToastABI -{ - using namespace ::ABI::Microsoft::Internal::ToastNotifications; -} namespace winrt::Microsoft::Windows::AppNotifications::implementation { - AppNotification::AppNotification() : BaseNotification() + AppNotification::AppNotification(hstring const& payload) { - BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); + XmlDocument xmlDocument{}; + + // We call LoadXml to verify the payload is xml + xmlDocument.LoadXml(payload); + m_payload = payload; } - AppNotification::AppNotification(hstring const& payload) : BaseNotification(payload) + hstring AppNotification::Tag() { - BaseNotification::NotificationType(ToastABI::NotificationType::NotificationType_Toast); + auto lock{ m_lock.lock_shared() }; + return m_tag; + } + + void AppNotification::Tag(hstring const& tag) + { + auto lock{ m_lock.lock_exclusive() }; + m_tag = tag; + } + + hstring AppNotification::Group() + { + auto lock{ m_lock.lock_shared() }; + return m_group; + } + + void AppNotification::Group(hstring const& group) + { + auto lock{ m_lock.lock_exclusive() }; + m_group = group; + } + + uint32_t AppNotification::Id() + { + auto lock{ m_lock.lock_shared() }; + return m_notificationId; + } + + hstring AppNotification::Payload() + { + auto lock{ m_lock.lock_shared() }; + return m_payload; } winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData AppNotification::Progress() @@ -38,6 +66,54 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation m_progressData = progressData; } + winrt::Windows::Foundation::DateTime AppNotification::Expiration() + { + auto lock{ m_lock.lock_shared() }; + return m_expirationTime; + } + + void AppNotification::Expiration(winrt::Windows::Foundation::DateTime const& expirationTime) + { + auto lock{ m_lock.lock_exclusive() }; + m_expirationTime = expirationTime; + } + + bool AppNotification::ExpiresOnReboot() + { + auto lock{ m_lock.lock_shared() }; + return m_expiresOnReboot; + } + + void AppNotification::ExpiresOnReboot(bool expiresOnReboot) + { + auto lock{ m_lock.lock_exclusive() }; + m_expiresOnReboot = expiresOnReboot; + } + + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority AppNotification::Priority() + { + auto lock{ m_lock.lock_shared() }; + return m_priority; + } + + void AppNotification::Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& priority) + { + auto lock{ m_lock.lock_exclusive() }; + m_priority = priority; + } + + bool AppNotification::SuppressDisplay() + { + auto lock{ m_lock.lock_shared() }; + return m_suppressDisplay; + } + + void AppNotification::SuppressDisplay(bool suppressDisplay) + { + auto lock{ m_lock.lock_exclusive() }; + m_suppressDisplay = suppressDisplay; + } + void AppNotification::SetNotificationId(uint32_t id) { auto lock{ m_lock.lock_exclusive() }; diff --git a/dev/AppNotifications/AppNotification.h b/dev/AppNotifications/AppNotification.h index fa39986823..e48c0fa6e4 100644 --- a/dev/AppNotifications/AppNotification.h +++ b/dev/AppNotifications/AppNotification.h @@ -3,7 +3,6 @@ #pragma once #include "Microsoft.Windows.AppNotifications.AppNotification.g.h" -#include "BaseNotification.h" namespace winrt::Microsoft::Windows::AppNotifications::implementation { @@ -13,13 +12,27 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation virtual void SetNotificationId(uint32_t id) = 0; }; - struct AppNotification : AppNotificationT, public ::Microsoft::Windows::BaseNotifications::BaseNotification + struct AppNotification : AppNotificationT { - AppNotification(); + AppNotification() = default; AppNotification(hstring const& payload); + hstring Tag(); + void Tag(hstring const& value); + hstring Group(); + void Group(hstring const& value); + uint32_t Id(); + hstring Payload(); winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData Progress(); void Progress(winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData const& value); + winrt::Windows::Foundation::DateTime Expiration(); + void Expiration(winrt::Windows::Foundation::DateTime const& value); + bool ExpiresOnReboot(); + void ExpiresOnReboot(bool value); + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority Priority(); + void Priority(winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority const& value); + bool SuppressDisplay(); + void SuppressDisplay(bool value); // IAppNotificationInternal void SetNotificationId(uint32_t id); @@ -28,7 +41,18 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation void ConferencingConfig(winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig const& value); private: + winrt::hstring m_tag{}; + winrt::hstring m_group{}; + uint32_t m_notificationId{ 0 }; + winrt::hstring m_payload{}; winrt::Microsoft::Windows::AppNotifications::AppNotificationProgressData m_progressData{ nullptr }; + winrt::Windows::Foundation::DateTime m_expirationTime{}; + bool m_expiresOnReboot{ false }; + winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority m_priority + { winrt::Microsoft::Windows::AppNotifications::AppNotificationPriority::Default }; + bool m_suppressDisplay{ false }; + wil::srwlock m_lock; + winrt::Microsoft::Windows::AppNotifications::AppNotificationConferencingConfig m_conferencingConfig{ nullptr }; }; } From 345d704c07c08a2ded1ff5f098b6da84c0cfaf12 Mon Sep 17 00:00:00 2001 From: Satwik Kumar Sharma Date: Thu, 12 Dec 2024 10:55:02 +0530 Subject: [PATCH 19/19] corrected the telemetry events --- .../BadgeNotificationManager.cpp | 36 ++++++++++--- .../BadgeNotificationTelemetry.h | 53 +++++++++++++++++-- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp index 921cafc416..bf9c4b4734 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationManager.cpp @@ -69,7 +69,14 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + auto logTelemetry{ BadgeNotificationTelemetry::SetBadgeAsCount::Start( + g_telemetryHelper, + m_appId) }; + SetBadge(std::to_wstring(notificationCount), nullptr); + + logTelemetry.Stop(); + return; } @@ -77,7 +84,14 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + auto logTelemetry{ BadgeNotificationTelemetry::SetBadgeAsCountWithExpiration::Start( + g_telemetryHelper, + m_appId) }; + SetBadge(std::to_wstring(notificationCount), &expiration); + + logTelemetry.Stop(); + return; } @@ -85,11 +99,18 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + auto logTelemetry{ BadgeNotificationTelemetry::SetBadgeAsGlyph::Start( + g_telemetryHelper, + m_appId) }; + std::wstring glyphValueString = GetBadgeNotificationGlyphToString(glyphValue); THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString.empty(), "Invalid Glyph value"); SetBadge(glyphValueString, nullptr); + + logTelemetry.Stop(); + return; } @@ -97,11 +118,18 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation { THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications"); + auto logTelemetry{ BadgeNotificationTelemetry::SetBadgeAsGlyphWithExpiration::Start( + g_telemetryHelper, + m_appId) }; + std::wstring glyphValueString = GetBadgeNotificationGlyphToString(glyphValue); THROW_HR_IF_MSG(E_INVALIDARG, glyphValueString.empty(), "Invalid Glyph value"); SetBadge(glyphValueString, &expiration); + + logTelemetry.Stop(); + return; } @@ -158,11 +186,6 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation auto xmlResult = wil::str_printf(L"", value.c_str()); ::Microsoft::Windows::BadgeNotifications::BadgeNotification badgeNotification(xmlResult.c_str()); - auto logTelemetry{ BadgeNotificationTelemetry::SetBadge::Start( - g_telemetryHelper, - m_appId, - badgeNotification.Payload().c_str()) }; - if (expiration != nullptr) { badgeNotification.Expiration(*expiration); @@ -180,7 +203,6 @@ namespace winrt::Microsoft::Windows::BadgeNotifications::implementation THROW_HR_IF(E_UNEXPECTED, notificationId == 0); badgeNotification.Id(notificationId); - - logTelemetry.Stop(); + return; } } diff --git a/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h index c2ae4b0df8..2abe43ad7a 100644 --- a/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h +++ b/dev/Notifications/BadgeNotifications/BadgeNotificationTelemetry.h @@ -16,17 +16,60 @@ class BadgeNotificationTelemetry : public wil::TraceLoggingProvider IMPLEMENT_TELEMETRY_CLASS(BadgeNotificationTelemetry, BadgeNotificationTelemetryProvider); public: - BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadge, PDT_ProductAndServicePerformance); + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadgeAsCount, PDT_ProductAndServicePerformance); DEFINE_ACTIVITY_START( NotificationTelemetryHelper& notificationTelemetryHelper, - std::wstring const& appId, - std::wstring const& payload) noexcept try + std::wstring const& appId) noexcept try + { + TraceLoggingClassWriteStart( + SetBadgeAsCount, + _GENERIC_PARTB_FIELDS_ENABLED, + TraceLoggingWideString(appId.c_str(), "AppId"), + TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), + TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); + } + CATCH_LOG() + END_ACTIVITY_CLASS(); + + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadgeAsCountWithExpiration, PDT_ProductAndServicePerformance); + DEFINE_ACTIVITY_START( + NotificationTelemetryHelper& notificationTelemetryHelper, + std::wstring const& appId) noexcept try + { + TraceLoggingClassWriteStart( + SetBadgeAsCountWithExpiration, + _GENERIC_PARTB_FIELDS_ENABLED, + TraceLoggingWideString(appId.c_str(), "AppId"), + TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), + TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); + } + CATCH_LOG() + END_ACTIVITY_CLASS(); + + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadgeAsGlyph, PDT_ProductAndServicePerformance); + DEFINE_ACTIVITY_START( + NotificationTelemetryHelper& notificationTelemetryHelper, + std::wstring const& appId) noexcept try + { + TraceLoggingClassWriteStart( + SetBadgeAsGlyph, + _GENERIC_PARTB_FIELDS_ENABLED, + TraceLoggingWideString(appId.c_str(), "AppId"), + TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), + TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); + } + CATCH_LOG() + END_ACTIVITY_CLASS(); + + BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(SetBadgeAsGlyphWithExpiration, PDT_ProductAndServicePerformance); + DEFINE_ACTIVITY_START( + NotificationTelemetryHelper& notificationTelemetryHelper, + std::wstring const& appId) noexcept try { TraceLoggingClassWriteStart( - SetBadge, + SetBadgeAsGlyphWithExpiration, _GENERIC_PARTB_FIELDS_ENABLED, TraceLoggingWideString(appId.c_str(), "AppId"), - TraceLoggingWideString(payload.c_str(), "PayloadSize"), TraceLoggingBool(notificationTelemetryHelper.IsPackagedApp(), "IsAppPackaged"), TraceLoggingWideString(notificationTelemetryHelper.GetAppName().c_str(), "AppName")); }