Bunch of improvements i dunno.
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
@@ -13,12 +14,14 @@ using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Core.Synchronizers;
|
||||
|
||||
public abstract class BaseSynchronizer<TBaseRequest> : IBaseSynchronizer
|
||||
public abstract partial class BaseSynchronizer<TBaseRequest> : ObservableObject, IBaseSynchronizer
|
||||
{
|
||||
protected SemaphoreSlim synchronizationSemaphore = new(1);
|
||||
protected CancellationToken activeSynchronizationCancellationToken;
|
||||
|
||||
protected List<IRequestBase> changeRequestQueue = [];
|
||||
protected readonly IMessenger Messenger;
|
||||
|
||||
public MailAccount Account { get; }
|
||||
|
||||
private AccountSynchronizerState state;
|
||||
@@ -29,13 +32,87 @@ public abstract class BaseSynchronizer<TBaseRequest> : IBaseSynchronizer
|
||||
{
|
||||
state = value;
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new AccountSynchronizerStateChanged(Account.Id, value));
|
||||
// Send state changed message with current progress information
|
||||
Messenger.Send(new AccountSynchronizerStateChanged(
|
||||
Account.Id,
|
||||
value,
|
||||
TotalItemsToSync,
|
||||
RemainingItemsToSync,
|
||||
SynchronizationStatus));
|
||||
}
|
||||
}
|
||||
|
||||
protected BaseSynchronizer(MailAccount account)
|
||||
/// <summary>
|
||||
/// Current synchronization status message.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public partial string SynchronizationStatus { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Total items to download/sync in current operation.
|
||||
/// 0 means no active download or indeterminate progress.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public partial int TotalItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining items to download/sync in current operation.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public partial int RemainingItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculated progress percentage (0-100) based on TotalItemsToSync and RemainingItemsToSync.
|
||||
/// Returns -1 for indeterminate progress (when both are 0).
|
||||
/// </summary>
|
||||
public double SynchronizationProgress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TotalItemsToSync == 0 || RemainingItemsToSync == 0)
|
||||
return -1; // Indeterminate
|
||||
|
||||
return ((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
protected BaseSynchronizer(MailAccount account, IMessenger messenger)
|
||||
{
|
||||
Account = account;
|
||||
Messenger = messenger ?? WeakReferenceMessenger.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets synchronization progress to default state.
|
||||
/// </summary>
|
||||
protected void ResetSyncProgress()
|
||||
{
|
||||
TotalItemsToSync = 0;
|
||||
RemainingItemsToSync = 0;
|
||||
SynchronizationStatus = string.Empty;
|
||||
OnPropertyChanged(nameof(SynchronizationProgress));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates synchronization progress with current item counts.
|
||||
/// </summary>
|
||||
/// <param name="total">Total items to sync</param>
|
||||
/// <param name="remaining">Remaining items to sync</param>
|
||||
/// <param name="status">Optional status message</param>
|
||||
protected void UpdateSyncProgress(int total, int remaining, string status = "")
|
||||
{
|
||||
TotalItemsToSync = total;
|
||||
RemainingItemsToSync = remaining;
|
||||
SynchronizationStatus = status;
|
||||
OnPropertyChanged(nameof(SynchronizationProgress));
|
||||
|
||||
// Send progress update message
|
||||
Messenger.Send(new AccountSynchronizerStateChanged(
|
||||
Account.Id,
|
||||
State,
|
||||
TotalItemsToSync,
|
||||
RemainingItemsToSync,
|
||||
SynchronizationStatus));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user