@@ -241,7 +241,7 @@ std::wstring Microsoft::Windows::AppNotifications::Helpers::GetDisplayNameBasedO
241241 return displayName;
242242}
243243
244- winrt::guid Microsoft::Windows::AppNotifications::Helpers::RegisterComActivatorGuidAndAssets ()
244+ winrt::guid Microsoft::Windows::AppNotifications::Helpers::RegisterComActivatorGuidAndAssets (winrt::hstring const & displayName, std::wstring const & iconFilePath )
245245{
246246 std::wstring registeredGuid;
247247 auto hr = GetActivatorGuid (registeredGuid);
@@ -258,20 +258,42 @@ winrt::guid Microsoft::Windows::AppNotifications::Helpers::RegisterComActivatorG
258258 RegisterComServer (comActivatorGuidString);
259259
260260 registeredGuid = comActivatorGuidString.get ();
261+ std::wstring notificationAppId{ Microsoft::Windows::AppNotifications::Helpers::RetrieveNotificationAppId () };
262+ RegisterAssets (notificationAppId, registeredGuid, displayName, iconFilePath);
261263 }
262264 else
263265 {
264266 THROW_IF_FAILED (hr);
265267 }
266268
267- std::wstring notificationAppId{ Microsoft::Windows::AppNotifications::Helpers::RetrieveNotificationAppId () };
268- RegisterAssets (notificationAppId, registeredGuid);
269-
270269 // Remove braces around the guid string
271270 return winrt::guid (registeredGuid.substr (1 , registeredGuid.size () - 2 ));
272271}
273272
274- void Microsoft::Windows::AppNotifications::Helpers::RegisterAssets (std::wstring const & appId, std::wstring const & clsid)
273+ // Try the following techniques to retrieve display name and icon:
274+ // 1. Assets provided by the user
275+ // 2. Based on the best app shortcut, using the FrameworkUdk.
276+ // 3. From the current process.
277+ // 4. Set a default DisplayName, but leave empty the icon file path so Shell can set a default icon.
278+ Microsoft::Windows::AppNotifications::ShellLocalization::AppNotificationAssets Microsoft::Windows::AppNotifications::Helpers::RegisterAssetsHelper (winrt::hstring const & displayName, std::wstring const & iconFilePath)
279+ {
280+ Microsoft::Windows::AppNotifications::ShellLocalization::AppNotificationAssets assets{};
281+
282+ if ((!displayName.empty ()) && (!iconFilePath.empty ()))
283+ {
284+ assets.displayName = displayName.c_str ();
285+ assets.iconFilePath = iconFilePath.c_str ();
286+ }
287+ else if (FAILED (Microsoft::Windows::AppNotifications::ShellLocalization::RetrieveAssetsFromShortcut (assets)) &&
288+ FAILED (Microsoft::Windows::AppNotifications::ShellLocalization::RetrieveAssetsFromProcess (assets)))
289+ {
290+ assets.displayName = GetDisplayNameBasedOnProcessName ();
291+ }
292+
293+ return assets;
294+ }
295+
296+ void Microsoft::Windows::AppNotifications::Helpers::RegisterAssets (std::wstring const & appId, std::wstring const & clsid, winrt::hstring const & displayName, std::wstring const & iconFilePath)
275297{
276298 wil::unique_hkey hKey;
277299 // subKey: \Software\Classes\AppUserModelId\{AppGUID}
@@ -288,17 +310,7 @@ void Microsoft::Windows::AppNotifications::Helpers::RegisterAssets(std::wstring
288310 &hKey,
289311 nullptr /* lpdwDisposition */ ));
290312
291- // Try the following techniques to retrieve display name and icon:
292- // 1. Based on the best app shortcut, using the FrameworkUdk.
293- // 2. From the current process.
294- // 3. Set a default DisplayName, but leave empty the icon file path so Shell can set a default icon.
295- Microsoft::Windows::AppNotifications::ShellLocalization::AppNotificationAssets assets{};
296-
297- if (FAILED (Microsoft::Windows::AppNotifications::ShellLocalization::RetrieveAssetsFromShortcut (assets)) &&
298- FAILED (Microsoft::Windows::AppNotifications::ShellLocalization::RetrieveAssetsFromProcess (assets)))
299- {
300- assets.displayName = GetDisplayNameBasedOnProcessName ();
301- }
313+ Microsoft::Windows::AppNotifications::ShellLocalization::AppNotificationAssets assets{ RegisterAssetsHelper (displayName, iconFilePath) };
302314
303315 RegisterValue (hKey, L" DisplayName" , reinterpret_cast <const BYTE*>(assets.displayName .c_str ()), REG_EXPAND_SZ, assets.displayName .size () * sizeof (wchar_t ));
304316
0 commit comments