From a7f14c8d419bca5698c2a92e0dffac2b9df7f314 Mon Sep 17 00:00:00 2001 From: Eric Langlois Date: Mon, 17 Oct 2022 10:13:57 -0700 Subject: [PATCH 1/4] Updating samples to latest SDK --- .../CppUnpackagedAppNotifications.vcxproj | 28 +++++++++---------- ...UnpackagedAppNotifications.vcxproj.filters | 2 +- .../packages.config | 8 +++--- .../CsUnpackagedAppNotifications.csproj | 14 +++++++--- .../MainWindow.xaml.cs | 3 -- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj index 88ff48e54..58a042ac6 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj @@ -1,8 +1,8 @@  - - - + + + true true @@ -220,21 +220,21 @@ - - - - + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - + + + + + + + \ No newline at end of file diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters index 071a538b2..299536593 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters @@ -80,4 +80,4 @@ - + \ No newline at end of file diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/packages.config b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/packages.config index 076923507..745663331 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/packages.config +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file diff --git a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj index e4099c53a..3d5cc1a87 100644 --- a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj +++ b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj @@ -1,8 +1,9 @@  WinExe - net5.0-windows10.0.19041.0 + net6.0-windows10.0.19041.0 10.0.17763.0 + 10.0.17763.0 CsUnpackagedAppNotifications app.manifest x86;x64;arm64 @@ -11,12 +12,17 @@ true Properties\PublishProfiles\win10-$(Platform).pubxml None + 10.0.18362.0 - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/MainWindow.xaml.cs b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/MainWindow.xaml.cs index ba2c00822..5103ef367 100644 --- a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/MainWindow.xaml.cs +++ b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/MainWindow.xaml.cs @@ -2,13 +2,10 @@ // Licensed under the MIT License. using Microsoft.UI.Xaml; -using System; using System.Runtime.InteropServices; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Gdi; -using Windows.Win32.UI.Controls; using Windows.Win32.UI.WindowsAndMessaging; -using static Windows.Win32.Constants; using static Windows.Win32.PInvoke; namespace CsUnpackagedAppNotifications From a044af3d3e50fd26d8d4f5f55d4c81e735b4ae80 Mon Sep 17 00:00:00 2001 From: Eric Langlois Date: Mon, 17 Oct 2022 10:20:23 -0700 Subject: [PATCH 2/4] Removing un-needed tag --- .../CsUnpackagedAppNotifications.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj index 3d5cc1a87..f3d598075 100644 --- a/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj +++ b/Samples/Notifications/App/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications/CsUnpackagedAppNotifications.csproj @@ -3,7 +3,6 @@ WinExe net6.0-windows10.0.19041.0 10.0.17763.0 - 10.0.17763.0 CsUnpackagedAppNotifications app.manifest x86;x64;arm64 From b390638fed834d5f7833f9bc9ed8d112c8ba16fc Mon Sep 17 00:00:00 2001 From: Eric Langlois Date: Mon, 24 Oct 2022 13:58:05 -0700 Subject: [PATCH 3/4] New scenario to showcase push / toast mixed scenarios --- .../CppUnpackagedAppNotifications.vcxproj | 9 ++++ ...UnpackagedAppNotifications.vcxproj.filters | 10 ++++ .../Notifications/PushToastWithAvatar.cpp | 47 +++++++++++++++++++ .../Notifications/PushToastWithAvatar.h | 15 ++++++ .../CppUnpackagedAppNotifications/Project.idl | 10 +++- .../SampleConfiguration.cpp | 4 +- .../Scenario3_PushToastWithAvatar.xaml | 32 +++++++++++++ .../Scenario3_PushToastWithAvatar.xaml.cpp | 41 ++++++++++++++++ .../Scenario3_PushToastWithAvatar.xaml.h | 27 +++++++++++ 9 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.cpp create mode 100644 Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.h create mode 100644 Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml create mode 100644 Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml.cpp create mode 100644 Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml.h diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj index 58a042ac6..0b98bc472 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj @@ -120,6 +120,7 @@ + @@ -139,6 +140,9 @@ Scenario2_ToastWithTextBox.xaml Code + + Scenario3_PushToastWithAvatar.xaml + SettingsPage.xaml Code @@ -156,6 +160,7 @@ Designer + Designer @@ -169,6 +174,7 @@ Code + @@ -191,6 +197,9 @@ Scenario2_ToastWithTextBox.xaml Code + + Scenario3_PushToastWithAvatar.xaml + SettingsPage.xaml Code diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters index 299536593..b88b277e2 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications.vcxproj.filters @@ -10,6 +10,7 @@ + @@ -28,6 +29,9 @@ Notifications + + Notifications + @@ -45,6 +49,9 @@ Notifications + + Notifications + @@ -80,4 +87,7 @@ + + + \ No newline at end of file diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.cpp b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.cpp new file mode 100644 index 000000000..1b3e4164e --- /dev/null +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.cpp @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#include "pch.h" +#include "PushToastWithAvatar.h" +#include "Common.h" +#include +#include +#include +#include "App.xaml.h" +#include "MainPage.xaml.h" + +namespace winrt +{ + using namespace Microsoft::Windows::AppNotifications; + using namespace Microsoft::Windows::AppNotifications::Builder; + using namespace CppUnpackagedAppNotifications::implementation; +} + +const wchar_t* PushToastWithAvatar::ScenarioName{ L"Push / Local Toast with Avatar Image" }; + +bool PushToastWithAvatar::SendToast() +{ + auto appNotification{ winrt::AppNotificationBuilder() + .AddArgument(L"action", L"ToastClick") + .AddArgument(Common::scenarioTag, std::to_wstring(PushToastWithAvatar::ScenarioId)) + .SetAppLogoOverride(winrt::Windows::Foundation::Uri(L"file://" + winrt::App::GetFullPathToAsset(L"Square150x150Logo.png")), winrt::AppNotificationImageCrop::Circle) + .AddText(ScenarioName) + .AddText(L"This is an example message using XML") + .AddButton(winrt::AppNotificationButton(L"Open App") + .AddArgument(L"action", L"OpenApp") + .AddArgument(Common::scenarioTag, std::to_wstring(PushToastWithAvatar::ScenarioId))) + .BuildNotification() }; + + winrt::AppNotificationManager::Default().Show(appNotification); + + return appNotification.Id() != 0; // return true (indicating success) if the toast was sent (if it has an Id) +} + +void PushToastWithAvatar::NotificationReceived(winrt::Microsoft::Windows::AppNotifications::AppNotificationActivatedEventArgs const& notificationActivatedEventArgs) +{ + winrt::CppUnpackagedAppNotifications::Notification notification{}; + notification.Originator = ScenarioName; + notification.Action = notificationActivatedEventArgs.Arguments().Lookup(L"action"); + winrt::MainPage::Current().NotificationReceived(notification); + winrt::App::ToForeground(); +} diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.h b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.h new file mode 100644 index 000000000..18e1c2972 --- /dev/null +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Notifications/PushToastWithAvatar.h @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once +#include + +struct PushToastWithAvatar +{ +public: + static const unsigned ScenarioId{ 1 }; + static const wchar_t* ScenarioName; + + static bool SendToast(); + static void NotificationReceived(winrt::Microsoft::Windows::AppNotifications::AppNotificationActivatedEventArgs const& notificationActivatedEventArgs); +}; diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Project.idl b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Project.idl index e83ce07b8..66ab7b8e8 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Project.idl +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Project.idl @@ -26,8 +26,14 @@ namespace CppUnpackagedAppNotifications Scenario2_ToastWithTextBox(); } - /* The following code is template-specific IDL. - These runtime classes are the same across all C++/WinRT WinUI samples. */ + [default_interface] + runtimeclass Scenario3_PushToastWithAvatar : Microsoft.UI.Xaml.Controls.Page + { + Scenario3_PushToastWithAvatar(); + } + + /* The following code is template-specific IDL. + These runtime classes are the same across all C++/WinRT WinUI samples. */ runtimeclass MainPage : Microsoft.UI.Xaml.Controls.Page { diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/SampleConfiguration.cpp b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/SampleConfiguration.cpp index d619ac12f..ca1a33c65 100644 --- a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/SampleConfiguration.cpp +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/SampleConfiguration.cpp @@ -7,6 +7,7 @@ #include "MainPage.xaml.h" #include "Notifications\ToastWithAvatar.h" #include "Notifications\ToastWithTextBox.h" +#include "Notifications\PushToastWithAvatar.h" namespace winrt { @@ -19,7 +20,8 @@ namespace winrt::CppUnpackagedAppNotifications IVector implementation::MainPage::scenariosInner = single_threaded_observable_vector( { Scenario{ ToastWithAvatar::ScenarioName, hstring(name_of())}, - Scenario{ ToastWithTextBox::ScenarioName, hstring(name_of())} + Scenario{ ToastWithTextBox::ScenarioName, hstring(name_of())}, + Scenario{ PushToastWithAvatar::ScenarioName, hstring(name_of())} }); hstring SampleConfig::FeatureName{ L"CppUnpackagedAppNotifications" }; diff --git a/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml new file mode 100644 index 000000000..0666aa874 --- /dev/null +++ b/Samples/Notifications/App/CppUnpackagedAppNotifications/CppUnpackagedAppNotifications/Scenario3_PushToastWithAvatar.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + This example demonstrates using a raw XML payload to produce a local toast notification with an avatar image and activation. + + +