Updated synchronization progress implementation.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace Wino.Core.Domain.Enums;
|
||||
|
||||
public enum SynchronizationProgressCategory
|
||||
{
|
||||
Mail,
|
||||
Calendar
|
||||
}
|
||||
@@ -1,35 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
|
||||
namespace Wino.Core.Domain.Interfaces;
|
||||
|
||||
public interface IAccountMenuItem : IMenuItem
|
||||
{
|
||||
bool IsEnabled { get; set; }
|
||||
|
||||
bool IsSynchronizationInProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculated synchronization progress percentage (0-100). -1 for indeterminate.
|
||||
/// Calculated synchronization progress percentage (0-100).
|
||||
/// </summary>
|
||||
double SynchronizationProgress { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Progress value clamped for XAML progress controls.
|
||||
/// </summary>
|
||||
double SynchronizationProgressValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Total items to sync. 0 for indeterminate progress.
|
||||
/// </summary>
|
||||
int TotalItemsToSync { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remaining items to sync.
|
||||
/// </summary>
|
||||
int RemainingItemsToSync { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Current synchronization status message.
|
||||
/// </summary>
|
||||
string SynchronizationStatus { get; set; }
|
||||
|
||||
|
||||
int UnreadItemCount { get; set; }
|
||||
IEnumerable<MailAccount> HoldingAccounts { get; }
|
||||
void ApplySynchronizationProgress(AccountSynchronizationProgress progress);
|
||||
void UpdateAccount(MailAccount account);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,11 @@ public interface ISynchronizationManager
|
||||
/// </summary>
|
||||
bool IsAccountSynchronizing(Guid accountId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the latest centralized synchronization progress snapshot for the given account and category.
|
||||
/// </summary>
|
||||
AccountSynchronizationProgress GetSynchronizationProgress(Guid accountId, SynchronizationProgressCategory category);
|
||||
|
||||
/// <summary>
|
||||
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -6,6 +6,7 @@ using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
|
||||
namespace Wino.Core.Domain.MenuItems;
|
||||
|
||||
@@ -14,18 +15,22 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
[ObservableProperty]
|
||||
private int unreadItemCount;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate), nameof(SynchronizationProgress), nameof(SynchronizationProgressValue))]
|
||||
public partial bool IsSynchronizationInProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total items to sync. 0 means indeterminate progress.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsSynchronizationProgressVisible), nameof(SynchronizationProgress), nameof(IsProgressIndeterminate))]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
||||
public partial int TotalItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining items to sync.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress))]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
||||
public partial int RemainingItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -39,31 +44,22 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
|
||||
public bool IsAttentionRequired => AttentionReason != AccountAttentionReason.None;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates synchronization progress percentage (0-100).
|
||||
/// Returns -1 for indeterminate progress when TotalItemsToSync is 0.
|
||||
/// </summary>
|
||||
public double SynchronizationProgress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TotalItemsToSync == 0 || RemainingItemsToSync == 0)
|
||||
return -1; // Indeterminate
|
||||
if (TotalItemsToSync <= 0)
|
||||
return 0;
|
||||
|
||||
return ((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100;
|
||||
return Math.Clamp(((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100, 0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether synchronization progress should be visible.
|
||||
/// Visible when there's active synchronization (TotalItemsToSync > 0 or RemainingItemsToSync > 0).
|
||||
/// </summary>
|
||||
public bool IsSynchronizationProgressVisible => TotalItemsToSync > 0 || RemainingItemsToSync > 0;
|
||||
public double SynchronizationProgressValue => SynchronizationProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Whether progress should be indeterminate (when total is 0 but there's still synchronization happening).
|
||||
/// </summary>
|
||||
public bool IsProgressIndeterminate => TotalItemsToSync == 0 && RemainingItemsToSync == 0 && IsSynchronizationProgressVisible;
|
||||
public bool IsSynchronizationProgressVisible => IsSynchronizationInProgress;
|
||||
|
||||
public bool IsProgressIndeterminate => IsSynchronizationInProgress && TotalItemsToSync <= 0;
|
||||
|
||||
public Guid AccountId => Parameter.Id;
|
||||
|
||||
@@ -77,7 +73,6 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
if (SetProperty(ref attentionReason, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(IsAttentionRequired));
|
||||
|
||||
UpdateFixAccountIssueMenuItem();
|
||||
}
|
||||
}
|
||||
@@ -108,6 +103,17 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
UpdateAccount(account);
|
||||
}
|
||||
|
||||
public void ApplySynchronizationProgress(AccountSynchronizationProgress progress)
|
||||
{
|
||||
if (progress == null || progress.AccountId != AccountId)
|
||||
return;
|
||||
|
||||
IsSynchronizationInProgress = progress.IsInProgress;
|
||||
TotalItemsToSync = progress.TotalUnits;
|
||||
RemainingItemsToSync = progress.RemainingUnits;
|
||||
SynchronizationStatus = progress.Status ?? string.Empty;
|
||||
}
|
||||
|
||||
public void UpdateAccount(MailAccount account)
|
||||
{
|
||||
Parameter = account;
|
||||
@@ -118,7 +124,8 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
OnPropertyChanged(nameof(AccountColorHex));
|
||||
OnPropertyChanged(nameof(IsAttentionRequired));
|
||||
|
||||
if (SubMenuItems == null) return;
|
||||
if (SubMenuItems == null)
|
||||
return;
|
||||
|
||||
foreach (var item in SubMenuItems)
|
||||
{
|
||||
@@ -133,12 +140,10 @@ public partial class AccountMenuItem : MenuItemBase<MailAccount, MenuItemBase<IM
|
||||
{
|
||||
if (AttentionReason != AccountAttentionReason.None && !SubMenuItems.Any(a => a is FixAccountIssuesMenuItem))
|
||||
{
|
||||
// Add fix issue item if not exists.
|
||||
SubMenuItems.Insert(0, new FixAccountIssuesMenuItem(Parameter, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove existing if issue is resolved.
|
||||
var fixAccountIssueItem = SubMenuItems.FirstOrDefault(a => a is FixAccountIssuesMenuItem);
|
||||
|
||||
if (fixAccountIssueItem != null)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
|
||||
namespace Wino.Core.Domain.MenuItems;
|
||||
|
||||
@@ -16,50 +17,37 @@ public partial class MergedAccountMenuItem : MenuItemBase<MergedInbox, IMenuItem
|
||||
[ObservableProperty]
|
||||
private int unreadItemCount;
|
||||
|
||||
/// <summary>
|
||||
/// Total items to sync across all merged accounts.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate))]
|
||||
[NotifyPropertyChangedFor(nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate), nameof(SynchronizationProgress), nameof(SynchronizationProgressValue))]
|
||||
public partial bool IsSynchronizationInProgress { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
||||
public partial int TotalItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining items to sync across all merged accounts.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(IsSynchronizationProgressVisible), nameof(IsProgressIndeterminate))]
|
||||
[NotifyPropertyChangedFor(nameof(SynchronizationProgress), nameof(SynchronizationProgressValue), nameof(IsProgressIndeterminate))]
|
||||
public partial int RemainingItemsToSync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current synchronization status message.
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public partial string SynchronizationStatus { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated synchronization progress for merged accounts.
|
||||
/// </summary>
|
||||
public double SynchronizationProgress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TotalItemsToSync == 0 || RemainingItemsToSync == 0)
|
||||
return -1; // Indeterminate
|
||||
if (TotalItemsToSync <= 0)
|
||||
return 0;
|
||||
|
||||
return ((double)(TotalItemsToSync - RemainingItemsToSync) / TotalItemsToSync) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether synchronization progress should be visible.
|
||||
/// Visible when there's active synchronization (TotalItemsToSync > 0 or RemainingItemsToSync > 0).
|
||||
/// </summary>
|
||||
public bool IsSynchronizationProgressVisible => TotalItemsToSync > 0 || RemainingItemsToSync > 0;
|
||||
public double SynchronizationProgressValue => SynchronizationProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Whether progress should be indeterminate.
|
||||
/// </summary>
|
||||
public bool IsProgressIndeterminate => TotalItemsToSync == 0 && IsSynchronizationProgressVisible;
|
||||
public bool IsSynchronizationProgressVisible => IsSynchronizationInProgress;
|
||||
|
||||
public bool IsProgressIndeterminate => IsSynchronizationInProgress && TotalItemsToSync <= 0;
|
||||
|
||||
[ObservableProperty]
|
||||
private string mergedAccountName;
|
||||
@@ -77,23 +65,34 @@ public partial class MergedAccountMenuItem : MenuItemBase<MergedInbox, IMenuItem
|
||||
{
|
||||
UnreadItemCount = SubMenuItems.OfType<IAccountMenuItem>().Sum(a => a.UnreadItemCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggregates synchronization progress from all child account menu items.
|
||||
/// </summary>
|
||||
|
||||
public void RefreshSynchronizationProgress()
|
||||
{
|
||||
var accountMenuItems = SubMenuItems.OfType<IAccountMenuItem>().ToList();
|
||||
|
||||
TotalItemsToSync = accountMenuItems.Sum(a => a.TotalItemsToSync);
|
||||
RemainingItemsToSync = accountMenuItems.Sum(a => a.RemainingItemsToSync);
|
||||
|
||||
// Use first non-empty status message
|
||||
SynchronizationStatus = accountMenuItems.FirstOrDefault(a => !string.IsNullOrEmpty(a.SynchronizationStatus))?.SynchronizationStatus ?? string.Empty;
|
||||
var activeAccountMenuItems = SubMenuItems
|
||||
.OfType<IAccountMenuItem>()
|
||||
.Where(a => a.IsSynchronizationInProgress)
|
||||
.ToList();
|
||||
|
||||
IsSynchronizationInProgress = activeAccountMenuItems.Any();
|
||||
TotalItemsToSync = activeAccountMenuItems.Sum(a => a.TotalItemsToSync);
|
||||
RemainingItemsToSync = activeAccountMenuItems.Sum(a => a.RemainingItemsToSync);
|
||||
SynchronizationStatus = activeAccountMenuItems
|
||||
.Select(a => a.SynchronizationStatus)
|
||||
.FirstOrDefault(s => !string.IsNullOrWhiteSpace(s)) ?? string.Empty;
|
||||
}
|
||||
|
||||
public void ApplySynchronizationProgress(AccountSynchronizationProgress progress)
|
||||
{
|
||||
if (progress == null)
|
||||
return;
|
||||
|
||||
IsSynchronizationInProgress = progress.IsInProgress;
|
||||
TotalItemsToSync = progress.TotalUnits;
|
||||
RemainingItemsToSync = progress.RemainingUnits;
|
||||
SynchronizationStatus = progress.Status ?? string.Empty;
|
||||
}
|
||||
|
||||
public void UpdateAccount(MailAccount account)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Enums;
|
||||
|
||||
namespace Wino.Core.Domain.Models.Synchronization;
|
||||
|
||||
public record AccountSynchronizationProgress(
|
||||
Guid AccountId,
|
||||
SynchronizationProgressCategory Category,
|
||||
bool IsInProgress,
|
||||
bool IsIndeterminate,
|
||||
double ProgressPercentage,
|
||||
int TotalUnits,
|
||||
int RemainingUnits,
|
||||
string Status,
|
||||
AccountSynchronizerState State)
|
||||
{
|
||||
public int CompletedUnits => Math.Max(0, TotalUnits - RemainingUnits);
|
||||
|
||||
public static AccountSynchronizationProgress Idle(Guid accountId, SynchronizationProgressCategory category)
|
||||
=> new(
|
||||
accountId,
|
||||
category,
|
||||
false,
|
||||
false,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
string.Empty,
|
||||
AccountSynchronizerState.Idle);
|
||||
}
|
||||
@@ -108,6 +108,11 @@
|
||||
"SyncAction_SynchronizingCalendarData": "Synchronizing calendar data",
|
||||
"SyncAction_SynchronizingCalendarEvents": "Synchronizing calendar events",
|
||||
"SyncAction_SynchronizingCalendarMetadata": "Synchronizing calendar metadata",
|
||||
"SynchronizationProgress_ApplyingChanges": "Applying changes",
|
||||
"SynchronizationProgress_CalendarInProgress": "Calendar sync in progress",
|
||||
"SynchronizationProgress_CalendarPercent": "Calendar sync {0}%",
|
||||
"SynchronizationProgress_MailInProgress": "Mail sync in progress",
|
||||
"SynchronizationProgress_MailPercent": "Mail sync {0}%",
|
||||
"SyncAction_Unarchiving": "Unarchiving {0} mail(s)",
|
||||
"CalendarAllDayEventSummary": "all-day events",
|
||||
"CalendarDisplayOptions_Color": "Color",
|
||||
|
||||
Reference in New Issue
Block a user