-
Notifications
You must be signed in to change notification settings - Fork 436
BackgroundTaskBuilder Implementation #4831
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
074376a
BackgroundTaskBuilder Implementation
godlytalias 429f992
Added C# Projection
godlytalias 9bf621b
Added AddCondition method
godlytalias 42d5eff
Updated as per review feedbacks
godlytalias 55ec233
Merge branch 'main' into user/godlyalias/bgtaskImpl
godlytalias 5b9ff1e
Removing unwanted characters
godlytalias 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
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
58 changes: 58 additions & 0 deletions
58
dev/BackgroundTask/BackgroundTaskBuilder/BackgroundTaskBuilder.cpp
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,58 @@ | ||
| // Copyright (c) Microsoft Corporation and Contributors. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "pch.h" | ||
| #include "BackgroundTaskBuilder.h" | ||
| #include "Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder.g.cpp" | ||
| #include <winrt/Windows.ApplicationModel.Activation.h> | ||
|
|
||
| namespace winrt | ||
| { | ||
| using namespace winrt::Windows::ApplicationModel::Background; | ||
| using namespace Windows::Storage; | ||
| } | ||
|
|
||
| namespace winrt::Microsoft::Windows::ApplicationModel::Background::implementation | ||
| { | ||
| void BackgroundTaskBuilder::SetTaskEntryPointClsid(winrt::guid clsId) | ||
| { | ||
| m_taskEntryPointClsid = clsId; | ||
| } | ||
|
|
||
| void BackgroundTaskBuilder::Name(winrt::hstring name) | ||
| { | ||
| m_name = name; | ||
| } | ||
|
|
||
| void BackgroundTaskBuilder::SetTrigger(winrt::IBackgroundTrigger trigger) | ||
| { | ||
| m_builder.SetTrigger(trigger); | ||
| } | ||
|
|
||
| void BackgroundTaskBuilder::AddCondition(winrt::IBackgroundCondition condition) | ||
| { | ||
| m_builder.AddCondition(condition); | ||
| } | ||
|
|
||
| winrt::BackgroundTaskRegistration BackgroundTaskBuilder::Register() | ||
| { | ||
| m_builder.Name(m_name); | ||
| m_builder.TaskEntryPoint(L"Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.Task"); | ||
| winrt::BackgroundTaskRegistration taskRegistration = m_builder.Register(); | ||
|
|
||
| winrt::ApplicationDataContainer localSettings = winrt::ApplicationData::Current().LocalSettings(); | ||
|
godlytalias marked this conversation as resolved.
|
||
| auto values = localSettings.Values(); | ||
| winrt::hstring lookupId = winrt::to_hstring(taskRegistration.TaskId()); | ||
| IInspectable obj = winrt::box_value(m_taskEntryPointClsid); | ||
| values.Insert(lookupId, obj); | ||
|
|
||
| return taskRegistration; | ||
| } | ||
|
|
||
| winrt::BackgroundTaskRegistration BackgroundTaskBuilder::Register(winrt::hstring taskName) | ||
| { | ||
| Name(taskName); | ||
| return Register(); | ||
| } | ||
|
|
||
| } | ||
42 changes: 42 additions & 0 deletions
42
dev/BackgroundTask/BackgroundTaskBuilder/BackgroundTaskBuilder.h
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,42 @@ | ||
| // Copyright (c) Microsoft Corporation and Contributors. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #pragma once | ||
| #include <winrt/Windows.ApplicationModel.Background.h> | ||
| #include "Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder.g.h" | ||
|
|
||
| namespace winrt::Microsoft::Windows::ApplicationModel::Background::implementation | ||
| { | ||
| struct BackgroundTaskBuilder : BackgroundTaskBuilderT<BackgroundTaskBuilder> | ||
| { | ||
| BackgroundTaskBuilder() = default; | ||
| void SetTaskEntryPointClsid(winrt::guid clsId); | ||
|
|
||
| void SetTrigger( | ||
| winrt::Windows::ApplicationModel::Background::IBackgroundTrigger trigger | ||
| ); | ||
|
|
||
| void AddCondition( | ||
| winrt::Windows::ApplicationModel::Background::IBackgroundCondition trigger | ||
| ); | ||
|
|
||
|
|
||
| void Name(winrt::hstring Name); | ||
| winrt::hstring Name() { return m_name; } | ||
|
|
||
| winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration Register(); | ||
| winrt::Windows::ApplicationModel::Background::BackgroundTaskRegistration Register(winrt::hstring taskName); | ||
|
|
||
| private: | ||
| winrt::guid m_taskEntryPointClsid; | ||
| winrt::Windows::ApplicationModel::Background::BackgroundTaskBuilder m_builder; | ||
| winrt::hstring m_name; | ||
| }; | ||
| } | ||
|
|
||
| namespace winrt::Microsoft::Windows::ApplicationModel::Background::factory_implementation | ||
| { | ||
| struct BackgroundTaskBuilder : BackgroundTaskBuilderT<BackgroundTaskBuilder, implementation::BackgroundTaskBuilder> | ||
| { | ||
| }; | ||
| } |
Oops, something went wrong.
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.