Skip to content
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

Added TerminalVelocity for BackgroundTaskBuilder API #4908

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ steps:
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
workingDirectory: '$(Build.SourcesDirectory)'

- task: powershell@2
displayName: 'Create BackgroundTask TerminalVelocity features'
inputs:
targetType: filePath
filePath: tools\TerminalVelocity\Generate-TerminalVelocityFeatures.ps1
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
workingDirectory: '$(Build.SourcesDirectory)'

- task: powershell@2
displayName: 'Create AppNotifications TerminalVelocity features'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
#pragma once
#include <winrt/Windows.ApplicationModel.Background.h>
#include "Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder.g.h"
#include <TerminalVelocityFeatures-BackgroundTask.h>

namespace winrt::Microsoft::Windows::ApplicationModel::Background::implementation
{
struct BackgroundTaskBuilder : BackgroundTaskBuilderT<BackgroundTaskBuilder>
{
BackgroundTaskBuilder() = default;
BackgroundTaskBuilder()
{
THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::ApplicationModel::Background::Feature_BackgroundTask::IsEnabled());
}

void SetTaskEntryPointClsid(winrt::guid clsId);

void SetTrigger(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
#include <TerminalVelocityFeatures-BackgroundTask.h>

namespace Microsoft.Windows.ApplicationModel.Background
{
[contractversion(1)]
apicontract BackgroundTaskContract{};

[contract(BackgroundTaskContract, 1)]
[feature(Feature_BackgroundTask)]
runtimeclass BackgroundTaskBuilder
{
BackgroundTaskBuilder();
Expand Down
32 changes: 32 additions & 0 deletions dev/Common/TerminalVelocityFeatures-BackgroundTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT IT

// INPUT FILE: dev\common\TerminalVelocityFeatures-BackgroundTask.xml
// OPTIONS: -Channel Experimental -Language C++ -Namespace Microsoft.Windows.ApplicationModel.Background -Path dev\common\TerminalVelocityFeatures-BackgroundTask.xml -Output dev\common\TerminalVelocityFeatures-BackgroundTask.h

#if defined(__midlrt)
namespace features
{
feature_name Feature_BackgroundTask = { DisabledByDefault, FALSE };
}
#endif // defined(__midlrt)

// Feature constants
#define WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED 1

#if defined(__cplusplus)

namespace Microsoft::Windows::ApplicationModel::Background
{

__pragma(detect_mismatch("ODR_violation_WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED_mismatch", "AlwaysEnabled"))
struct Feature_BackgroundTask
{
static constexpr bool IsEnabled() { return WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_APPLICATIONMODEL_BACKGROUND_FEATURE_BACKGROUNDTASK_ENABLED == 1; }
};

} // namespace Microsoft.Windows.ApplicationModel.Background

#endif // defined(__cplusplus)
20 changes: 20 additions & 0 deletions dev/Common/TerminalVelocityFeatures-BackgroundTask.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<features xmlns="http://microsoft.com/windowsappsdk/TerminalVelocity/20210729/TerminalVelocityFeatures.xsd">

<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See LICENSE in the project root for license information.
-->

<!-- See docs/TerminalVelocity.md for more info. -->

<!-- Enabled variants -->
<feature>
<name>Feature_BackgroundTask</name>
<description>Supports BackgroundTask executions for WinAppSDK apps</description>
<state>AlwaysEnabled</state>
<alwaysDisabledChannelTokens>
<channelToken>Preview</channelToken>
<channelToken>Stable</channelToken>
</alwaysDisabledChannelTokens>
</feature>
</features>
11 changes: 10 additions & 1 deletion specs/BackgroundTask/BackgroundTaskBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This API takes care of avoiding this workaround so that WinAppSDK applications c

## Register Background Task (c++)

Registering a Background Task for full trust COM component. Developers may also need to set the **WindowsAppSDKBackgroundTask** property as true in their project configuration.
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**

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

Package Manifest:
```
<Extension Category="windows.backgroundTasks" EntryPoint="Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task">
<BackgroundTasks>
<Task Type="general"/>
</BackgroundTasks>
</Extension>
```

# API Pages

## BackgroundTaskBuilder class
Expand Down