Skip to content

Commit e4227ec

Browse files
authored
Added TerminalVelocity for BackgroundTaskBuilder API (#4908)
Signed-off-by: Godly Alias <[email protected]>
1 parent 999df08 commit e4227ec

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

build/AzurePipelinesTemplates/WindowsAppSDK-SetupBuildEnvironment-Steps.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ steps:
131131
arguments: -Path $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-ApplicationData.xml -Channel $(channel) -Language C++ -Namespace Microsoft.Windows.Storage.ApplicationData -Output $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-ApplicationData.h
132132
workingDirectory: '$(Build.SourcesDirectory)'
133133
134+
- task: powershell@2
135+
displayName: 'Create BackgroundTask TerminalVelocity features'
136+
inputs:
137+
targetType: filePath
138+
filePath: tools\TerminalVelocity\Generate-TerminalVelocityFeatures.ps1
139+
arguments: -Path $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-BackgroundTask.xml -Channel $(channel) -Language C++ -Namespace Microsoft.Windows.ApplicationModel.Background -Output $(Build.SourcesDirectory)\dev\common\TerminalVelocityFeatures-BackgroundTask.h
140+
workingDirectory: '$(Build.SourcesDirectory)'
141+
134142
- task: powershell@2
135143
displayName: 'Create AppNotifications TerminalVelocity features'
136144
inputs:

dev/BackgroundTask/BackgroundTaskBuilder/BackgroundTaskBuilder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
#pragma once
55
#include <winrt/Windows.ApplicationModel.Background.h>
66
#include "Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder.g.h"
7+
#include <TerminalVelocityFeatures-BackgroundTask.h>
78

89
namespace winrt::Microsoft::Windows::ApplicationModel::Background::implementation
910
{
1011
struct BackgroundTaskBuilder : BackgroundTaskBuilderT<BackgroundTaskBuilder>
1112
{
12-
BackgroundTaskBuilder() = default;
13+
BackgroundTaskBuilder()
14+
{
15+
THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::ApplicationModel::Background::Feature_BackgroundTask::IsEnabled());
16+
}
17+
1318
void SetTaskEntryPointClsid(winrt::guid clsId);
1419

1520
void SetTrigger(

dev/BackgroundTask/BackgroundTaskBuilder/BackgroundTaskBuilder.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) Microsoft Corporation and Contributors.
22
// Licensed under the MIT License.
3+
#include <TerminalVelocityFeatures-BackgroundTask.h>
34

45
namespace Microsoft.Windows.ApplicationModel.Background
56
{
67
[contractversion(1)]
78
apicontract BackgroundTaskContract{};
89

910
[contract(BackgroundTaskContract, 1)]
11+
[feature(Feature_BackgroundTask)]
1012
runtimeclass BackgroundTaskBuilder
1113
{
1214
BackgroundTaskBuilder();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation and Contributors.
2+
// Licensed under the MIT License.
3+
4+
// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT IT
5+
6+
// INPUT FILE: dev\common\TerminalVelocityFeatures-BackgroundTask.xml
7+
// OPTIONS: -Channel Experimental -Language C++ -Namespace Microsoft.Windows.ApplicationModel.Background -Path dev\common\TerminalVelocityFeatures-BackgroundTask.xml -Output dev\common\TerminalVelocityFeatures-BackgroundTask.h
8+
9+
#if defined(__midlrt)
10+
namespace features
11+
{
12+
feature_name Feature_BackgroundTask = { DisabledByDefault, FALSE };
13+
}
14+
#endif // defined(__midlrt)
15+
16+
// Feature constants
17+
#define WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED 1
18+
19+
#if defined(__cplusplus)
20+
21+
namespace Microsoft::Windows::ApplicationModel::Background
22+
{
23+
24+
__pragma(detect_mismatch("ODR_violation_WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED_mismatch", "AlwaysEnabled"))
25+
struct Feature_BackgroundTask
26+
{
27+
static constexpr bool IsEnabled() { return WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED == 1; }
28+
};
29+
30+
} // namespace Microsoft.Windows.ApplicationModel.Background
31+
32+
#endif // defined(__cplusplus)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<features xmlns="http://microsoft.com/windowsappsdk/TerminalVelocity/20210729/TerminalVelocityFeatures.xsd">
3+
4+
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
5+
Licensed under the MIT License. See LICENSE in the project root for license information.
6+
-->
7+
8+
<!-- See docs/TerminalVelocity.md for more info. -->
9+
10+
<!-- Enabled variants -->
11+
<feature>
12+
<name>Feature_BackgroundTask</name>
13+
<description>Supports BackgroundTask executions for WinAppSDK apps</description>
14+
<state>AlwaysEnabled</state>
15+
<alwaysDisabledChannelTokens>
16+
<channelToken>Preview</channelToken>
17+
<channelToken>Stable</channelToken>
18+
</alwaysDisabledChannelTokens>
19+
</feature>
20+
</features>

specs/BackgroundTask/BackgroundTaskBuilder.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This API takes care of avoiding this workaround so that WinAppSDK applications c
1515

1616
## Register Background Task (c++)
1717

18-
Registering a Background Task for full trust COM component. Developers may also need to set the **WindowsAppSDKBackgroundTask** property as true in their project configuration.
18+
Registering a Background Task for full trust COM component. Developers may also need to set the **WindowsAppSDKBackgroundTask** property as *true* in the project configuration. Also in the manifest file *EntryPoint* for BackgroundTask is to be set as **Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task**
1919

2020
```c++
2121
//Using WinAppSDK API for BackgroundTaskBuilder
@@ -28,6 +28,15 @@ This API takes care of avoiding this workaround so that WinAppSDK applications c
2828
builder.Register();
2929
```
3030

31+
Package Manifest:
32+
```
33+
<Extension Category="windows.backgroundTasks" EntryPoint="Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task">
34+
<BackgroundTasks>
35+
<Task Type="general"/>
36+
</BackgroundTasks>
37+
</Extension>
38+
```
39+
3140
# API Pages
3241

3342
## BackgroundTaskBuilder class

0 commit comments

Comments
 (0)