Account attentions.
This commit is contained in:
@@ -90,6 +90,8 @@ public class OutlookAuthenticator : BaseAuthenticator, IOutlookAuthenticator
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
throw new MsalUiRequiredException("test", "test2");
|
||||||
|
|
||||||
var authResult = await _publicClientApplication.AcquireTokenSilent(Scope, storedAccount).ExecuteAsync();
|
var authResult = await _publicClientApplication.AcquireTokenSilent(Scope, storedAccount).ExecuteAsync();
|
||||||
|
|
||||||
return new TokenInformationEx(authResult.AccessToken, authResult.Account.Username);
|
return new TokenInformationEx(authResult.AccessToken, authResult.Account.Username);
|
||||||
@@ -113,6 +115,12 @@ public class OutlookAuthenticator : BaseAuthenticator, IOutlookAuthenticator
|
|||||||
{
|
{
|
||||||
await EnsureTokenCacheAttachedAsync();
|
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
|
AuthenticationResult authResult = await _publicClientApplication
|
||||||
.AcquireTokenInteractive(Scope)
|
.AcquireTokenInteractive(Scope)
|
||||||
.ExecuteAsync();
|
.ExecuteAsync();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public static class Constants
|
|||||||
|
|
||||||
public const string ToastMailUniqueIdKey = nameof(ToastMailUniqueIdKey);
|
public const string ToastMailUniqueIdKey = nameof(ToastMailUniqueIdKey);
|
||||||
public const string ToastActionKey = nameof(ToastActionKey);
|
public const string ToastActionKey = nameof(ToastActionKey);
|
||||||
|
public const string ToastMailAccountIdKey = nameof(ToastMailAccountIdKey);
|
||||||
|
|
||||||
public const string ClientLogFile = "Client_.log";
|
public const string ClientLogFile = "Client_.log";
|
||||||
public const string ServerLogFile = "Server_.log";
|
public const string ServerLogFile = "Server_.log";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Wino.Core.Domain.Entities.Mail;
|
using Wino.Core.Domain.Entities.Mail;
|
||||||
|
using Wino.Core.Domain.Entities.Shared;
|
||||||
|
|
||||||
namespace Wino.Core.Domain.Interfaces;
|
namespace Wino.Core.Domain.Interfaces;
|
||||||
|
|
||||||
@@ -22,4 +23,10 @@ public interface INotificationBuilder
|
|||||||
/// Removes the toast notification for a specific mail by unique id.
|
/// Removes the toast notification for a specific mail by unique id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void RemoveNotification(Guid mailUniqueId);
|
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>
|
/// </summary>
|
||||||
bool IsAccountSynchronizing(Guid accountId);
|
bool IsAccountSynchronizing(Guid accountId);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queues a mail action request to the corresponding account's synchronizer.
|
|
||||||
/// </summary>
|
|
||||||
Task QueueRequestAsync(IRequestBase request, Guid accountId);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
|
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Wino.Core.Domain.Entities.Mail;
|
using Wino.Core.Domain.Entities.Mail;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
@@ -22,6 +23,8 @@ public class MailSynchronizationResult
|
|||||||
|
|
||||||
public SynchronizationCompletedState CompletedState { get; set; }
|
public SynchronizationCompletedState CompletedState { get; set; }
|
||||||
|
|
||||||
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
|
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
|
||||||
|
|
||||||
// Mail synchronization
|
// Mail synchronization
|
||||||
@@ -41,5 +44,9 @@ public class MailSynchronizationResult
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static MailSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
|
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",
|
"BasicIMAPSetupDialog_Title": "IMAP Account",
|
||||||
"Busy": "Busy",
|
"Busy": "Busy",
|
||||||
"Buttons_AddAccount": "Add Account",
|
"Buttons_AddAccount": "Add Account",
|
||||||
|
"Buttons_FixAccount": "Fix Account",
|
||||||
"Buttons_AddNewAlias": "Add New Alias",
|
"Buttons_AddNewAlias": "Add New Alias",
|
||||||
"Buttons_Allow": "Allow",
|
"Buttons_Allow": "Allow",
|
||||||
"Buttons_ApplyTheme": "Apply Theme",
|
"Buttons_ApplyTheme": "Apply Theme",
|
||||||
@@ -172,6 +173,8 @@
|
|||||||
"ElementTheme_Light": "Light mode",
|
"ElementTheme_Light": "Light mode",
|
||||||
"Emoji": "Emoji",
|
"Emoji": "Emoji",
|
||||||
"Error_FailedToSetupSystemFolders_Title": "Failed to setup system folders",
|
"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_AuthenticationCanceled": "Authentication canceled",
|
||||||
"Exception_CustomThemeExists": "This theme already exists.",
|
"Exception_CustomThemeExists": "This theme already exists.",
|
||||||
"Exception_CustomThemeMissingName": "You must provide a name.",
|
"Exception_CustomThemeMissingName": "You must provide a name.",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Windows.Data.Xml.Dom;
|
|||||||
using Windows.UI.Notifications;
|
using Windows.UI.Notifications;
|
||||||
using Wino.Core.Domain;
|
using Wino.Core.Domain;
|
||||||
using Wino.Core.Domain.Entities.Mail;
|
using Wino.Core.Domain.Entities.Mail;
|
||||||
|
using Wino.Core.Domain.Entities.Shared;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
using Wino.Messaging.UI;
|
using Wino.Messaging.UI;
|
||||||
@@ -17,19 +18,16 @@ namespace Wino.Core.WinUI.Services;
|
|||||||
|
|
||||||
public class NotificationBuilder : INotificationBuilder
|
public class NotificationBuilder : INotificationBuilder
|
||||||
{
|
{
|
||||||
private readonly IUnderlyingThemeService _underlyingThemeService;
|
|
||||||
private readonly IAccountService _accountService;
|
private readonly IAccountService _accountService;
|
||||||
private readonly IFolderService _folderService;
|
private readonly IFolderService _folderService;
|
||||||
private readonly IMailService _mailService;
|
private readonly IMailService _mailService;
|
||||||
private readonly IThumbnailService _thumbnailService;
|
private readonly IThumbnailService _thumbnailService;
|
||||||
|
|
||||||
public NotificationBuilder(IUnderlyingThemeService underlyingThemeService,
|
public NotificationBuilder(IAccountService accountService,
|
||||||
IAccountService accountService,
|
|
||||||
IFolderService folderService,
|
IFolderService folderService,
|
||||||
IMailService mailService,
|
IMailService mailService,
|
||||||
IThumbnailService thumbnailService)
|
IThumbnailService thumbnailService)
|
||||||
{
|
{
|
||||||
_underlyingThemeService = underlyingThemeService;
|
|
||||||
_accountService = accountService;
|
_accountService = accountService;
|
||||||
_folderService = folderService;
|
_folderService = folderService;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
@@ -52,23 +50,23 @@ public class NotificationBuilder : INotificationBuilder
|
|||||||
{
|
{
|
||||||
var mailItem = await _mailService.GetSingleMailItemAsync(item.UniqueId);
|
var mailItem = await _mailService.GetSingleMailItemAsync(item.UniqueId);
|
||||||
|
|
||||||
if (mailItem == null || mailItem.AssignedFolder == null)
|
//if (mailItem == null || mailItem.AssignedFolder == null)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
// Only create notifications for Inbox folder mails
|
//// Only create notifications for Inbox folder mails
|
||||||
if (mailItem.AssignedFolder.SpecialFolderType != SpecialFolderType.Inbox)
|
//if (mailItem.AssignedFolder.SpecialFolderType != SpecialFolderType.Inbox)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
// Skip folders with synchronization disabled
|
//// Skip folders with synchronization disabled
|
||||||
if (!mailItem.AssignedFolder.IsSynchronizationEnabled)
|
//if (!mailItem.AssignedFolder.IsSynchronizationEnabled)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
// Skip already read mails
|
//// Skip already read mails
|
||||||
if (mailItem.IsRead)
|
//if (mailItem.IsRead)
|
||||||
{
|
//{
|
||||||
RemoveNotification(mailItem.UniqueId);
|
// RemoveNotification(mailItem.UniqueId);
|
||||||
continue;
|
// continue;
|
||||||
}
|
//}
|
||||||
|
|
||||||
inboxMailItems.Add(mailItem);
|
inboxMailItems.Add(mailItem);
|
||||||
}
|
}
|
||||||
@@ -237,4 +235,19 @@ public class NotificationBuilder : INotificationBuilder
|
|||||||
Log.Error(ex, $"Failed to remove notification for mail {mailUniqueId}");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ public class SynchronizationManager : ISynchronizationManager
|
|||||||
if (synchronizer == null)
|
if (synchronizer == null)
|
||||||
{
|
{
|
||||||
_logger.Error("Could not find or create synchronizer for account {AccountId}", options.AccountId);
|
_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}",
|
_logger.Information("Starting mail synchronization for account {AccountId} with type {SyncType}",
|
||||||
@@ -151,12 +152,14 @@ public class SynchronizationManager : ISynchronizationManager
|
|||||||
if (result.DownloadedMessages?.Any() ?? false)
|
if (result.DownloadedMessages?.Any() ?? false)
|
||||||
await _notificationBuilder.CreateNotificationsAsync(result.DownloadedMessages);
|
await _notificationBuilder.CreateNotificationsAsync(result.DownloadedMessages);
|
||||||
|
|
||||||
|
await _notificationBuilder.UpdateTaskbarIconBadgeAsync();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex, "Mail synchronization failed for account {AccountId}", options.AccountId);
|
_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;
|
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>
|
/// <summary>
|
||||||
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
|
/// Queues a mail action request to the corresponding account's synchronizer with optional synchronization triggering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public abstract class WinoSynchronizer<TBaseRequest, TMessageType, TCalendarEven
|
|||||||
{
|
{
|
||||||
Log.Error(ex, "Failed to update profile information for {Name}", Account.Name);
|
Log.Error(ex, "Failed to update profile information for {Name}", Account.Name);
|
||||||
|
|
||||||
return MailSynchronizationResult.Failed;
|
return MailSynchronizationResult.Failed(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return MailSynchronizationResult.Completed(newProfileInformation);
|
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);
|
Log.Error(ex, "Failed to update aliases for {Name}", Account.Name);
|
||||||
|
|
||||||
return MailSynchronizationResult.Failed;
|
return MailSynchronizationResult.Failed(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
|
|||||||
|
|
||||||
public bool IsNotificationActivation(out AppNotificationActivatedEventArgs args)
|
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();
|
var activationArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
|
||||||
|
|
||||||
if (activationArgs.Kind == ExtendedActivationKind.AppNotification)
|
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.)
|
// User clicked action button (Mark as Read, Delete, etc.)
|
||||||
// Execute action without window and exit.
|
// Execute action without window and exit.
|
||||||
|
|
||||||
await HandleToastActionAsync(action, mailItemUniqueId);
|
await HandleToastActionAsync(action, mailItemUniqueId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,7 +312,7 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the main window and activates it.
|
/// Creates the main window and activates it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task CreateAndActivateWindow(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
private async Task CreateAndActivateWindow(LaunchActivatedEventArgs args)
|
||||||
{
|
{
|
||||||
CreateWindow(args);
|
CreateWindow(args);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Wino.Mail.WinUI (Package)": {
|
"Wino.Mail.WinUI (Package)": {
|
||||||
"commandName": "MsixPackage"
|
"commandName": "MsixPackage",
|
||||||
|
"doNotLaunchApp": true
|
||||||
},
|
},
|
||||||
"Wino.Mail.WinUI (Unpackaged)": {
|
"Wino.Mail.WinUI (Unpackaged)": {
|
||||||
"commandName": "Project"
|
"commandName": "Project"
|
||||||
|
|||||||
Reference in New Issue
Block a user