From 718beb85acf8f10a341fe35db8d8babc1df37aed Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 12 Jul 2024 13:08:57 +0200 Subject: [PATCH] Fixed background update service --- app/MindWork AI Studio/Tools/UpdateService.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/app/MindWork AI Studio/Tools/UpdateService.cs b/app/MindWork AI Studio/Tools/UpdateService.cs index 809009a8..1c8a5f7a 100644 --- a/app/MindWork AI Studio/Tools/UpdateService.cs +++ b/app/MindWork AI Studio/Tools/UpdateService.cs @@ -14,10 +14,11 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver private static ISnackbar? SNACKBAR; private readonly SettingsManager settingsManager; - private readonly TimeSpan updateInterval; private readonly MessageBus messageBus; private readonly Rust rust; + private TimeSpan updateInterval; + public UpdateService(MessageBus messageBus, SettingsManager settingsManager, Rust rust) { this.settingsManager = settingsManager; @@ -26,8 +27,16 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver this.messageBus.RegisterComponent(this); this.ApplyFilters([], [ Event.USER_SEARCH_FOR_UPDATE ]); - - this.updateInterval = settingsManager.ConfigurationData.UpdateBehavior switch + } + + #region Overrides of BackgroundService + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested && !IS_INITIALIZED) + await Task.Delay(TimeSpan.FromSeconds(3), stoppingToken); + + this.updateInterval = this.settingsManager.ConfigurationData.UpdateBehavior switch { UpdateBehavior.NO_CHECK => Timeout.InfiniteTimeSpan, UpdateBehavior.ONCE_STARTUP => Timeout.InfiniteTimeSpan, @@ -38,21 +47,11 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver _ => TimeSpan.FromHours(1) }; - } - - #region Overrides of BackgroundService - - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - while (!stoppingToken.IsCancellationRequested && !IS_INITIALIZED) - { - await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken); - } - - await this.settingsManager.LoadSettings(); - if(this.settingsManager.ConfigurationData.UpdateBehavior != UpdateBehavior.NO_CHECK) - await this.CheckForUpdate(); + if(this.settingsManager.ConfigurationData.UpdateBehavior is UpdateBehavior.NO_CHECK) + return; + + await this.CheckForUpdate(); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(this.updateInterval, stoppingToken);