-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BackgroundTaskBuilder Implementation (#4831)
* BackgroundTaskBuilder Implementation --------- Signed-off-by: godlytalias <godlytalias@yahoo.co.in>
- Loading branch information
1 parent
2b52cc9
commit 8e8ed8b
Showing
21 changed files
with
637 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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(); | ||
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 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.