Files
Wino-Mail/Wino.Mail/Views/ImapSetup/WelcomeImapSetupPage.xaml.cs
T

96 lines
3.2 KiB
C#
Raw Normal View History

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