Full trust Wino Server implementation. (#295)
* Separation of messages. Introducing Wino.Messages library. * Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics. * Remove debug code. * Enable generating assembly info to deal with unsupported os platform warnings. * Fix server-client connection. * UIMessage communication. Single instancing for server and re-connection mechanism on suspension. * Removed IWinoSynchronizerFactory from UWP project. * Removal of background task service from core. * Delegating changes to UI and triggering new background synchronization. * Fix build error. * Moved core lib messages to Messaging project. * Better client-server communication. Handling of requests in the server. New synchronizer factory in the server. * WAM broker and MSAL token caching for OutlookAuthenticator. Handling account creation for Outlook. * WinoServerResponse basics. * Delegating protocol activation for Gmail authenticator. * Adding margin to searchbox to match action bar width. * Move libraries into lib folder. * Storing base64 encoded mime on draft creation instead of MimeMessage object. Fixes serialization/deserialization issue with S.T.Json * Scrollbar adjustments * WınoExpander for thread expander layout ıssue. * Handling synchronizer state changes. * Double init on background activation. * FIxing packaging issues and new Wino Mail launcher protocol for activation from full thrust process. * Remove debug deserialization. * Remove debug code. * Making sure the server connection is established when the app is launched. * Thrust -> Trust string replacement... * Rename package to Wino Mail * Enable translated values in the server. * Fixed an issue where toast activation can't find the clicked mail after the folder is initialized. * Revert debug code. * Change server background sync to every 3 minute and Inbox only synchronization. * Revert google auth changes. * App preferences page. * Changing tray icon visibility on preference change. * Start the server with invisible tray icon if set to invisible. * Reconnect button on the title bar. * Handling of toast actions. * Enable x86 build for server during packaging. * Get rid of old background tasks and v180 migration. * Terminate client when Exit clicked in server. * Introducing SynchronizationSource to prevent notifying UI after server tick synchronization. * Remove confirmAppClose restricted capability and unused debug code in manifest. * Closing the reconnect info popup when reconnect is clicked. * Custom RetryHandler for OutlookSynchronizer and separating client/server logs. * Running server on Windows startup. * Fix startup exe. * Fix for expander list view item paddings. * Force full sync on app launch instead of Inbox. * Fix draft creation. * Fix an issue with custom folder sync logic. * Reporting back account sync progress from server. * Fix sending drafts and missing notifications for imap. * Changing imap folder sync requirements. * Retain file count is set to 3. * Disabled swipe gestures temporarily due to native crash with SwipeControl * Save all attachments implementation. * Localization for save all attachments button. * Fix logging dates for logs. * Fixing ARM64 build. * Add ARM64 build config to packaging project. * Comment out OutOfProcPDB for ARM64. * Hnadling GONE response for Outlook folder synchronization.
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
private readonly IStoreRatingService _storeRatingService;
|
||||
private readonly INativeAppService _nativeAppService;
|
||||
private readonly IAppInitializerService _appInitializerService;
|
||||
private readonly IApplicationConfiguration _appInitializerService;
|
||||
private readonly IFileService _fileService;
|
||||
private readonly ILogInitializer _logInitializer;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Wino.Mail.ViewModels
|
||||
IDialogService dialogService,
|
||||
INativeAppService nativeAppService,
|
||||
IPreferencesService preferencesService,
|
||||
IAppInitializerService appInitializerService,
|
||||
IApplicationConfiguration appInitializerService,
|
||||
IFileService fileService,
|
||||
ILogInitializer logInitializer) : base(dialogService)
|
||||
{
|
||||
@@ -72,12 +72,13 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
private Task ShareProtocolLogAsync()
|
||||
=> SaveLogInternalAsync(ImapTestService.ProtocolLogFileName);
|
||||
|
||||
private Task ShareWinoLogAsync()
|
||||
=> SaveLogInternalAsync(LogInitializer.WinoLogFileName);
|
||||
=> SaveLogInternalAsync(Constants.ClientLogFile);
|
||||
|
||||
private async Task SaveLogInternalAsync(string sourceFileName)
|
||||
{
|
||||
var appDataFolder = _appInitializerService.GetApplicationDataFolder();
|
||||
var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
|
||||
|
||||
var logFile = Path.Combine(appDataFolder, sourceFileName);
|
||||
|
||||
|
||||
@@ -5,21 +5,19 @@ using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Core.Requests;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
public partial class AccountDetailsPageViewModel : BaseViewModel
|
||||
{
|
||||
private readonly IWinoSynchronizerFactory _synchronizerFactory;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IFolderService _folderService;
|
||||
|
||||
@@ -45,11 +43,9 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
|
||||
public AccountDetailsPageViewModel(IDialogService dialogService,
|
||||
IWinoSynchronizerFactory synchronizerFactory,
|
||||
IAccountService accountService,
|
||||
IFolderService folderService) : base(dialogService)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_accountService = accountService;
|
||||
_folderService = folderService;
|
||||
}
|
||||
@@ -99,10 +95,7 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
await _accountService.DeleteAccountAsync(Account);
|
||||
|
||||
_synchronizerFactory.DeleteSynchronizer(Account);
|
||||
|
||||
// TODO: Clear existing requests.
|
||||
// _synchronizationWorker.ClearRequests(Account.Id);
|
||||
// TODO: Server: Cancel ongoing calls from server for this account.
|
||||
|
||||
DialogService.InfoBarMessage(Translator.Info_AccountDeletedTitle, string.Format(Translator.Info_AccountDeletedMessage, Account.Name), InfoBarMessageType.Success);
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Store;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.Messages.Authorization;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Core.Requests;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Authorization;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -35,7 +36,7 @@ namespace Wino.Mail.ViewModels
|
||||
private readonly IStoreManagementService _storeManagementService;
|
||||
private readonly IPreferencesService _preferencesService;
|
||||
private readonly IAuthenticationProvider _authenticationProvider;
|
||||
private readonly IWinoSynchronizerFactory _synchronizerFactory;
|
||||
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
|
||||
|
||||
public ObservableCollection<IAccountProviderDetailViewModel> Accounts { get; set; } = [];
|
||||
|
||||
@@ -60,22 +61,22 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
public AccountManagementViewModel(IDialogService dialogService,
|
||||
IWinoNavigationService navigationService,
|
||||
IWinoSynchronizerFactory synchronizerFactory,
|
||||
IAccountService accountService,
|
||||
IProviderService providerService,
|
||||
IFolderService folderService,
|
||||
IStoreManagementService storeManagementService,
|
||||
IPreferencesService preferencesService,
|
||||
IAuthenticationProvider authenticationProvider) : base(dialogService)
|
||||
IAuthenticationProvider authenticationProvider,
|
||||
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
|
||||
{
|
||||
_accountService = accountService;
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_dialogService = dialogService;
|
||||
_providerService = providerService;
|
||||
_folderService = folderService;
|
||||
_storeManagementService = storeManagementService;
|
||||
_preferencesService = preferencesService;
|
||||
_authenticationProvider = authenticationProvider;
|
||||
_winoServerConnectionManager = winoServerConnectionManager;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -153,7 +154,7 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
creationDialog = _dialogService.GetAccountCreationDialog(accountCreationDialogResult.ProviderType);
|
||||
|
||||
_accountService.ExternalAuthenticationAuthenticator = _authenticationProvider.GetAuthenticator(accountCreationDialogResult.ProviderType);
|
||||
// _accountService.ExternalAuthenticationAuthenticator = _authenticationProvider.GetAuthenticator(accountCreationDialogResult.ProviderType);
|
||||
|
||||
CustomServerInformation customServerInformation = null;
|
||||
|
||||
@@ -193,9 +194,13 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
// For OAuth authentications, we just generate token and assign it to the MailAccount.
|
||||
|
||||
tokenInformation = await _accountService.ExternalAuthenticationAuthenticator.GenerateTokenAsync(createdAccount, false)
|
||||
?? throw new AuthenticationException(Translator.Exception_TokenInfoRetrivalFailed);
|
||||
var tokenInformationResponse = await _winoServerConnectionManager.GetResponseAsync<TokenInformation, AuthorizationRequested>(new AuthorizationRequested(accountCreationDialogResult.ProviderType, createdAccount));
|
||||
|
||||
tokenInformationResponse.ThrowIfFailed();
|
||||
|
||||
// ?? throw new AuthenticationException(Translator.Exception_TokenInfoRetrivalFailed);
|
||||
|
||||
tokenInformation = tokenInformationResponse.Data;
|
||||
createdAccount.Address = tokenInformation.Address;
|
||||
tokenInformation.AccountId = createdAccount.Id;
|
||||
}
|
||||
@@ -205,8 +210,6 @@ namespace Wino.Mail.ViewModels
|
||||
// Local account has been created.
|
||||
// Create new synchronizer and start synchronization.
|
||||
|
||||
var synchronizer = _synchronizerFactory.CreateNewSynchronizer(createdAccount);
|
||||
|
||||
if (creationDialog is ICustomServerAccountCreationDialog customServerAccountCreationDialog)
|
||||
customServerAccountCreationDialog.ShowPreparingFolders();
|
||||
else
|
||||
@@ -218,8 +221,9 @@ namespace Wino.Mail.ViewModels
|
||||
Type = SynchronizationType.FoldersOnly
|
||||
};
|
||||
|
||||
var synchronizationResult = await synchronizer.SynchronizeAsync(options);
|
||||
var synchronizationResultResponse = await _winoServerConnectionManager.GetResponseAsync<SynchronizationResult, NewSynchronizationRequested>(new NewSynchronizationRequested(options, SynchronizationSource.Client));
|
||||
|
||||
var synchronizationResult = synchronizationResultResponse.Data;
|
||||
if (synchronizationResult.CompletedState != SynchronizationCompletedState.Success)
|
||||
throw new Exception(Translator.Exception_FailedToSynchronizeFolders);
|
||||
|
||||
@@ -377,11 +381,10 @@ namespace Wino.Mail.ViewModels
|
||||
return new AccountProviderDetailViewModel(provider, account);
|
||||
}
|
||||
|
||||
public void Receive(ProtocolAuthorizationCallbackReceived message)
|
||||
public async void Receive(ProtocolAuthorizationCallbackReceived message)
|
||||
{
|
||||
// Authorization must be completed in account service.
|
||||
|
||||
_accountService.ExternalAuthenticationAuthenticator?.ContinueAuthorization(message.AuthorizationResponseUri);
|
||||
// Authorization must be completed in the server.
|
||||
await _winoServerConnectionManager.GetResponseAsync<bool, ProtocolAuthorizationCallbackReceived>(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
140
Wino.Mail.ViewModels/AppPreferencesPageViewModel.cs
Normal file
140
Wino.Mail.ViewModels/AppPreferencesPageViewModel.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Messaging.Server;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
public partial class AppPreferencesPageViewModel : BaseViewModel
|
||||
{
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private List<string> _appTerminationBehavior;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorDisabled))]
|
||||
[NotifyPropertyChangedFor(nameof(IsStartupBehaviorEnabled))]
|
||||
private StartupBehaviorResult startupBehaviorResult;
|
||||
|
||||
public bool IsStartupBehaviorDisabled => !IsStartupBehaviorEnabled;
|
||||
public bool IsStartupBehaviorEnabled => StartupBehaviorResult == StartupBehaviorResult.Enabled;
|
||||
|
||||
private string _selectedAppTerminationBehavior;
|
||||
public string SelectedAppTerminationBehavior
|
||||
{
|
||||
get => _selectedAppTerminationBehavior;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedAppTerminationBehavior, value);
|
||||
|
||||
PreferencesService.ServerTerminationBehavior = (ServerBackgroundMode)AppTerminationBehavior.IndexOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
|
||||
private readonly IStartupBehaviorService _startupBehaviorService;
|
||||
|
||||
public AppPreferencesPageViewModel(IDialogService dialogService,
|
||||
IPreferencesService preferencesService,
|
||||
IWinoServerConnectionManager winoServerConnectionManager,
|
||||
IStartupBehaviorService startupBehaviorService) : base(dialogService)
|
||||
{
|
||||
PreferencesService = preferencesService;
|
||||
_winoServerConnectionManager = winoServerConnectionManager;
|
||||
_startupBehaviorService = startupBehaviorService;
|
||||
|
||||
// Load the app termination behavior options
|
||||
|
||||
_appTerminationBehavior =
|
||||
[
|
||||
Translator.SettingsAppPreferences_ServerBackgroundingMode_MinimizeTray_Title, // "Minimize to tray"
|
||||
Translator.SettingsAppPreferences_ServerBackgroundingMode_Invisible_Title, // "Invisible"
|
||||
Translator.SettingsAppPreferences_ServerBackgroundingMode_Terminate_Title // "Terminate"
|
||||
];
|
||||
|
||||
SelectedAppTerminationBehavior = _appTerminationBehavior[(int)PreferencesService.ServerTerminationBehavior];
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ToggleStartupBehaviorAsync()
|
||||
{
|
||||
if (IsStartupBehaviorEnabled)
|
||||
{
|
||||
await DisableStartupAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await EnableStartupAsync();
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(IsStartupBehaviorEnabled));
|
||||
}
|
||||
|
||||
private async Task EnableStartupAsync()
|
||||
{
|
||||
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(true);
|
||||
|
||||
NotifyCurrentStartupState();
|
||||
}
|
||||
|
||||
private async Task DisableStartupAsync()
|
||||
{
|
||||
StartupBehaviorResult = await _startupBehaviorService.ToggleStartupBehavior(false);
|
||||
|
||||
NotifyCurrentStartupState();
|
||||
}
|
||||
|
||||
private void NotifyCurrentStartupState()
|
||||
{
|
||||
if (StartupBehaviorResult == StartupBehaviorResult.Enabled)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Enabled, InfoBarMessageType.Success);
|
||||
}
|
||||
else if (StartupBehaviorResult == StartupBehaviorResult.Disabled)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_Disabled, InfoBarMessageType.Warning);
|
||||
}
|
||||
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByPolicy)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByPolicy, InfoBarMessageType.Warning);
|
||||
}
|
||||
else if (StartupBehaviorResult == StartupBehaviorResult.DisabledByUser)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Info, Translator.SettingsAppPreferences_StartupBehavior_DisabledByUser, InfoBarMessageType.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, Translator.SettingsAppPreferences_StartupBehavior_FatalError, InfoBarMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
|
||||
if (e.PropertyName == nameof(SelectedAppTerminationBehavior))
|
||||
{
|
||||
var terminationModeChangedResult = await _winoServerConnectionManager.GetResponseAsync<bool, ServerTerminationModeChanged>(new ServerTerminationModeChanged(PreferencesService.ServerTerminationBehavior));
|
||||
|
||||
if (!terminationModeChangedResult.IsSuccess)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.GeneralTitle_Error, terminationModeChangedResult.Message, InfoBarMessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async void OnNavigatedTo(NavigationMode mode, object parameters)
|
||||
{
|
||||
base.OnNavigatedTo(mode, parameters);
|
||||
|
||||
StartupBehaviorResult = await _startupBehaviorService.GetCurrentStartupBehaviorAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.AppCenter.Crashes;
|
||||
using MoreLinq;
|
||||
@@ -13,33 +14,30 @@ using Wino.Core;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.MenuItems;
|
||||
using Wino.Core.Messages.Accounts;
|
||||
using Wino.Core.Messages.Mails;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Core.Messages.Shell;
|
||||
using Wino.Core.Messages.Synchronization;
|
||||
using Wino.Core.Requests;
|
||||
using Wino.Core.Services;
|
||||
using Wino.Messaging.Client.Accounts;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
using Wino.Messaging.Client.Shell;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
public partial class AppShellViewModel : BaseViewModel,
|
||||
ISynchronizationProgress,
|
||||
IRecipient<NewSynchronizationRequested>,
|
||||
IRecipient<NavigateSettingsRequested>,
|
||||
IRecipient<MailtoProtocolMessageRequested>,
|
||||
IRecipient<RefreshUnreadCountsMessage>,
|
||||
IRecipient<AccountsMenuRefreshRequested>,
|
||||
IRecipient<MergedInboxRenamed>,
|
||||
IRecipient<LanguageChanged>,
|
||||
IRecipient<AccountMenuItemsReordered>
|
||||
IRecipient<AccountMenuItemsReordered>,
|
||||
IRecipient<AccountSynchronizationProgressUpdatedMessage>
|
||||
{
|
||||
#region Menu Items
|
||||
|
||||
@@ -62,6 +60,7 @@ namespace Wino.Mail.ViewModels
|
||||
#endregion
|
||||
|
||||
public IStatePersistanceService StatePersistenceService { get; }
|
||||
public IWinoServerConnectionManager ServerConnectionManager { get; }
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
public IWinoNavigationService NavigationService { get; }
|
||||
|
||||
@@ -73,7 +72,6 @@ namespace Wino.Mail.ViewModels
|
||||
private readonly INotificationBuilder _notificationBuilder;
|
||||
private readonly IWinoRequestDelegator _winoRequestDelegator;
|
||||
|
||||
private readonly IWinoSynchronizerFactory _synchronizerFactory;
|
||||
private readonly IBackgroundTaskService _backgroundTaskService;
|
||||
private readonly IMimeFileService _mimeFileService;
|
||||
|
||||
@@ -82,9 +80,11 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
private readonly SemaphoreSlim accountInitFolderUpdateSlim = new SemaphoreSlim(1);
|
||||
|
||||
[ObservableProperty]
|
||||
private WinoServerConnectionStatus activeConnectionStatus;
|
||||
|
||||
public AppShellViewModel(IDialogService dialogService,
|
||||
IWinoNavigationService navigationService,
|
||||
IWinoSynchronizerFactory synchronizerFactory,
|
||||
IBackgroundTaskService backgroundTaskService,
|
||||
IMimeFileService mimeFileService,
|
||||
INativeAppService nativeAppService,
|
||||
@@ -97,13 +97,24 @@ namespace Wino.Mail.ViewModels
|
||||
INotificationBuilder notificationBuilder,
|
||||
IWinoRequestDelegator winoRequestDelegator,
|
||||
IFolderService folderService,
|
||||
IStatePersistanceService statePersistanceService) : base(dialogService)
|
||||
IStatePersistanceService statePersistanceService,
|
||||
IWinoServerConnectionManager serverConnectionManager) : base(dialogService)
|
||||
{
|
||||
StatePersistenceService = statePersistanceService;
|
||||
ServerConnectionManager = serverConnectionManager;
|
||||
|
||||
ActiveConnectionStatus = serverConnectionManager.Status;
|
||||
ServerConnectionManager.StatusChanged += async (sender, status) =>
|
||||
{
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
ActiveConnectionStatus = status;
|
||||
});
|
||||
};
|
||||
|
||||
PreferencesService = preferencesService;
|
||||
NavigationService = navigationService;
|
||||
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_backgroundTaskService = backgroundTaskService;
|
||||
_mimeFileService = mimeFileService;
|
||||
_nativeAppService = nativeAppService;
|
||||
@@ -117,6 +128,9 @@ namespace Wino.Mail.ViewModels
|
||||
_winoRequestDelegator = winoRequestDelegator;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private Task ReconnectServerAsync() => ServerConnectionManager.ConnectAsync();
|
||||
|
||||
protected override void OnDispatcherAssigned()
|
||||
{
|
||||
base.OnDispatcherAssigned();
|
||||
@@ -221,9 +235,7 @@ namespace Wino.Mail.ViewModels
|
||||
await RecreateMenuItemsAsync();
|
||||
await ProcessLaunchOptionsAsync();
|
||||
|
||||
#if !DEBUG
|
||||
await ForceAllAccountSynchronizationsAsync();
|
||||
#endif
|
||||
await ConfigureBackgroundTasksAsync();
|
||||
}
|
||||
|
||||
@@ -233,10 +245,6 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
await _backgroundTaskService.HandleBackgroundTaskRegistrations();
|
||||
}
|
||||
catch (BackgroundTaskExecutionRequestDeniedException)
|
||||
{
|
||||
await DialogService.ShowMessageAsync(Translator.Info_BackgroundExecutionDeniedMessage, Translator.Info_BackgroundExecutionDeniedTitle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Crashes.TrackError(ex);
|
||||
@@ -255,10 +263,10 @@ namespace Wino.Mail.ViewModels
|
||||
var options = new SynchronizationOptions()
|
||||
{
|
||||
AccountId = account.Id,
|
||||
Type = SynchronizationType.Inbox
|
||||
Type = SynchronizationType.Full
|
||||
};
|
||||
|
||||
Messenger.Send(new NewSynchronizationRequested(options));
|
||||
Messenger.Send(new NewSynchronizationRequested(options, SynchronizationSource.Client));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,23 +352,27 @@ namespace Wino.Mail.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public async Task NavigateFolderAsync(IBaseFolderMenuItem baseFolderMenuItem)
|
||||
public async Task NavigateFolderAsync(IBaseFolderMenuItem baseFolderMenuItem, TaskCompletionSource<bool> folderInitAwaitTask = null)
|
||||
{
|
||||
// It's already there. Don't navigate again.
|
||||
if (SelectedMenuItem == baseFolderMenuItem) return;
|
||||
|
||||
SelectedMenuItem = baseFolderMenuItem;
|
||||
baseFolderMenuItem.IsSelected = true;
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
SelectedMenuItem = baseFolderMenuItem;
|
||||
baseFolderMenuItem.IsSelected = true;
|
||||
|
||||
var mailInitCompletionSource = new TaskCompletionSource<bool>();
|
||||
var args = new NavigateMailFolderEventArgs(baseFolderMenuItem, mailInitCompletionSource);
|
||||
if (folderInitAwaitTask == null) folderInitAwaitTask = new TaskCompletionSource<bool>();
|
||||
|
||||
NavigationService.NavigateFolder(args);
|
||||
var args = new NavigateMailFolderEventArgs(baseFolderMenuItem, folderInitAwaitTask);
|
||||
|
||||
UpdateWindowTitleForFolder(baseFolderMenuItem);
|
||||
NavigationService.NavigateFolder(args);
|
||||
|
||||
UpdateWindowTitleForFolder(baseFolderMenuItem);
|
||||
});
|
||||
|
||||
// Wait until mail list page picks up the event and finish initialization of the mails.
|
||||
await mailInitCompletionSource.Task;
|
||||
await folderInitAwaitTask.Task;
|
||||
}
|
||||
|
||||
private void UpdateWindowTitleForFolder(IBaseFolderMenuItem folder)
|
||||
@@ -594,11 +606,7 @@ namespace Wino.Mail.ViewModels
|
||||
if (navigateInbox)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
NavigateInbox(clickedBaseAccountMenuItem);
|
||||
});
|
||||
await NavigateInboxAsync(clickedBaseAccountMenuItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,20 +674,22 @@ namespace Wino.Mail.ViewModels
|
||||
await _notificationBuilder.UpdateTaskbarIconBadgeAsync();
|
||||
}
|
||||
|
||||
private async void NavigateInbox(IAccountMenuItem clickedBaseAccountMenuItem)
|
||||
private async Task NavigateInboxAsync(IAccountMenuItem clickedBaseAccountMenuItem)
|
||||
{
|
||||
var folderInitAwaitTask = new TaskCompletionSource<bool>();
|
||||
|
||||
if (clickedBaseAccountMenuItem is AccountMenuItem accountMenuItem)
|
||||
{
|
||||
if (MenuItems.TryGetWindowsStyleRootSpecialFolderMenuItem(accountMenuItem.AccountId, SpecialFolderType.Inbox, out FolderMenuItem inboxFolder))
|
||||
{
|
||||
await NavigateFolderAsync(inboxFolder);
|
||||
await NavigateFolderAsync(inboxFolder, folderInitAwaitTask);
|
||||
}
|
||||
}
|
||||
else if (clickedBaseAccountMenuItem is MergedAccountMenuItem mergedAccountMenuItem)
|
||||
{
|
||||
if (MenuItems.TryGetMergedAccountSpecialFolderMenuItem(mergedAccountMenuItem.EntityId.GetValueOrDefault(), SpecialFolderType.Inbox, out IBaseFolderMenuItem inboxFolder))
|
||||
{
|
||||
await NavigateFolderAsync(inboxFolder);
|
||||
await NavigateFolderAsync(inboxFolder, folderInitAwaitTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -769,75 +779,13 @@ namespace Wino.Mail.ViewModels
|
||||
MailtoParameters = _launchProtocolService.MailtoParameters
|
||||
};
|
||||
|
||||
var createdMimeMessage = await _mailService.CreateDraftMimeMessageAsync(account.Id, draftOptions).ConfigureAwait(false);
|
||||
var createdDraftMailMessage = await _mailService.CreateDraftAsync(account, createdMimeMessage).ConfigureAwait(false);
|
||||
var createdBase64EncodedMimeMessage = await _mailService.CreateDraftMimeBase64Async(account.Id, draftOptions).ConfigureAwait(false);
|
||||
var createdDraftMailMessage = await _mailService.CreateDraftAsync(account, createdBase64EncodedMimeMessage).ConfigureAwait(false);
|
||||
|
||||
var draftPreperationRequest = new DraftPreperationRequest(account, createdDraftMailMessage, createdMimeMessage);
|
||||
var draftPreperationRequest = new DraftPreperationRequest(account, createdDraftMailMessage, createdBase64EncodedMimeMessage);
|
||||
await _winoRequestDelegator.ExecuteAsync(draftPreperationRequest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async void Receive(NewSynchronizationRequested message)
|
||||
{
|
||||
// Don't send message for sync completion when we execute requests.
|
||||
// People are usually interested in seeing the notification after they trigger the synchronization.
|
||||
|
||||
bool shouldReportSynchronizationResult = message.Options.Type != SynchronizationType.ExecuteRequests;
|
||||
|
||||
var synchronizer = _synchronizerFactory.GetAccountSynchronizer(message.Options.AccountId);
|
||||
|
||||
if (synchronizer == null) return;
|
||||
|
||||
var accountId = message.Options.AccountId;
|
||||
|
||||
message.Options.ProgressListener = this;
|
||||
|
||||
bool isSynchronizationSucceeded = false;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: Cancellation Token
|
||||
var synchronizationResult = await synchronizer.SynchronizeAsync(message.Options);
|
||||
|
||||
isSynchronizationSucceeded = synchronizationResult.CompletedState == SynchronizationCompletedState.Success;
|
||||
|
||||
// Create notification for synchronization result.
|
||||
if (synchronizationResult.DownloadedMessages.Any())
|
||||
{
|
||||
var accountInboxFolder = await _folderService.GetSpecialFolderByAccountIdAsync(message.Options.AccountId, SpecialFolderType.Inbox);
|
||||
|
||||
if (accountInboxFolder == null) return;
|
||||
|
||||
await _notificationBuilder.CreateNotificationsAsync(accountInboxFolder.Id, synchronizationResult.DownloadedMessages);
|
||||
}
|
||||
}
|
||||
catch (AuthenticationAttentionException)
|
||||
{
|
||||
await SetAccountAttentionAsync(accountId, AccountAttentionReason.InvalidCredentials);
|
||||
}
|
||||
catch (SystemFolderConfigurationMissingException)
|
||||
{
|
||||
await SetAccountAttentionAsync(accountId, AccountAttentionReason.MissingSystemFolderConfiguration);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.Info_SyncCanceledMessage, Translator.Info_SyncCanceledMessage, InfoBarMessageType.Warning);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.Info_SyncFailedTitle, ex.Message, InfoBarMessageType.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (shouldReportSynchronizationResult)
|
||||
Messenger.Send(new AccountSynchronizationCompleted(accountId,
|
||||
isSynchronizationSucceeded ? SynchronizationCompletedState.Success : SynchronizationCompletedState.Failed,
|
||||
message.Options.GroupedSynchronizationTrackingId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override async void OnAccountUpdated(MailAccount updatedAccount)
|
||||
{
|
||||
await ExecuteUIThread(() =>
|
||||
@@ -867,11 +815,12 @@ namespace Wino.Mail.ViewModels
|
||||
Type = SynchronizationType.Full,
|
||||
};
|
||||
|
||||
Messenger.Send(new NewSynchronizationRequested(options));
|
||||
Messenger.Send(new NewSynchronizationRequested(options, SynchronizationSource.Client));
|
||||
|
||||
await _nativeAppService.PinAppToTaskbarAsync();
|
||||
}
|
||||
|
||||
// TODO: Handle by messaging.
|
||||
private async Task SetAccountAttentionAsync(Guid accountId, AccountAttentionReason reason)
|
||||
{
|
||||
if (!MenuItems.TryGetAccountMenuItem(accountId, out IAccountMenuItem accountMenuItem)) return;
|
||||
@@ -913,15 +862,6 @@ namespace Wino.Mail.ViewModels
|
||||
await CreateNewMailForAsync(targetAccount);
|
||||
}
|
||||
|
||||
public async void AccountProgressUpdated(Guid accountId, int progress)
|
||||
{
|
||||
var accountMenuItem = MenuItems.GetSpecificAccountMenuItem(accountId);
|
||||
|
||||
if (accountMenuItem == null) return;
|
||||
|
||||
await ExecuteUIThread(() => { accountMenuItem.SynchronizationProgress = progress; });
|
||||
}
|
||||
|
||||
private async Task RecreateMenuItemsAsync()
|
||||
{
|
||||
await ExecuteUIThread(() =>
|
||||
@@ -1009,5 +949,14 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
UpdateFolderCollection(mailItemFolder);
|
||||
}
|
||||
|
||||
public async void Receive(AccountSynchronizationProgressUpdatedMessage message)
|
||||
{
|
||||
var accountMenuItem = MenuItems.GetSpecificAccountMenuItem(message.AccountId);
|
||||
|
||||
if (accountMenuItem == null) return;
|
||||
|
||||
await ExecuteUIThread(() => { accountMenuItem.SynchronizationProgress = message.Progress; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Requests;
|
||||
using Wino.Core.Requests;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -72,9 +71,7 @@ namespace Wino.Mail.ViewModels
|
||||
protected virtual void OnFolderRenamed(IMailItemFolder mailItemFolder) { }
|
||||
protected virtual void OnFolderSynchronizationEnabled(IMailItemFolder mailItemFolder) { }
|
||||
|
||||
public void ReportUIChange<TMessage>(TMessage message) where TMessage : class, IUIMessage
|
||||
=> Messenger.Send(message);
|
||||
|
||||
public void ReportUIChange<TMessage>(TMessage message) where TMessage : class, IUIMessage => Messenger.Send(message);
|
||||
void IRecipient<AccountCreatedMessage>.Receive(AccountCreatedMessage message) => OnAccountCreated(message.Account);
|
||||
void IRecipient<AccountRemovedMessage>.Receive(AccountRemovedMessage message) => OnAccountRemoved(message.Account);
|
||||
void IRecipient<AccountUpdatedMessage>.Receive(AccountUpdatedMessage message) => OnAccountUpdated(message.Account);
|
||||
|
||||
@@ -18,9 +18,9 @@ using Wino.Core.Domain.Models.MailItem;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Reader;
|
||||
using Wino.Core.Extensions;
|
||||
using Wino.Core.Messages.Mails;
|
||||
using Wino.Core.Services;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -171,7 +171,14 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
var assignedAccount = CurrentMailDraftItem.AssignedAccount;
|
||||
var sentFolder = await _folderService.GetSpecialFolderByAccountIdAsync(assignedAccount.Id, SpecialFolderType.Sent);
|
||||
var draftSendPreparationRequest = new SendDraftPreparationRequest(CurrentMailDraftItem.MailCopy, CurrentMimeMessage, CurrentMailDraftItem.AssignedFolder, sentFolder, CurrentMailDraftItem.AssignedAccount.Preferences);
|
||||
|
||||
using MemoryStream memoryStream = new();
|
||||
CurrentMimeMessage.WriteTo(FormatOptions.Default, memoryStream);
|
||||
byte[] buffer = memoryStream.GetBuffer();
|
||||
int count = (int)memoryStream.Length;
|
||||
|
||||
var base64EncodedMessage = Convert.ToBase64String(buffer);
|
||||
var draftSendPreparationRequest = new SendDraftPreparationRequest(CurrentMailDraftItem.MailCopy, sentFolder, CurrentMailDraftItem.AssignedFolder, CurrentMailDraftItem.AssignedAccount.Preferences, base64EncodedMessage);
|
||||
|
||||
await _worker.ExecuteAsync(draftSendPreparationRequest);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
|
||||
namespace Wino.Mail.ViewModels.Data
|
||||
{
|
||||
|
||||
@@ -24,12 +24,13 @@ using Wino.Core.Domain.Models.MailItem;
|
||||
using Wino.Core.Domain.Models.Menus;
|
||||
using Wino.Core.Domain.Models.Reader;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.Messages.Mails;
|
||||
using Wino.Core.Messages.Shell;
|
||||
using Wino.Core.Messages.Synchronization;
|
||||
using Wino.Mail.ViewModels.Collections;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Mail.ViewModels.Messages;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
using Wino.Messaging.Client.Shell;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -72,12 +73,11 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
private readonly IMailService _mailService;
|
||||
private readonly IFolderService _folderService;
|
||||
private readonly IWinoSynchronizerFactory _winoSynchronizerFactory;
|
||||
private readonly IThreadingStrategyProvider _threadingStrategyProvider;
|
||||
private readonly IContextMenuItemService _contextMenuItemService;
|
||||
private readonly IWinoRequestDelegator _winoRequestDelegator;
|
||||
private readonly IKeyPressService _keyPressService;
|
||||
|
||||
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
|
||||
private MailItemViewModel _activeMailItem;
|
||||
|
||||
public List<SortingOption> SortingOptions { get; } =
|
||||
@@ -143,20 +143,20 @@ namespace Wino.Mail.ViewModels
|
||||
IMailService mailService,
|
||||
IStatePersistanceService statePersistanceService,
|
||||
IFolderService folderService,
|
||||
IWinoSynchronizerFactory winoSynchronizerFactory,
|
||||
IThreadingStrategyProvider threadingStrategyProvider,
|
||||
IContextMenuItemService contextMenuItemService,
|
||||
IWinoRequestDelegator winoRequestDelegator,
|
||||
IKeyPressService keyPressService,
|
||||
IPreferencesService preferencesService) : base(dialogService)
|
||||
IPreferencesService preferencesService,
|
||||
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
|
||||
{
|
||||
PreferencesService = preferencesService;
|
||||
_winoServerConnectionManager = winoServerConnectionManager;
|
||||
StatePersistanceService = statePersistanceService;
|
||||
NavigationService = navigationService;
|
||||
|
||||
_mailService = mailService;
|
||||
_folderService = folderService;
|
||||
_winoSynchronizerFactory = winoSynchronizerFactory;
|
||||
_threadingStrategyProvider = threadingStrategyProvider;
|
||||
_contextMenuItemService = contextMenuItemService;
|
||||
_winoRequestDelegator = winoRequestDelegator;
|
||||
@@ -450,7 +450,7 @@ namespace Wino.Mail.ViewModels
|
||||
GroupedSynchronizationTrackingId = trackingSynchronizationId
|
||||
};
|
||||
|
||||
Messenger.Send(new NewSynchronizationRequested(options));
|
||||
Messenger.Send(new NewSynchronizationRequested(options, SynchronizationSource.Client));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,6 +602,8 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
base.OnMailAdded(addedMail);
|
||||
|
||||
if (addedMail.AssignedAccount == null || addedMail.AssignedFolder == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
await listManipulationSemepahore.WaitAsync();
|
||||
@@ -866,6 +868,8 @@ namespace Wino.Mail.ViewModels
|
||||
// Let awaiters know about the completion of mail init.
|
||||
message.FolderInitLoadAwaitTask?.TrySetResult(true);
|
||||
|
||||
await Task.Yield();
|
||||
|
||||
isChangingFolder = false;
|
||||
|
||||
void ResetFilters()
|
||||
@@ -914,6 +918,7 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
void IRecipient<MailItemNavigationRequested>.Receive(MailItemNavigationRequested message)
|
||||
{
|
||||
Debug.WriteLine($"Mail item navigation requested");
|
||||
// Find mail item and add to selected items.
|
||||
|
||||
MailItemViewModel navigatingMailItem = null;
|
||||
@@ -975,13 +980,9 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
foreach (var accountId in accountIds)
|
||||
{
|
||||
var synchronizer = _winoSynchronizerFactory.GetAccountSynchronizer(accountId);
|
||||
var serverResponse = await _winoServerConnectionManager.GetResponseAsync<bool, SynchronizationExistenceCheckRequest>(new SynchronizationExistenceCheckRequest(accountId));
|
||||
|
||||
if (synchronizer == null) continue;
|
||||
|
||||
bool isAccountSynchronizing = synchronizer.State != AccountSynchronizerState.Idle;
|
||||
|
||||
if (isAccountSynchronizing)
|
||||
if (serverResponse.IsSuccess && serverResponse.Data == true)
|
||||
{
|
||||
isAnyAccountSynchronizing = true;
|
||||
break;
|
||||
|
||||
@@ -21,10 +21,11 @@ using Wino.Core.Domain.Models.Menus;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Models.Reader;
|
||||
using Wino.Core.Extensions;
|
||||
using Wino.Core.Messages.Mails;
|
||||
using Wino.Core.Services;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Mail.ViewModels.Messages;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
using Wino.Messaging.Server;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -37,11 +38,10 @@ namespace Wino.Mail.ViewModels
|
||||
private readonly IMimeFileService _mimeFileService;
|
||||
private readonly Core.Domain.Interfaces.IMailService _mailService;
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IWinoSynchronizerFactory _winoSynchronizerFactory;
|
||||
private readonly IWinoRequestDelegator _requestDelegator;
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private readonly IUnsubscriptionService _unsubscriptionService;
|
||||
|
||||
private readonly IWinoServerConnectionManager _winoServerConnectionManager;
|
||||
private bool forceImageLoading = false;
|
||||
|
||||
private MailItemViewModel initializedMailItemViewModel = null;
|
||||
@@ -81,6 +81,8 @@ namespace Wino.Mail.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasMultipleAttachments => Attachments.Count > 1;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(ShouldDisplayDownloadProgress))]
|
||||
private bool isIndetermineProgress;
|
||||
@@ -124,24 +126,23 @@ namespace Wino.Mail.ViewModels
|
||||
IMimeFileService mimeFileService,
|
||||
Core.Domain.Interfaces.IMailService mailService,
|
||||
IFileService fileService,
|
||||
IWinoSynchronizerFactory winoSynchronizerFactory,
|
||||
IWinoRequestDelegator requestDelegator,
|
||||
IStatePersistanceService statePersistanceService,
|
||||
IClipboardService clipboardService,
|
||||
IUnsubscriptionService unsubscriptionService,
|
||||
IPreferencesService preferencesService) : base(dialogService)
|
||||
IPreferencesService preferencesService,
|
||||
IWinoServerConnectionManager winoServerConnectionManager) : base(dialogService)
|
||||
{
|
||||
NativeAppService = nativeAppService;
|
||||
StatePersistanceService = statePersistanceService;
|
||||
PreferencesService = preferencesService;
|
||||
|
||||
_winoServerConnectionManager = winoServerConnectionManager;
|
||||
_clipboardService = clipboardService;
|
||||
_unsubscriptionService = unsubscriptionService;
|
||||
_underlyingThemeService = underlyingThemeService;
|
||||
_mimeFileService = mimeFileService;
|
||||
_mailService = mailService;
|
||||
_fileService = fileService;
|
||||
_winoSynchronizerFactory = winoSynchronizerFactory;
|
||||
_requestDelegator = requestDelegator;
|
||||
}
|
||||
|
||||
@@ -168,10 +169,7 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
if (initializedMailItemViewModel == null && initializedMimeMessageInformation == null) return;
|
||||
|
||||
if (initializedMailItemViewModel != null)
|
||||
await RenderAsync(initializedMimeMessageInformation);
|
||||
else
|
||||
await RenderAsync(initializedMimeMessageInformation);
|
||||
await RenderAsync(initializedMimeMessageInformation);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -272,14 +270,16 @@ namespace Wino.Mail.ViewModels
|
||||
draftOptions.ReferenceMailCopy = initializedMailItemViewModel.MailCopy;
|
||||
draftOptions.ReferenceMimeMessage = initializedMimeMessageInformation.MimeMessage;
|
||||
|
||||
var createdMimeMessage = await _mailService.CreateDraftMimeMessageAsync(initializedMailItemViewModel.AssignedAccount.Id, draftOptions).ConfigureAwait(false);
|
||||
var createdMimeMessage = await _mailService.CreateDraftMimeBase64Async(initializedMailItemViewModel.AssignedAccount.Id, draftOptions).ConfigureAwait(false);
|
||||
|
||||
var createdDraftMailMessage = await _mailService.CreateDraftAsync(initializedMailItemViewModel.AssignedAccount,
|
||||
createdMimeMessage,
|
||||
initializedMimeMessageInformation.MimeMessage,
|
||||
initializedMailItemViewModel).ConfigureAwait(false);
|
||||
|
||||
var draftPreperationRequest = new DraftPreperationRequest(initializedMailItemViewModel.AssignedAccount, createdDraftMailMessage, createdMimeMessage)
|
||||
var draftPreperationRequest = new DraftPreperationRequest(initializedMailItemViewModel.AssignedAccount,
|
||||
createdDraftMailMessage,
|
||||
createdMimeMessage)
|
||||
{
|
||||
ReferenceMimeMessage = initializedMimeMessageInformation.MimeMessage,
|
||||
ReferenceMailCopy = initializedMailItemViewModel.MailCopy
|
||||
@@ -302,6 +302,9 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
base.OnNavigatedTo(mode, parameters);
|
||||
|
||||
Attachments.CollectionChanged -= AttachmentsUpdated;
|
||||
Attachments.CollectionChanged += AttachmentsUpdated;
|
||||
|
||||
renderCancellationTokenSource.Cancel();
|
||||
|
||||
initializedMailItemViewModel = null;
|
||||
@@ -344,17 +347,20 @@ namespace Wino.Mail.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private async void AttachmentsUpdated(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
await ExecuteUIThread(() => { OnPropertyChanged(nameof(HasMultipleAttachments)); });
|
||||
}
|
||||
|
||||
private async Task HandleSingleItemDownloadAsync(MailItemViewModel mailItemViewModel)
|
||||
{
|
||||
var synchronizer = _winoSynchronizerFactory.GetAccountSynchronizer(mailItemViewModel.AssignedAccount.Id);
|
||||
|
||||
try
|
||||
{
|
||||
// To show the progress on the UI.
|
||||
CurrentDownloadPercentage = 1;
|
||||
|
||||
await synchronizer.DownloadMissingMimeMessageAsync(mailItemViewModel.MailCopy, this, renderCancellationTokenSource.Token);
|
||||
var package = new DownloadMissingMessageRequested(mailItemViewModel.AssignedAccount.Id, mailItemViewModel.MailCopy);
|
||||
await _winoServerConnectionManager.GetResponseAsync<bool, DownloadMissingMessageRequested>(package);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -455,6 +461,8 @@ namespace Wino.Mail.ViewModels
|
||||
{
|
||||
base.OnNavigatedFrom(mode, parameters);
|
||||
|
||||
Attachments.CollectionChanged -= AttachmentsUpdated;
|
||||
|
||||
renderCancellationTokenSource.Cancel();
|
||||
CurrentDownloadPercentage = 0d;
|
||||
|
||||
@@ -634,6 +642,32 @@ namespace Wino.Mail.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task SaveAllAttachmentsAsync()
|
||||
{
|
||||
var pickedPath = await DialogService.PickWindowsFolderAsync();
|
||||
|
||||
if (string.IsNullOrEmpty(pickedPath)) return;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
foreach (var attachmentViewModel in Attachments)
|
||||
{
|
||||
await SaveAttachmentInternalAsync(attachmentViewModel, pickedPath);
|
||||
}
|
||||
|
||||
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveSuccessTitle, Translator.Info_AttachmentSaveSuccessMessage, InfoBarMessageType.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, WinoErrors.SaveAttachment);
|
||||
Crashes.TrackError(ex);
|
||||
|
||||
DialogService.InfoBarMessage(Translator.Info_AttachmentSaveFailedTitle, Translator.Info_AttachmentSaveFailedMessage, InfoBarMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns created file path.
|
||||
private async Task<string> SaveAttachmentInternalAsync(MailAttachmentViewModel attachmentViewModel, string saveFolderPath)
|
||||
{
|
||||
@@ -666,6 +700,23 @@ namespace Wino.Mail.ViewModels
|
||||
// For upload.
|
||||
void ITransferProgress.Report(long bytesTransferred) { }
|
||||
|
||||
public async void Receive(NewMailItemRenderingRequestedEvent message) => await RenderAsync(message.MailItemViewModel, renderCancellationTokenSource.Token);
|
||||
public async void Receive(NewMailItemRenderingRequestedEvent message)
|
||||
{
|
||||
try
|
||||
{
|
||||
await RenderAsync(message.MailItemViewModel, renderCancellationTokenSource.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Log.Information("Canceled mail rendering.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DialogService.InfoBarMessage(Translator.Info_MailRenderingFailedTitle, string.Format(Translator.Info_MailRenderingFailedMessage, ex.Message), InfoBarMessageType.Error);
|
||||
|
||||
Crashes.TrackError(ex);
|
||||
Log.Error(ex, "Render Failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Core.Requests;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
|
||||
@@ -4,8 +4,7 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
|
||||
namespace Wino.Mail.ViewModels
|
||||
{
|
||||
@@ -26,6 +25,7 @@ namespace Wino.Mail.ViewModels
|
||||
WinoPage.MessageListPage => Translator.SettingsMessageList_Title,
|
||||
WinoPage.ReadComposePanePage => Translator.SettingsReadComposePane_Title,
|
||||
WinoPage.LanguageTimePage => Translator.SettingsLanguageTime_Title,
|
||||
WinoPage.AppPreferencesPage => Translator.SettingsAppPreferences_Title,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -17,6 +18,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.csproj" />
|
||||
<ProjectReference Include="..\Wino.Core\Wino.Core.csproj" />
|
||||
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user