Remove SessionConntectedTask.

This commit is contained in:
Burak Kaan Köse
2024-08-09 01:24:55 +02:00
parent b07ae4bc42
commit 5901344459
6 changed files with 13 additions and 87 deletions

View File

@@ -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();
}
}
}