Account attentions.

This commit is contained in:
Burak Kaan Köse
2025-11-14 12:12:13 +01:00
parent 6be271565e
commit 13cb3a1042
11 changed files with 70 additions and 42 deletions
@@ -90,6 +90,8 @@ public class OutlookAuthenticator : BaseAuthenticator, IOutlookAuthenticator
try
{
throw new MsalUiRequiredException("test", "test2");
var authResult = await _publicClientApplication.AcquireTokenSilent(Scope, storedAccount).ExecuteAsync();
return new TokenInformationEx(authResult.AccessToken, authResult.Account.Username);
@@ -113,6 +115,12 @@ public class OutlookAuthenticator : BaseAuthenticator, IOutlookAuthenticator
{
await EnsureTokenCacheAttachedAsync();
// Interactive authentication required but window doesn't exist.
// This can happen when being called from a notification background task and the token is expired.
// Force account attention;
if (_nativeAppService.GetCoreWindowHwnd == null) throw new AuthenticationAttentionException(account);
AuthenticationResult authResult = await _publicClientApplication
.AcquireTokenInteractive(Scope)
.ExecuteAsync();
+1
View File
@@ -12,6 +12,7 @@ public static class Constants
public const string ToastMailUniqueIdKey = nameof(ToastMailUniqueIdKey);
public const string ToastActionKey = nameof(ToastActionKey);
public const string ToastMailAccountIdKey = nameof(ToastMailAccountIdKey);
public const string ClientLogFile = "Client_.log";
public const string ServerLogFile = "Server_.log";
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Interfaces;
@@ -22,4 +23,10 @@ public interface INotificationBuilder
/// Removes the toast notification for a specific mail by unique id.
/// </summary>
void RemoveNotification(Guid mailUniqueId);
/// <summary>
/// Shows a notification that the account requires attention.
/// </summary>
/// <param name="account">Account that needs attention.</param>
void CreateAttentionRequiredNotification(MailAccount account);
}
@@ -41,11 +41,6 @@ public interface ISynchronizationManager
/// </summary>
bool IsAccountSynchronizing(Guid accountId);
/// <summary>
/// Queues a mail action request to the corresponding account's synchronizer.
/// </summary>
Task QueueRequestAsync(IRequestBase request, Guid accountId);
/// <summary>
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
/// </summary>
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
@@ -22,6 +23,8 @@ public class MailSynchronizationResult
public SynchronizationCompletedState CompletedState { get; set; }
public Exception Exception { get; set; }
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
// Mail synchronization
@@ -41,5 +44,9 @@ public class MailSynchronizationResult
};
public static MailSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static MailSynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };
public static MailSynchronizationResult Failed(Exception exception) => new()
{
CompletedState = SynchronizationCompletedState.Failed,
Exception = exception
};
}
@@ -47,6 +47,7 @@
"BasicIMAPSetupDialog_Title": "IMAP Account",
"Busy": "Busy",
"Buttons_AddAccount": "Add Account",
"Buttons_FixAccount": "Fix Account",
"Buttons_AddNewAlias": "Add New Alias",
"Buttons_Allow": "Allow",
"Buttons_ApplyTheme": "Apply Theme",
@@ -172,6 +173,8 @@
"ElementTheme_Light": "Light mode",
"Emoji": "Emoji",
"Error_FailedToSetupSystemFolders_Title": "Failed to setup system folders",
"Exception_AccountNeedsAttention_Title": "Account needs attention",
"Exception_AccountNeedsAttention_Message": "'{0}' requires your attention to continue working.",
"Exception_AuthenticationCanceled": "Authentication canceled",
"Exception_CustomThemeExists": "This theme already exists.",
"Exception_CustomThemeMissingName": "You must provide a name.",
+31 -18
View File
@@ -9,6 +9,7 @@ using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Messaging.UI;
@@ -17,19 +18,16 @@ namespace Wino.Core.WinUI.Services;
public class NotificationBuilder : INotificationBuilder
{
private readonly IUnderlyingThemeService _underlyingThemeService;
private readonly IAccountService _accountService;
private readonly IFolderService _folderService;
private readonly IMailService _mailService;
private readonly IThumbnailService _thumbnailService;
public NotificationBuilder(IUnderlyingThemeService underlyingThemeService,
IAccountService accountService,
public NotificationBuilder(IAccountService accountService,
IFolderService folderService,
IMailService mailService,
IThumbnailService thumbnailService)
{
_underlyingThemeService = underlyingThemeService;
_accountService = accountService;
_folderService = folderService;
_mailService = mailService;
@@ -52,23 +50,23 @@ public class NotificationBuilder : INotificationBuilder
{
var mailItem = await _mailService.GetSingleMailItemAsync(item.UniqueId);
if (mailItem == null || mailItem.AssignedFolder == null)
continue;
//if (mailItem == null || mailItem.AssignedFolder == null)
// continue;
// Only create notifications for Inbox folder mails
if (mailItem.AssignedFolder.SpecialFolderType != SpecialFolderType.Inbox)
continue;
//// Only create notifications for Inbox folder mails
//if (mailItem.AssignedFolder.SpecialFolderType != SpecialFolderType.Inbox)
// continue;
// Skip folders with synchronization disabled
if (!mailItem.AssignedFolder.IsSynchronizationEnabled)
continue;
//// Skip folders with synchronization disabled
//if (!mailItem.AssignedFolder.IsSynchronizationEnabled)
// continue;
// Skip already read mails
if (mailItem.IsRead)
{
RemoveNotification(mailItem.UniqueId);
continue;
}
//// Skip already read mails
//if (mailItem.IsRead)
//{
// RemoveNotification(mailItem.UniqueId);
// continue;
//}
inboxMailItems.Add(mailItem);
}
@@ -237,4 +235,19 @@ public class NotificationBuilder : INotificationBuilder
Log.Error(ex, $"Failed to remove notification for mail {mailUniqueId}");
}
}
public void CreateAttentionRequiredNotification(MailAccount account)
{
var builder = new ToastContentBuilder();
builder.SetToastScenario(ToastScenario.Default);
builder.AddText(Translator.Exception_AccountNeedsAttention_Title);
builder.AddText(string.Format(Translator.Exception_AccountNeedsAttention_Message, account.Name));
builder.AddButton(GetDismissButton());
builder.AddArgument(Constants.ToastMailAccountIdKey, account.Id.ToString());
builder.AddButton(new ToastButton().SetContent(Translator.Buttons_FixAccount));
builder.Show();
}
}
+5 -12
View File
@@ -134,7 +134,8 @@ public class SynchronizationManager : ISynchronizationManager
if (synchronizer == null)
{
_logger.Error("Could not find or create synchronizer for account {AccountId}", options.AccountId);
return MailSynchronizationResult.Failed;
return MailSynchronizationResult.Failed(new Exception("Can't create/get synchronizer."));
}
_logger.Information("Starting mail synchronization for account {AccountId} with type {SyncType}",
@@ -151,12 +152,14 @@ public class SynchronizationManager : ISynchronizationManager
if (result.DownloadedMessages?.Any() ?? false)
await _notificationBuilder.CreateNotificationsAsync(result.DownloadedMessages);
await _notificationBuilder.UpdateTaskbarIconBadgeAsync();
return result;
}
catch (Exception ex)
{
_logger.Error(ex, "Mail synchronization failed for account {AccountId}", options.AccountId);
return MailSynchronizationResult.Failed;
return MailSynchronizationResult.Failed(ex);
}
}
@@ -178,16 +181,6 @@ public class SynchronizationManager : ISynchronizationManager
return false;
}
/// <summary>
/// Queues a mail action request to the corresponding account's synchronizer.
/// </summary>
/// <param name="request">Request to queue</param>
/// <param name="accountId">Account ID to queue the request for</param>
public async Task QueueRequestAsync(IRequestBase request, Guid accountId)
{
await QueueRequestAsync(request, accountId, triggerSynchronization: true);
}
/// <summary>
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
/// </summary>
+2 -2
View File
@@ -271,7 +271,7 @@ public abstract class WinoSynchronizer<TBaseRequest, TMessageType, TCalendarEven
{
Log.Error(ex, "Failed to update profile information for {Name}", Account.Name);
return MailSynchronizationResult.Failed;
return MailSynchronizationResult.Failed(ex);
}
return MailSynchronizationResult.Completed(newProfileInformation);
@@ -292,7 +292,7 @@ public abstract class WinoSynchronizer<TBaseRequest, TMessageType, TCalendarEven
{
Log.Error(ex, "Failed to update aliases for {Name}", Account.Name);
return MailSynchronizationResult.Failed;
return MailSynchronizationResult.Failed(ex);
}
}
+2 -2
View File
@@ -37,7 +37,6 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
public bool IsNotificationActivation(out AppNotificationActivatedEventArgs args)
{
// https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/toast-notifications?tabs=appsdk
var activationArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
if (activationArgs.Kind == ExtendedActivationKind.AppNotification)
@@ -179,6 +178,7 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
{
// User clicked action button (Mark as Read, Delete, etc.)
// Execute action without window and exit.
await HandleToastActionAsync(action, mailItemUniqueId);
}
}
@@ -312,7 +312,7 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
/// <summary>
/// Creates the main window and activates it.
/// </summary>
private async Task CreateAndActivateWindow(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
private async Task CreateAndActivateWindow(LaunchActivatedEventArgs args)
{
CreateWindow(args);
@@ -1,7 +1,8 @@
{
"profiles": {
"Wino.Mail.WinUI (Package)": {
"commandName": "MsixPackage"
"commandName": "MsixPackage",
"doNotLaunchApp": true
},
"Wino.Mail.WinUI (Unpackaged)": {
"commandName": "Project"