Revert everything back. Mission failed.

This commit is contained in:
Burak Kaan Köse
2024-07-20 04:16:45 +02:00
parent e04c17d591
commit 2d6155ae6f
381 changed files with 3246 additions and 292 deletions

View File

@@ -0,0 +1,30 @@
using System.Linq;
using Wino.Core.Domain.Interfaces;
#if NET8_0
using Microsoft.UI.Xaml;
#else
using Windows.UI.Xaml;
#endif
namespace Wino.Services
{
public class ApplicationResourceManager : IApplicationResourceManager<ResourceDictionary>
{
public void AddResource(ResourceDictionary resource)
=> App.Current.Resources.MergedDictionaries.Add(resource);
public void RemoveResource(ResourceDictionary resource)
=> App.Current.Resources.MergedDictionaries.Remove(resource);
public bool ContainsResourceKey(string resourceKey)
=> App.Current.Resources.ContainsKey(resourceKey);
public ResourceDictionary GetLastResource()
=> App.Current.Resources.MergedDictionaries.LastOrDefault();
public void ReplaceResource(string resourceKey, object resource)
=> App.Current.Resources[resourceKey] = resource;
public TReturn GetResource<TReturn>(string resourceKey)
=> (TReturn)App.Current.Resources[resourceKey];
}
}

View File

@@ -0,0 +1,399 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Serilog;
using Windows.Storage;
using Windows.Storage.Pickers;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models.Synchronization;
using Wino.Core.Messages.Shell;
using Wino.Core.Messages.Synchronization;
using Wino.Core.UWP.Extensions;
using Wino.Dialogs;
using Wino.Helpers;
using Wino.Core.WinUI.Services;
using Wino.Messaging.Server;
using Windows.Foundation.Metadata;
#if NET8_0
using Microsoft.UI.Xaml.Controls;
#else
using Windows.UI.Xaml.Controls;
#endif
namespace Wino.Services
{
public class DialogService : IDialogService
{
private SemaphoreSlim _presentationSemaphore = new SemaphoreSlim(1);
private readonly IThemeService _themeService;
private readonly IAppShellService _appShellService;
public DialogService(IThemeService themeService, IAppShellService appShellService)
{
_themeService = themeService;
_appShellService = appShellService;
}
public void ShowNotSupportedMessage()
{
InfoBarMessage(Translator.Info_UnsupportedFunctionalityTitle, Translator.Info_UnsupportedFunctionalityDescription, InfoBarMessageType.Error);
}
public async Task ShowMessageAsync(string message, string title)
{
var dialog = new WinoMessageDialog()
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
AssignXamlRoot(dialog);
await HandleDialogPresentation(() => dialog.ShowDialogAsync(title, message));
}
private void AssignXamlRoot(ContentDialog dialog)
{
#if NET8_0
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
{
dialog.XamlRoot = (_appShellService.AppWindow.Content).XamlRoot;
}
#endif
}
/// <summary>
/// Waits for PopupRoot to be available before presenting the dialog and returns the result after presentation.
/// </summary>
/// <param name="dialog">Dialog to present and wait for closing.</param>
/// <returns>Dialog result from WinRT.</returns>
private async Task<ContentDialogResult> HandleDialogPresentationAsync(ContentDialog dialog)
{
await _presentationSemaphore.WaitAsync();
try
{
AssignXamlRoot(dialog);
return await dialog.ShowAsync();
}
catch (Exception ex)
{
Log.Error(ex, $"Handling dialog service failed. Dialog was {dialog.GetType().Name}");
}
finally
{
_presentationSemaphore.Release();
}
return ContentDialogResult.None;
}
/// <summary>
/// Waits for PopupRoot to be available before executing the given Task that returns customized result.
/// </summary>
/// <param name="executionTask">Task that presents the dialog and returns result.</param>
/// <returns>Dialog result from the custom dialog.</returns>
private async Task<bool> HandleDialogPresentation(Func<Task<bool>> executionTask)
{
await _presentationSemaphore.WaitAsync();
try
{
return await executionTask();
}
catch (Exception ex)
{
Log.Error(ex, "Handling dialog service failed.");
}
finally
{
_presentationSemaphore.Release();
}
return false;
}
public async Task<bool> ShowConfirmationDialogAsync(string question, string title, string confirmationButtonTitle)
{
var dialog = new ConfirmationDialog()
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
AssignXamlRoot(dialog);
return await HandleDialogPresentation(() => dialog.ShowDialogAsync(title, question, confirmationButtonTitle));
}
public async Task<AccountCreationDialogResult> ShowNewAccountMailProviderDialogAsync(List<IProviderDetail> availableProviders)
{
var dialog = new NewAccountDialog
{
Providers = availableProviders,
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(dialog);
return dialog.Result;
}
public IAccountCreationDialog GetAccountCreationDialog(MailProviderType type)
{
IAccountCreationDialog dialog = null;
if (type == MailProviderType.IMAP4)
{
dialog = new NewImapSetupDialog
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
}
else
{
dialog = new AccountCreationDialog
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
}
AssignXamlRoot(dialog as ContentDialog);
return dialog;
}
public void InfoBarMessage(string title, string message, InfoBarMessageType messageType)
=> WeakReferenceMessenger.Default.Send(new InfoBarMessageRequested(messageType, title, message));
public void InfoBarMessage(string title, string message, InfoBarMessageType messageType, string actionButtonText, Action action)
=> WeakReferenceMessenger.Default.Send(new InfoBarMessageRequested(messageType, title, message, actionButtonText, action));
public async Task<string> ShowTextInputDialogAsync(string currentInput, string dialogTitle, string dialogDescription, string primaryButtonText)
{
var inputDialog = new TextInputDialog()
{
CurrentInput = currentInput,
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme(),
Title = dialogTitle
};
inputDialog.SetDescription(dialogDescription);
inputDialog.SetPrimaryButtonText(primaryButtonText);
await HandleDialogPresentationAsync(inputDialog);
if (inputDialog.HasInput.GetValueOrDefault() && !currentInput.Equals(inputDialog.CurrentInput))
return inputDialog.CurrentInput;
return string.Empty;
}
public async Task<string> PickWindowsFolderAsync()
{
var picker = new FolderPicker
{
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
};
picker.FileTypeFilter.Add("*");
var pickedFolder = await picker.PickSingleFolderAsync();
if (pickedFolder != null)
{
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("FolderPickerToken", pickedFolder);
return pickedFolder.Path;
}
return string.Empty;
}
public async Task<MailAccount> ShowEditAccountDialogAsync(MailAccount account)
{
var editAccountDialog = new AccountEditDialog(account)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(editAccountDialog);
return editAccountDialog.IsSaved ? editAccountDialog.Account : null;
}
public async Task<IStoreRatingDialog> ShowRatingDialogAsync()
{
var storeDialog = new StoreRatingDialog()
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(storeDialog);
return storeDialog;
}
public async Task HandleSystemFolderConfigurationDialogAsync(Guid accountId, IFolderService folderService)
{
try
{
var configurableFolder = await folderService.GetFoldersAsync(accountId);
var systemFolderConfigurationDialog = new SystemFolderConfigurationDialog(configurableFolder)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(systemFolderConfigurationDialog);
var configuration = systemFolderConfigurationDialog.Configuration;
if (configuration != null)
{
var updatedAccount = await folderService.UpdateSystemFolderConfigurationAsync(accountId, configuration);
// Update account menu item and force re-synchronization.
WeakReferenceMessenger.Default.Send(new AccountUpdatedMessage(updatedAccount));
var options = new SynchronizationOptions()
{
AccountId = updatedAccount.Id,
Type = SynchronizationType.Full,
};
WeakReferenceMessenger.Default.Send(new NewSynchronizationRequested(options));
}
if (configuration != null)
{
InfoBarMessage(Translator.SystemFolderConfigSetupSuccess_Title, Translator.SystemFolderConfigSetupSuccess_Message, InfoBarMessageType.Success);
}
}
catch (Exception ex)
{
InfoBarMessage(Translator.Error_FailedToSetupSystemFolders_Title, ex.Message, InfoBarMessageType.Error);
}
}
public async Task<IMailItemFolder> ShowMoveMailFolderDialogAsync(List<IMailItemFolder> availableFolders)
{
var moveDialog = new MoveMailDialog(availableFolders)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(moveDialog);
return moveDialog.SelectedFolder;
}
public async Task<IMailItemFolder> PickFolderAsync(Guid accountId, PickFolderReason reason, IFolderService folderService)
{
var allFolders = await folderService.GetFolderStructureForAccountAsync(accountId, true);
return await ShowMoveMailFolderDialogAsync(allFolders.Folders);
}
public async Task<bool> ShowCustomThemeBuilderDialogAsync()
{
var themeBuilderDialog = new CustomThemeBuilderDialog()
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
var dialogResult = await HandleDialogPresentationAsync(themeBuilderDialog);
return dialogResult == ContentDialogResult.Primary;
}
private async Task<StorageFile> PickFileAsync(params object[] typeFilters)
{
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail
};
foreach (var filter in typeFilters)
{
picker.FileTypeFilter.Add(filter.ToString());
}
var file = await picker.PickSingleFileAsync();
if (file == null) return null;
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("FilePickerPath", file);
return file;
}
public async Task<byte[]> PickWindowsFileContentAsync(params object[] typeFilters)
{
var file = await PickFileAsync(typeFilters);
if (file == null) return Array.Empty<byte>();
return await file.ReadBytesAsync();
}
public Task<bool> ShowHardDeleteConfirmationAsync() => ShowConfirmationDialogAsync(Translator.DialogMessage_HardDeleteConfirmationMessage, Translator.DialogMessage_HardDeleteConfirmationTitle, Translator.Buttons_Yes);
public async Task<MailAccount> ShowAccountPickerDialogAsync(List<MailAccount> availableAccounts)
{
var accountPicker = new AccountPickerDialog(availableAccounts)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(accountPicker);
return accountPicker.PickedAccount;
}
public async Task<AccountSignature> ShowSignatureEditorDialog(AccountSignature signatureModel = null)
{
SignatureEditorDialog signatureEditorDialog;
if (signatureModel != null)
{
signatureEditorDialog = new SignatureEditorDialog(signatureModel)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
}
else
{
signatureEditorDialog = new SignatureEditorDialog()
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
}
var result = await HandleDialogPresentationAsync(signatureEditorDialog);
return result == ContentDialogResult.Primary ? signatureEditorDialog.Result : null;
}
public async Task ShowAccountReorderDialogAsync(ObservableCollection<IAccountProviderDetailViewModel> availableAccounts)
{
var accountReorderDialog = new AccountReorderDialog(availableAccounts)
{
RequestedTheme = _themeService.RootTheme.ToWindowsElementTheme()
};
await HandleDialogPresentationAsync(accountReorderDialog);
}
}
}

View File

@@ -0,0 +1,11 @@
using System.Collections.Specialized;
using Wino.Core.Domain.Interfaces;
namespace Wino.Services
{
public class LaunchProtocolService : ILaunchProtocolService
{
public object LaunchParameter { get; set; }
public NameValueCollection MailtoParameters { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using Wino.Core.Domain.Interfaces;
namespace Wino.Services
{
public class ToastActivationService
{
private readonly IMailService _mailService;
private readonly IWinoRequestDelegator _winoRequestDelegator;
private readonly INativeAppService _nativeAppService;
public ToastActivationService(IMailService mailService,
IWinoRequestDelegator winoRequestDelegator,
INativeAppService nativeAppService)
{
_mailService = mailService;
_winoRequestDelegator = winoRequestDelegator;
_nativeAppService = nativeAppService;
}
}
}

View File

@@ -0,0 +1,198 @@
using System;
using System.Linq;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.Domain.Models.Navigation;
using Wino.Helpers;
using Wino.Mail.ViewModels.Data;
using Wino.Mail.ViewModels.Messages;
using Wino.Views;
using Wino.Views.Account;
using Wino.Views.Settings;
using Wino.Core.WinUI.Services;
#if NET8_0
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
#endif
namespace Wino.Services
{
public class WinoNavigationService : IWinoNavigationService
{
private readonly IStatePersistanceService _statePersistanceService;
private readonly IAppShellService _appShellService;
private WinoPage[] _renderingPageTypes = new WinoPage[]
{
WinoPage.MailRenderingPage,
WinoPage.ComposePage
};
private Frame GetCoreFrame(NavigationReferenceFrame frameType)
{
if (_appShellService.AppWindow.Content is Frame appFrame && appFrame.Content is AppShell shellPage)
return WinoVisualTreeHelper.GetChildObject<Frame>(shellPage, frameType.ToString());
return null;
}
private Type GetCurrentFrameType(ref Frame _frame)
{
if (_frame != null && _frame.Content != null)
return _frame.Content.GetType();
else
{
return null;
}
}
public WinoNavigationService(IStatePersistanceService statePersistanceService, IAppShellService appShellService)
{
_statePersistanceService = statePersistanceService;
_appShellService = appShellService;
}
private Type GetPageType(WinoPage winoPage)
{
switch (winoPage)
{
case WinoPage.None:
return null;
case WinoPage.IdlePage:
return typeof(IdlePage);
case WinoPage.AccountDetailsPage:
return typeof(AccountDetailsPage);
case WinoPage.MergedAccountDetailsPage:
return typeof(MergedAccountDetailsPage);
case WinoPage.AccountManagementPage:
return typeof(NewAccountManagementPage);
case WinoPage.SignatureManagementPage:
return typeof(SignatureManagementPage);
case WinoPage.AboutPage:
return typeof(AboutPage);
case WinoPage.PersonalizationPage:
return typeof(PersonalizationPage);
case WinoPage.MessageListPage:
return typeof(MessageListPage);
case WinoPage.ReadingPanePage:
return typeof(ReadingPanePage);
case WinoPage.MailRenderingPage:
return typeof(MailRenderingPage);
case WinoPage.ComposePage:
return typeof(ComposePage);
case WinoPage.MailListPage:
return typeof(MailListPage);
case WinoPage.SettingsPage:
return typeof(SettingsPage);
case WinoPage.WelcomePage:
return typeof(WelcomePage);
case WinoPage.SettingOptionsPage:
return typeof(SettingOptionsPage);
default:
return null;
}
}
public bool Navigate(WinoPage page,
object parameter = null,
NavigationReferenceFrame frame = NavigationReferenceFrame.ShellFrame,
NavigationTransitionType transition = NavigationTransitionType.None)
{
var pageType = GetPageType(page);
Frame shellFrame = GetCoreFrame(NavigationReferenceFrame.ShellFrame);
_statePersistanceService.IsReadingMail = _renderingPageTypes.Contains(page);
if (shellFrame != null)
{
var currentFrameType = GetCurrentFrameType(ref shellFrame);
bool isMailListingPageActive = currentFrameType != null && currentFrameType == typeof(MailListPage);
// Active page is mail list page and we are refreshing the folder.
if (isMailListingPageActive && currentFrameType == pageType && parameter is NavigateMailFolderEventArgs folderNavigationArgs)
{
// No need for new navigation, just refresh the folder.
WeakReferenceMessenger.Default.Send(new ActiveMailFolderChangedEvent(folderNavigationArgs.BaseFolderMenuItem, folderNavigationArgs.FolderInitLoadAwaitTask));
return true;
}
var transitionInfo = GetNavigationTransitionInfo(transition);
// This page must be opened in the Frame placed in MailListingPage.
if (isMailListingPageActive && frame == NavigationReferenceFrame.RenderingFrame)
{
var listingFrame = GetCoreFrame(NavigationReferenceFrame.RenderingFrame);
if (listingFrame == null) return false;
// Active page is mail list page and we are opening a mail item.
// No navigation needed, just refresh the rendered mail item.
if (listingFrame.Content != null
&& listingFrame.Content.GetType() == GetPageType(WinoPage.MailRenderingPage)
&& parameter is MailItemViewModel mailItemViewModel
&& page != WinoPage.ComposePage)
{
WeakReferenceMessenger.Default.Send(new NewMailItemRenderingRequestedEvent(mailItemViewModel));
}
else
{
listingFrame.Navigate(pageType, parameter, transitionInfo);
}
return true;
}
if ((currentFrameType != null && currentFrameType != pageType) || currentFrameType == null)
{
return shellFrame.Navigate(pageType, parameter, transitionInfo);
}
}
return false;
}
private NavigationTransitionInfo GetNavigationTransitionInfo(NavigationTransitionType transition)
{
return transition switch
{
NavigationTransitionType.DrillIn => new DrillInNavigationTransitionInfo(),
_ => new SuppressNavigationTransitionInfo(),
};
}
public void NavigateCompose(IMailItem mailItem, NavigationTransitionType transition = NavigationTransitionType.None)
=> Navigate(WinoPage.ComposePage, mailItem, NavigationReferenceFrame.RenderingFrame, transition);
// Standalone EML viewer.
public void NavigateRendering(MimeMessageInformation mimeMessageInformation, NavigationTransitionType transition = NavigationTransitionType.None)
{
if (mimeMessageInformation == null)
throw new ArgumentException("MimeMessage cannot be null.");
Navigate(WinoPage.MailRenderingPage, mimeMessageInformation, NavigationReferenceFrame.RenderingFrame, transition);
}
// Mail item view model clicked handler.
public void NavigateRendering(IMailItem mailItem, NavigationTransitionType transition = NavigationTransitionType.None)
{
if (mailItem is MailItemViewModel mailItemViewModel)
Navigate(WinoPage.MailRenderingPage, mailItemViewModel, NavigationReferenceFrame.RenderingFrame, transition);
else
throw new ArgumentException("MailItem must be of type MailItemViewModel.");
}
public void NavigateFolder(NavigateMailFolderEventArgs args)
=> Navigate(WinoPage.MailListPage, args, NavigationReferenceFrame.ShellFrame);
}
}