feat(preferences): Add email sync interval setting (#710)

* feat(preferences):  Add email sync interval setting

Introduced a new property `EmailSyncIntervalMinutes` in the `IPreferencesService` interface to allow users to configure the email synchronization interval in minutes. This feature enhances user control over email sync behavior.

• Updated `resources.json` to include translations for the new setting.
• Implemented the logic for the new property in `PreferencesService.cs`, with a default value of 3 minutes.
• Added binding and UI support in `AppPreferencesPageViewModel.cs` and `AppPreferencesPage.xaml` to allow users to modify the sync interval.
• Integrated the new setting into `ServerContext.cs` to dynamically adjust the synchronization timer based on user preferences.

This change improves the user experience by providing customizable email synchronization settings.

* Minimum interval and added an icon.

* Proper SetProperty usage.

* Making sure the minimum sync interval is 1 in the ServerContext.

* Making sure the minimum is applied to first trigger of the sync timer.

---------

Co-authored-by: Burak Kaan Köse <bkaankose@outlook.com>
This commit is contained in:
Maicol Battistini
2025-07-24 09:45:35 +02:00
committed by GitHub
parent 8cd7f68c30
commit c2bb07ff3d
7 changed files with 66 additions and 5 deletions

View File

@@ -47,6 +47,8 @@ public class ServerContext :
IRecipient<OnlineSearchRequested>,
IRecipient<AccountCacheResetMessage>
{
private const double MinimumSynchronizationIntervalMinutes = 1;
private readonly System.Timers.Timer _timer;
private static object connectionLock = new object();
@@ -57,6 +59,7 @@ public class ServerContext :
private readonly ISynchronizerFactory _synchronizerFactory;
private readonly IServerMessageHandlerFactory _serverMessageHandlerFactory;
private readonly IAccountService _accountService;
private readonly IPreferencesService _preferencesService;
private readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions
{
TypeInfoResolver = new ServerRequestTypeInfoResolver()
@@ -66,12 +69,13 @@ public class ServerContext :
IApplicationConfiguration applicationFolderConfiguration,
ISynchronizerFactory synchronizerFactory,
IServerMessageHandlerFactory serverMessageHandlerFactory,
IAccountService accountService)
IAccountService accountService,
IPreferencesService preferencesService)
{
// Setup timer for synchronization.
_preferencesService = preferencesService;
_timer = new System.Timers.Timer(1000 * 60 * 3); // 1 minute
_timer.Elapsed += SynchronizationTimerTriggered;
_preferencesService.PropertyChanged += PreferencesUpdated;
_databaseService = databaseService;
_applicationFolderConfiguration = applicationFolderConfiguration;
@@ -81,6 +85,22 @@ public class ServerContext :
WeakReferenceMessenger.Default.RegisterAll(this);
// Setup timer for synchronization.
RestartSynchronizationTimer();
}
private void PreferencesUpdated(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IPreferencesService.EmailSyncIntervalMinutes))
RestartSynchronizationTimer();
}
private void RestartSynchronizationTimer()
{
_timer.Stop();
// Ensure that the interval is at least 1 minute.
_timer.Interval = 1000 * 60 * Math.Max(MinimumSynchronizationIntervalMinutes, _preferencesService.EmailSyncIntervalMinutes);
_timer.Start();
}