Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions WindowsAppRuntime.sln

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions build/NuSpecs/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@

<!-- PowerNotifications -->
<ActivatableClass ActivatableClassId="Microsoft.Windows.System.Power.PowerManager" ThreadingModel="both" />

<!-- ToastNotifications -->
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastActivationInfo" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastAssets" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ToastNotifications.ToastNotificationManager" ThreadingModel="both" />

</InProcessServer>
</Extension>
Expand Down
1 change: 1 addition & 0 deletions dev/AppLifecycle/ActivationRegistrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
static PCWSTR c_argumentSuffix{ L":" };
static PCWSTR c_msProtocolArgumentString{ L"ms-protocol" };
static PCWSTR c_pushProtocolArgumentString{ L"WindowsAppRuntimePushServer" };
static PCWSTR c_toastProtocolArgumentString{ L"ToastActivated" };
static PCWSTR c_runKeyPath{ LR"(Software\Microsoft\Windows\CurrentVersion\Run\)" };

struct ActivationRegistrationManager
Expand Down
6 changes: 3 additions & 3 deletions dev/AppLifecycle/AppInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "FileActivatedEventArgs.h"
#include "Association.h"
#include "ExtensionContract.h"
#include "GetRawNotificationEventArgs.h"
#include "GetNotificationEventArgs.h"

using namespace winrt;
using namespace winrt::Windows::Foundation;
Expand Down Expand Up @@ -376,10 +376,10 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
// protocol, except the catch-all LaunchActivatedEventArgs case.
if (!contractArgument.empty())
{
if (contractArgument == c_pushProtocolArgumentString)
if (contractArgument == c_pushProtocolArgumentString || contractArgument == c_toastProtocolArgumentString)
{
// Generate a basic encoded launch Uri for all Push activations.
std::wstring tempContractData = GenerateEncodedLaunchUri(L"App", c_pushContractId);
std::wstring tempContractData = (contractArgument == c_pushProtocolArgumentString) ? GenerateEncodedLaunchUri(L"App", c_pushContractId) : GenerateEncodedLaunchUri(L"App", c_toastContractId);
contractArgument = c_msProtocolArgumentString;

// A non-empty contractData means we have a payload.
Expand Down
1 change: 1 addition & 0 deletions dev/AppLifecycle/AppLifecycle.idl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Microsoft.Windows.AppLifecycle
// Windows.ApplicationModel.Activation.ActivationKind.

Push = 5000,
ToastActivation,
};

runtimeclass AppActivationArguments
Expand Down
3 changes: 2 additions & 1 deletion dev/AppLifecycle/ExtensionContract.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ProtocolActivatedEventArgs.h"
#include "FileActivatedEventArgs.h"
#include "StartupActivatedEventArgs.h"
#include "GetRawNotificationEventArgs.h"
#include "GetNotificationEventArgs.h"

namespace winrt::Microsoft::Windows::AppLifecycle::implementation
{
Expand All @@ -26,6 +26,7 @@ namespace winrt::Microsoft::Windows::AppLifecycle::implementation
{ ExtendedActivationKind::Protocol, c_protocolContractId, &ProtocolActivatedEventArgs::Deserialize },
{ ExtendedActivationKind::StartupTask, c_startupTaskContractId, &StartupActivatedEventArgs::Deserialize },
{ ExtendedActivationKind::Push, c_pushContractId, &winrt::Microsoft::Windows::PushNotifications::Deserialize },
{ ExtendedActivationKind::ToastActivation, c_toastContractId, &winrt::Microsoft::Windows::ToastNotifications::Deserialize },
};

inline bool IsEncodedLaunch(winrt::Windows::Foundation::Uri const& uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#pragma once
#include "PushNotificationReceivedEventArgs.h"
#include <winrt/Windows.ApplicationModel.Core.h>
#include "externs.h"

constexpr PCWSTR c_pushContractId = L"Windows.Push";
constexpr PCWSTR c_toastContractId = L"Windows.Toast";

namespace winrt::Microsoft::Windows::PushNotifications
{
Expand All @@ -25,11 +25,14 @@ namespace winrt::Microsoft::Windows::PushNotifications
return winrt::make<winrt::Microsoft::Windows::PushNotifications::implementation::PushNotificationReceivedEventArgs>(payloadAsWstring);
}
}
return GetArgsFromStore();
}
}

const DWORD receiveArgsTimeoutInMSec{ 2000 };
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), !GetWaitHandleForArgs().wait(receiveArgsTimeoutInMSec));

// If COM static store was uninit, let it throw
return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY);
namespace winrt::Microsoft::Windows::ToastNotifications
{
static winrt::Windows::Foundation::IInspectable Deserialize(winrt::Windows::Foundation::Uri const& uri)
{
return GetArgsFromStore();
}
}
2 changes: 1 addition & 1 deletion dev/PushNotifications/PushNotifications.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)externs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)GetRawNotificationEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)GetNotificationEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)PushNotificationActivationInfo.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)PushNotificationBackgroundTask.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)PushNotificationChannel.h" />
Expand Down
10 changes: 10 additions & 0 deletions dev/PushNotifications/externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once
#include "pch.h"
#include <winrt/Windows.ApplicationModel.Core.h>

wil::unique_event& GetWaitHandleForArgs();

Expand All @@ -20,3 +21,12 @@ inline HRESULT GetCurrentProcessPath(wil::unique_cotaskmem_string& processName)
{
return wil::GetModuleFileNameExW(GetCurrentProcess(), nullptr, processName);
};

inline winrt::Windows::Foundation::IInspectable GetArgsFromStore()
{
const DWORD receiveArgsTimeoutInMSec{ 2000 };
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), !GetWaitHandleForArgs().wait(receiveArgsTimeoutInMSec));

// If COM static store was uninit, let it throw
return winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().Lookup(ACTIVATED_EVENT_ARGS_KEY);
}
19 changes: 19 additions & 0 deletions dev/ToastNotifications/ToastActivatedEventArgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "Microsoft.Windows.ToastNotifications.ToastActivatedEventArgs.g.h"

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
struct ToastActivatedEventArgs : ToastActivatedEventArgsT<ToastActivatedEventArgs>
{
ToastActivatedEventArgs() = default;

ToastActivatedEventArgs(winrt::hstring const& arguments, winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::hstring> const& userInput) : m_arguments(arguments), m_userInput(userInput) {};

winrt::hstring ActivationArgs() { return m_arguments; };
winrt::Windows::Foundation::Collections::IMap<hstring, hstring> UserInput() { return m_userInput; };

private:
winrt::hstring m_arguments;
winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::hstring> m_userInput;
};
}
45 changes: 45 additions & 0 deletions dev/ToastNotifications/ToastActivationCallback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "pch.h"
#include <ToastActivationCallback.h>
#include "ToastActivatedEventArgs.h"
#include "externs.h"
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/base.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <iostream>
#include <ToastNotificationUtility.h>

namespace winrt
{
using namespace Microsoft::Windows::ToastNotifications;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
}

HRESULT __stdcall ToastActivationCallback::Activate(
LPCWSTR /* appUserModelId */,
LPCWSTR invokedArgs,
[[maybe_unused]] NOTIFICATION_USER_INPUT_DATA const* data,
[[maybe_unused]] ULONG dataCount) noexcept try
{
winrt::IMap<winrt::hstring, winrt::hstring> userInput{ winrt::single_threaded_map<winrt::hstring, winrt::hstring>() };
for (unsigned long i = 0; i < dataCount; i++)
{
userInput.Insert(data[i].Key, data[i].Value);
}

winrt::ToastActivatedEventArgs activatedEventArgs = winrt::make<winrt::Microsoft::Windows::ToastNotifications::implementation::ToastActivatedEventArgs>(invokedArgs, userInput);
if (GetToastHandleCount() > 0)
{
GetToastHandlers()(*this, activatedEventArgs);
}
else
{
auto appProperties = winrt::CoreApplication::Properties();
appProperties.Insert(ACTIVATED_EVENT_ARGS_KEY, activatedEventArgs);
SetEvent(GetWaitHandleForArgs().get());
}

return S_OK;
}
CATCH_RETURN()
38 changes: 38 additions & 0 deletions dev/ToastNotifications/ToastActivationCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once

#include "NotificationActivationCallback.h"

struct ToastActivationCallback : winrt::implements<ToastActivationCallback, INotificationActivationCallback>
{
HRESULT __stdcall Activate(
LPCWSTR appUserModelId,
LPCWSTR invokedArgs,
[[maybe_unused]] NOTIFICATION_USER_INPUT_DATA const* data,
[[maybe_unused]] ULONG dataCount) noexcept;
};

struct ToastActivationCallbackFactory : winrt::implements<ToastActivationCallbackFactory, IClassFactory>
{
STDMETHODIMP CreateInstance(_In_opt_ IUnknown* aggregateInterface, _In_ REFIID interfaceId, _Outptr_ VOID** object) noexcept final try
{
RETURN_HR_IF(CLASS_E_NOAGGREGATION, aggregateInterface != nullptr);
return winrt::make<ToastActivationCallback>().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;
}
};
36 changes: 36 additions & 0 deletions dev/ToastNotifications/ToastActivationInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "pch.h"
#include "ToastActivationInfo.h"
#include "Microsoft.Windows.ToastNotifications.ToastActivationInfo.g.cpp"

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
winrt::Microsoft::Windows::ToastNotifications::ToastActivationInfo ToastActivationInfo::CreateFromActivationGuid(winrt::guid const& taskClsid)
{
THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications");

THROW_HR_IF(E_INVALIDARG, (taskClsid == winrt::guid(GUID_NULL)));

return winrt::make<ToastActivationInfo>(taskClsid);
}

winrt::Microsoft::Windows::ToastNotifications::ToastActivationInfo ToastActivationInfo::CreateFromToastAssets(winrt::Microsoft::Windows::ToastNotifications::ToastAssets const& assets)
{
THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, AppModel::Identity::IsPackagedProcess(), "Not applicable for packaged applications");

return winrt::make<ToastActivationInfo>(assets);
}

winrt::guid ToastActivationInfo::TaskClsid()
{
THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, !AppModel::Identity::IsPackagedProcess(), "Not applicable for unpackaged applications");

return m_taskClsid;
}

winrt::Microsoft::Windows::ToastNotifications::ToastAssets ToastActivationInfo::Assets()
{
THROW_HR_IF_MSG(E_ILLEGAL_METHOD_CALL, AppModel::Identity::IsPackagedProcess(), "Not applicable for packaged applications");

return m_assets;
}
}
27 changes: 27 additions & 0 deletions dev/ToastNotifications/ToastActivationInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "Microsoft.Windows.ToastNotifications.ToastActivationInfo.g.h"

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
struct ToastActivationInfo : ToastActivationInfoT<ToastActivationInfo>
{
ToastActivationInfo() = default;

ToastActivationInfo(winrt::guid const& taskClsid) : m_taskClsid(taskClsid) {};
ToastActivationInfo(winrt::Microsoft::Windows::ToastNotifications::ToastAssets const& assets) : m_assets(assets) {};
static winrt::Microsoft::Windows::ToastNotifications::ToastActivationInfo CreateFromActivationGuid(winrt::guid const& taskClsid);
static winrt::Microsoft::Windows::ToastNotifications::ToastActivationInfo CreateFromToastAssets(winrt::Microsoft::Windows::ToastNotifications::ToastAssets const& assets);
winrt::guid TaskClsid();
winrt::Microsoft::Windows::ToastNotifications::ToastAssets Assets();

private:
const winrt::guid m_taskClsid{ GUID_NULL };
const winrt::Microsoft::Windows::ToastNotifications::ToastAssets m_assets{ nullptr };
};
}
namespace winrt::Microsoft::Windows::ToastNotifications::factory_implementation
{
struct ToastActivationInfo : ToastActivationInfoT<ToastActivationInfo, implementation::ToastActivationInfo>
{
};
}
15 changes: 15 additions & 0 deletions dev/ToastNotifications/ToastAssets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "pch.h"
#include "ToastAssets.h"
#include "Microsoft.Windows.ToastNotifications.ToastAssets.g.cpp"

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
hstring ToastAssets::DisplayName()
{
return m_displayName;
}
winrt::Windows::Foundation::Uri ToastAssets::IconPath()
{
return m_iconPath;
}
}
24 changes: 24 additions & 0 deletions dev/ToastNotifications/ToastAssets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "Microsoft.Windows.ToastNotifications.ToastAssets.g.h"

namespace winrt::Microsoft::Windows::ToastNotifications::implementation
{
struct ToastAssets : ToastAssetsT<ToastAssets>
{
ToastAssets() = default;

ToastAssets(winrt::hstring const& displayName, winrt::Windows::Foundation::Uri const& iconPath) : m_displayName(displayName), m_iconPath(iconPath) {};
hstring DisplayName();
winrt::Windows::Foundation::Uri IconPath();

private:
const hstring m_displayName;
const winrt::Windows::Foundation::Uri m_iconPath;
};
}
namespace winrt::Microsoft::Windows::ToastNotifications::factory_implementation
{
struct ToastAssets : ToastAssetsT<ToastAssets, implementation::ToastAssets>
{
};
}
Loading