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>
|
||||
<Compile Include="AppUpdatedTask.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SessionConnectedTask.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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
|
||||
{
|
||||
/// <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>
|
||||
/// Unregisters all existing background tasks. Useful for migrations.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using Serilog;
|
||||
using Windows.ApplicationModel.Background;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
@@ -8,12 +6,7 @@ namespace Wino.Core.UWP.Services
|
||||
{
|
||||
public class BackgroundTaskService : IBackgroundTaskService
|
||||
{
|
||||
private const string Is180BackgroundTasksRegisteredKey = nameof(Is180BackgroundTasksRegisteredKey);
|
||||
|
||||
public const string ToastActivationTaskEx = nameof(ToastActivationTaskEx);
|
||||
|
||||
private const string SessionConnectedTaskEntryPoint = "Wino.BackgroundTasks.SessionConnectedTask";
|
||||
private const string SessionConnectedTaskName = "SessionConnectedTask";
|
||||
private const string IsBackgroundTasksUnregisteredKey = nameof(IsBackgroundTasksUnregisteredKey);
|
||||
|
||||
private readonly IConfigurationService _configurationService;
|
||||
|
||||
@@ -22,48 +15,17 @@ namespace Wino.Core.UWP.Services
|
||||
_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()
|
||||
{
|
||||
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 ForceAllAccountSynchronizationsAsync();
|
||||
await ConfigureBackgroundTasksAsync();
|
||||
ConfigureBackgroundTasks();
|
||||
}
|
||||
|
||||
private async Task ConfigureBackgroundTasksAsync()
|
||||
private void ConfigureBackgroundTasks()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _backgroundTaskService.HandleBackgroundTaskRegistrations();
|
||||
_backgroundTaskService.UnregisterAllBackgroundTask();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -55,13 +55,6 @@
|
||||
<!-- App updated task. Notifies about new version after each Store update. -->
|
||||
<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 -->
|
||||
<uap:Extension Category="windows.protocol">
|
||||
<uap:Protocol Name="mailto" />
|
||||
|
||||
Reference in New Issue
Block a user