2024-08-09 01:24:55 +02:00
|
|
|
|
using Serilog;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Windows.ApplicationModel.Background;
|
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Wino.Core.UWP.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BackgroundTaskService : IBackgroundTaskService
|
|
|
|
|
|
{
|
2024-08-09 01:24:55 +02:00
|
|
|
|
private const string IsBackgroundTasksUnregisteredKey = nameof(IsBackgroundTasksUnregisteredKey);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
private readonly IConfigurationService _configurationService;
|
|
|
|
|
|
|
|
|
|
|
|
public BackgroundTaskService(IConfigurationService configurationService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_configurationService = configurationService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UnregisterAllBackgroundTask()
|
|
|
|
|
|
{
|
2024-08-09 02:02:11 +02:00
|
|
|
|
if (!_configurationService.Get(IsBackgroundTasksUnregisteredKey, false))
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-08-09 01:24:55 +02:00
|
|
|
|
foreach (var task in BackgroundTaskRegistration.AllTasks)
|
|
|
|
|
|
{
|
|
|
|
|
|
task.Value.Unregister(true);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-08-09 01:24:55 +02:00
|
|
|
|
Log.Information("Unregistered all background tasks.");
|
2024-08-09 02:02:11 +02:00
|
|
|
|
_configurationService.Set(IsBackgroundTasksUnregisteredKey, true);
|
2024-08-09 01:24:55 +02:00
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|