-
Notifications
You must be signed in to change notification settings - Fork 436
Support foregroundtask registration for packaged applications #1521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sharath2727
merged 11 commits into
WNP_LRP
from
user/vemancha/foregroundtaskforpackagedapplications
Oct 5, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0debeb8
Support foregroundtask registration for packaged applications
sharath2727 ec54a79
Address comments
sharath2727 c951092
Address comments2
sharath2727 484fcaa
Introduce PushNotificationsUtility.h/cpp
sharath2727 45cdd39
Address comments
sharath2727 537af31
Mark PushNotificationUtility.h file to be shared across the PushNotif…
sharath2727 6a3aa4d
Add try/catch around onRawNotificationRecveived
sharath2727 d2f6f38
Set foregroundhandled to true by default
sharath2727 3b09702
Address comments for getappusermodelId API
sharath2727 35b9948
Address nits
sharath2727 a3d70bc
Adress one more nit
sharath2727 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
| #include "pch.h" | ||
| #include "externs.h" | ||
| #include "PushNotificationUtility.h" | ||
|
|
||
| wil::unique_cotaskmem_string GetAppUserModelId() | ||
| { | ||
| wchar_t appId[APPLICATION_USER_MODEL_ID_MAX_LENGTH] = {}; | ||
| UINT32 appIdSize{ ARRAYSIZE(appId) }; | ||
|
|
||
| THROW_IF_FAILED(::GetCurrentApplicationUserModelId(&appIdSize, appId)); | ||
|
|
||
| return wil::make_unique_string<wil::unique_cotaskmem_string>(appId); | ||
| } | ||
|
|
||
| std::wstring Utf8BytesToWideString(unsigned int payloadLength, _In_reads_(payloadLength) byte* payload) | ||
| { | ||
| int size = MultiByteToWideChar( | ||
| CP_UTF8, | ||
| 0, | ||
| reinterpret_cast<PCSTR>(payload), | ||
| payloadLength, | ||
| nullptr, | ||
| 0); | ||
| THROW_LAST_ERROR_IF(size == 0); | ||
|
|
||
| std::wstring payloadAsWideString(size, 0); | ||
| size = MultiByteToWideChar( | ||
| CP_UTF8, | ||
| 0, | ||
| reinterpret_cast<PCSTR>(payload), | ||
| payloadLength, | ||
| &payloadAsWideString[0], | ||
| size); | ||
| THROW_LAST_ERROR_IF(size == 0); | ||
|
|
||
| return payloadAsWideString; | ||
| } | ||
|
|
||
| void ProtocolLaunchHelper(unsigned int payloadLength, _In_reads_(payloadLength) byte* payload) | ||
| { | ||
| // Command line format: ----WindowsAppRuntimePushServer:-Payload:"<payloadAsEscapedUriFormat>" | ||
| std::wstring commandLine = L"----WindowsAppRuntimePushServer:-Payload:\""; | ||
|
|
||
| // Escape special characters to follow command line standards for any app activation type in AppLifecycle | ||
| // (See AppInstance.cpp and Serialize() from other activation types) | ||
| std::wstring payloadAsWideString = Utf8BytesToWideString(payloadLength, payload); | ||
| auto payloadAsEscapedUriFormat = winrt::Windows::Foundation::Uri::EscapeComponent(payloadAsWideString.c_str()); | ||
|
|
||
| commandLine.append(payloadAsEscapedUriFormat); | ||
| commandLine.append(L"\""); | ||
|
|
||
| wil::unique_cotaskmem_string processName; | ||
| THROW_IF_FAILED(GetCurrentProcessPath(processName)); | ||
|
|
||
| SHELLEXECUTEINFO shellExecuteInfo{}; | ||
| shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO); | ||
| shellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_DOENVSUBST; | ||
| shellExecuteInfo.lpFile = processName.get(); | ||
| shellExecuteInfo.lpParameters = commandLine.c_str(); | ||
|
|
||
| shellExecuteInfo.nShow = SW_NORMAL; | ||
|
|
||
| if (!ShellExecuteEx(&shellExecuteInfo)) | ||
| { | ||
| THROW_IF_WIN32_ERROR(GetLastError()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
|
||
| #pragma once | ||
| #include "pch.h" | ||
|
|
||
| const std::wstring ConvertByteArrayToWideString(unsigned int payloadLength, _In_reads_(payloadLength) byte* payload); | ||
| void ProtocolLaunchHelper(unsigned int payloadLength, _In_reads_(payloadLength) byte* payload); | ||
| wil::unique_cotaskmem_string GetAppUserModelId(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.