2024-04-18 01:44:37 +02:00
|
|
|
|
using System;
|
2024-06-17 02:16:06 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
2024-06-17 02:16:06 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
2024-06-17 02:16:06 +02:00
|
|
|
|
using Wino.Core.Domain;
|
2024-11-10 23:28:25 +01:00
|
|
|
|
using Wino.Core.Domain.Entities.Shared;
|
2024-06-17 02:16:06 +02:00
|
|
|
|
using Wino.Core.Domain.Exceptions;
|
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
2025-02-15 12:53:32 +01:00
|
|
|
|
using Wino.Core.Domain.Models.Accounts;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Wino.Core.Domain.Models.AutoDiscovery;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
using Wino.Messaging.Client.Mails;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Wino.Views.ImapSetup
|
|
|
|
|
|
{
|
|
|
|
|
|
public sealed partial class WelcomeImapSetupPage : Page
|
|
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
private readonly IAutoDiscoveryService _autoDiscoveryService = App.Current.Services.GetService<IAutoDiscoveryService>();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
public WelcomeImapSetupPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
base.OnNavigatedTo(e);
|
|
|
|
|
|
|
|
|
|
|
|
AutoDiscoveryPanel.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
MainSetupPanel.Visibility = Visibility.Visible;
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Parameter is MailAccount accountProperties)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayNameBox.Text = accountProperties.Name;
|
|
|
|
|
|
}
|
2025-02-15 12:53:32 +01:00
|
|
|
|
else if (e.Parameter is AccountCreationDialogResult creationDialogResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupNavigationRequested(typeof(TestingImapConnectionPage), creationDialogResult));
|
|
|
|
|
|
}
|
2024-06-17 02:16:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void SignInClicked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
MainSetupPanel.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
AutoDiscoveryPanel.Visibility = Visibility.Visible;
|
|
|
|
|
|
|
|
|
|
|
|
// Let users see the discovery message for a while...
|
|
|
|
|
|
|
|
|
|
|
|
await Task.Delay(1000);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
var minimalSettings = new AutoDiscoveryMinimalSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
Password = PasswordBox.Password,
|
|
|
|
|
|
DisplayName = DisplayNameBox.Text,
|
|
|
|
|
|
Email = AddressBox.Text,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
var discoverySettings = await _autoDiscoveryService.GetAutoDiscoverySettings(minimalSettings);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
if (discoverySettings == null)
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
// Couldn't find settings.
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-09-14 21:51:43 +02:00
|
|
|
|
var failurePackage = new ImapConnectionFailedPackage(Translator.Exception_ImapAutoDiscoveryFailed, string.Empty, discoverySettings);
|
2024-06-17 02:16:06 +02:00
|
|
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupBackNavigationRequested(typeof(ImapConnectionFailedPage), failurePackage));
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
2024-06-17 02:16:06 +02:00
|
|
|
|
else
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
// Settings are found. Test the connection with the given password.
|
|
|
|
|
|
|
|
|
|
|
|
discoverySettings.UserMinimalSettings = minimalSettings;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupNavigationRequested(typeof(TestingImapConnectionPage), discoverySettings));
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
private void CancelClicked(object sender, RoutedEventArgs e) => WeakReferenceMessenger.Default.Send(new ImapSetupDismissRequested());
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
private void AdvancedConfigurationClicked(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var latestMinimalSettings = new AutoDiscoveryMinimalSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayName = DisplayNameBox.Text,
|
|
|
|
|
|
Password = PasswordBox.Password,
|
|
|
|
|
|
Email = AddressBox.Text
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-21 02:58:12 +02:00
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupNavigationRequested(typeof(AdvancedImapSetupPage), latestMinimalSettings));
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|