Remove SessionConntectedTask.
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Windows.ApplicationModel;
|
|
||||||
using Windows.ApplicationModel.Background;
|
|
||||||
|
|
||||||
namespace Wino.BackgroundTasks
|
|
||||||
{
|
|
||||||
public sealed class SessionConnectedTask : IBackgroundTask
|
|
||||||
{
|
|
||||||
public async void Run(IBackgroundTaskInstance taskInstance)
|
|
||||||
{
|
|
||||||
var def = taskInstance.GetDeferral();
|
|
||||||
|
|
||||||
// Run server on session connected by launching the Full Thrust process.
|
|
||||||
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
|
|
||||||
|
|
||||||
def.Complete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -104,7 +104,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AppUpdatedTask.cs" />
|
<Compile Include="AppUpdatedTask.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SessionConnectedTask.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
using System.Threading.Tasks;
|
namespace Wino.Core.Domain.Interfaces
|
||||||
|
|
||||||
namespace Wino.Core.Domain.Interfaces
|
|
||||||
{
|
{
|
||||||
public interface IBackgroundTaskService
|
public interface IBackgroundTaskService
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Manages background task registrations, requests access if needed, checks the statusses of them etc.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="BackgroundTaskExecutionRequestDeniedException">If the access request is denied for some reason.</exception>
|
|
||||||
/// <exception cref="BackgroundTaskRegistrationFailedException">If one of the requires background tasks are failed during registration.</exception>
|
|
||||||
Task HandleBackgroundTaskRegistrations();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unregisters all existing background tasks. Useful for migrations.
|
/// Unregisters all existing background tasks. Useful for migrations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using Serilog;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Serilog;
|
|
||||||
using Windows.ApplicationModel.Background;
|
using Windows.ApplicationModel.Background;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
|
|
||||||
@@ -8,12 +6,7 @@ namespace Wino.Core.UWP.Services
|
|||||||
{
|
{
|
||||||
public class BackgroundTaskService : IBackgroundTaskService
|
public class BackgroundTaskService : IBackgroundTaskService
|
||||||
{
|
{
|
||||||
private const string Is180BackgroundTasksRegisteredKey = nameof(Is180BackgroundTasksRegisteredKey);
|
private const string IsBackgroundTasksUnregisteredKey = nameof(IsBackgroundTasksUnregisteredKey);
|
||||||
|
|
||||||
public const string ToastActivationTaskEx = nameof(ToastActivationTaskEx);
|
|
||||||
|
|
||||||
private const string SessionConnectedTaskEntryPoint = "Wino.BackgroundTasks.SessionConnectedTask";
|
|
||||||
private const string SessionConnectedTaskName = "SessionConnectedTask";
|
|
||||||
|
|
||||||
private readonly IConfigurationService _configurationService;
|
private readonly IConfigurationService _configurationService;
|
||||||
|
|
||||||
@@ -22,48 +15,17 @@ namespace Wino.Core.UWP.Services
|
|||||||
_configurationService = configurationService;
|
_configurationService = configurationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleBackgroundTaskRegistrations()
|
|
||||||
{
|
|
||||||
bool is180BackgroundTaskRegistered = _configurationService.Get<bool>(Is180BackgroundTasksRegisteredKey);
|
|
||||||
|
|
||||||
// Don't re-register tasks.
|
|
||||||
if (is180BackgroundTaskRegistered) return;
|
|
||||||
|
|
||||||
var response = await BackgroundExecutionManager.RequestAccessAsync();
|
|
||||||
|
|
||||||
if (response != BackgroundAccessStatus.DeniedBySystemPolicy ||
|
|
||||||
response != BackgroundAccessStatus.DeniedByUser)
|
|
||||||
{
|
|
||||||
// Unregister all tasks and register new ones.
|
|
||||||
|
|
||||||
UnregisterAllBackgroundTask();
|
|
||||||
RegisterSessionConnectedTask();
|
|
||||||
|
|
||||||
_configurationService.Set(Is180BackgroundTasksRegisteredKey, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnregisterAllBackgroundTask()
|
public void UnregisterAllBackgroundTask()
|
||||||
{
|
{
|
||||||
foreach (var task in BackgroundTaskRegistration.AllTasks)
|
if (_configurationService.Get<bool>(IsBackgroundTasksUnregisteredKey, false))
|
||||||
{
|
{
|
||||||
task.Value.Unregister(true);
|
foreach (var task in BackgroundTaskRegistration.AllTasks)
|
||||||
|
{
|
||||||
|
task.Value.Unregister(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Information("Unregistered all background tasks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Information("Unregistered all background tasks.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private BackgroundTaskRegistration RegisterSessionConnectedTask()
|
|
||||||
{
|
|
||||||
var builder = new BackgroundTaskBuilder
|
|
||||||
{
|
|
||||||
Name = SessionConnectedTaskName,
|
|
||||||
TaskEntryPoint = SessionConnectedTaskEntryPoint
|
|
||||||
};
|
|
||||||
|
|
||||||
builder.SetTrigger(new SystemTrigger(SystemTriggerType.SessionConnected, false));
|
|
||||||
|
|
||||||
return builder.Register();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,14 +236,14 @@ namespace Wino.Mail.ViewModels
|
|||||||
await ProcessLaunchOptionsAsync();
|
await ProcessLaunchOptionsAsync();
|
||||||
|
|
||||||
await ForceAllAccountSynchronizationsAsync();
|
await ForceAllAccountSynchronizationsAsync();
|
||||||
await ConfigureBackgroundTasksAsync();
|
ConfigureBackgroundTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConfigureBackgroundTasksAsync()
|
private void ConfigureBackgroundTasks()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _backgroundTaskService.HandleBackgroundTaskRegistrations();
|
_backgroundTaskService.UnregisterAllBackgroundTask();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,13 +55,6 @@
|
|||||||
<!-- App updated task. Notifies about new version after each Store update. -->
|
<!-- App updated task. Notifies about new version after each Store update. -->
|
||||||
<Extension Category="windows.updateTask" EntryPoint="Wino.BackgroundTasks.AppUpdatedTask" />
|
<Extension Category="windows.updateTask" EntryPoint="Wino.BackgroundTasks.AppUpdatedTask" />
|
||||||
|
|
||||||
<!-- SessionConnected task for background synchronization on startup. -->
|
|
||||||
<Extension Category="windows.backgroundTasks" EntryPoint="Wino.BackgroundTasks.SessionConnectedTask">
|
|
||||||
<BackgroundTasks>
|
|
||||||
<Task Type="systemEvent" />
|
|
||||||
</BackgroundTasks>
|
|
||||||
</Extension>
|
|
||||||
|
|
||||||
<!-- Protocol activation: mailto -->
|
<!-- Protocol activation: mailto -->
|
||||||
<uap:Extension Category="windows.protocol">
|
<uap:Extension Category="windows.protocol">
|
||||||
<uap:Protocol Name="mailto" />
|
<uap:Protocol Name="mailto" />
|
||||||
|
|||||||
Reference in New Issue
Block a user