iCloud special imap handling.

This commit is contained in:
Burak Kaan Köse
2025-01-21 23:57:58 +01:00
parent 05280dfd42
commit 20010e77ae
21 changed files with 433 additions and 250 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,76 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Messaging.UI;
namespace Wino.Core.UWP.Controls
{
public sealed partial class AccountCreationDialogControl : UserControl, IRecipient<CopyAuthURLRequested>
{
private string copyClipboardURL;
public event EventHandler CancelClicked;
public AccountCreationDialogState State
{
get { return (AccountCreationDialogState)GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(AccountCreationDialogControl), new PropertyMetadata(AccountCreationDialogState.Idle, new PropertyChangedCallback(OnStateChanged)));
public AccountCreationDialogControl()
{
InitializeComponent();
}
private static void OnStateChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is AccountCreationDialogControl dialog)
{
dialog.UpdateVisualStates();
}
}
private void UpdateVisualStates() => VisualStateManager.GoToState(this, State.ToString(), false);
public async void Receive(CopyAuthURLRequested message)
{
copyClipboardURL = message.AuthURL;
await Task.Delay(2000);
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
AuthHelpDialogButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
});
}
private void ControlLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
WeakReferenceMessenger.Default.Register(this);
}
private void ControlUnloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
WeakReferenceMessenger.Default.UnregisterAll(this);
}
private async void CopyClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (string.IsNullOrEmpty(copyClipboardURL)) return;
var clipboardService = WinoApplication.Current.Services.GetService<IClipboardService>();
await clipboardService.CopyClipboardAsync(copyClipboardURL);
}
private void CancelButtonClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e) => CancelClicked?.Invoke(this, null);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,50 +1,58 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using System.Threading;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.UWP;
using Wino.Messaging.UI;
namespace Wino.Dialogs
{
public sealed partial class AccountCreationDialog : BaseAccountCreationDialog, IRecipient<CopyAuthURLRequested>
public sealed partial class AccountCreationDialog : ContentDialog, IAccountCreationDialog
{
private string copyClipboardURL;
public CancellationTokenSource CancellationTokenSource { get; private set; }
public AccountCreationDialogState State
{
get { return (AccountCreationDialogState)GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(AccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle));
public AccountCreationDialog()
{
InitializeComponent();
WeakReferenceMessenger.Default.Register(this);
}
public override void OnStateChanged(AccountCreationDialogState state)
// Prevent users from dismissing it by ESC key.
public void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
var tt = VisualStateManager.GoToState(this, state.ToString(), true);
}
public async void Receive(CopyAuthURLRequested message)
{
copyClipboardURL = message.AuthURL;
await Task.Delay(2000);
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
if (args.Result == ContentDialogResult.None)
{
AuthHelpDialogButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
});
args.Cancel = true;
}
}
private void CancelClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e) => Complete(true);
private async void CopyClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
public void ShowDialog(CancellationTokenSource cancellationTokenSource)
{
if (string.IsNullOrEmpty(copyClipboardURL)) return;
CancellationTokenSource = cancellationTokenSource;
var clipboardService = WinoApplication.Current.Services.GetService<IClipboardService>();
await clipboardService.CopyClipboardAsync(copyClipboardURL);
_ = ShowAsync();
}
public void Complete(bool cancel)
{
State = cancel ? AccountCreationDialogState.Canceled : AccountCreationDialogState.Completed;
// Unregister from closing event.
Closing -= DialogClosing;
if (cancel && !CancellationTokenSource.IsCancellationRequested)
{
CancellationTokenSource.Cancel();
}
Hide();
}
private void CancelClicked(object sender, System.EventArgs e) => Complete(true);
}
}

View File

@@ -1,60 +0,0 @@
using System.Threading;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
namespace Wino.Dialogs
{
public abstract class BaseAccountCreationDialog : ContentDialog, IAccountCreationDialog
{
public AccountCreationDialogState State
{
get { return (AccountCreationDialogState)GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
public CancellationTokenSource CancellationTokenSource { get; private set; }
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle, OnStateChanged));
private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dialog = d as BaseAccountCreationDialog;
dialog.OnStateChanged((AccountCreationDialogState)e.NewValue);
}
public abstract void OnStateChanged(AccountCreationDialogState state);
// Prevent users from dismissing it by ESC key.
public void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (args.Result == ContentDialogResult.None)
{
args.Cancel = true;
}
}
public void ShowDialog(CancellationTokenSource cancellationTokenSource)
{
CancellationTokenSource = cancellationTokenSource;
_ = ShowAsync();
}
public void Complete(bool cancel)
{
State = cancel ? AccountCreationDialogState.Canceled : AccountCreationDialogState.Completed;
// Unregister from closing event.
Closing -= DialogClosing;
if (cancel && !CancellationTokenSource.IsCancellationRequested)
{
CancellationTokenSource.Cancel();
}
Hide();
}
}
}

View File

@@ -85,6 +85,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
@@ -103,20 +104,27 @@
Source="{x:Bind SelectedMailProvider.ProviderImage, Mode=OneWay}" />
<TextBox
x:Name="SpecialImapAddress"
x:Name="DisplayNameTextBox"
Grid.Row="1"
TextChanged="InputChanged"
Header="Display Name"
PlaceholderText="eg. John Doe"
TextChanged="InputChanged" />
<TextBox
x:Name="SpecialImapAddress"
Grid.Row="2"
Header="E-mail Address"
PlaceholderText="eg. johndoe@testmail.com" />
PlaceholderText="eg. johndoe@testmail.com"
TextChanged="InputChanged" />
<PasswordBox
x:Name="AppSpecificPassword"
PasswordChanged="ImapPasswordChanged"
Grid.Row="2"
Header="App-Specific Password" />
Grid.Row="3"
Header="App-Specific Password"
PasswordChanged="ImapPasswordChanged" />
<HyperlinkButton
Grid.Row="3"
Grid.Row="4"
HorizontalAlignment="Right"
Click="AppSpecificHelpButtonClicked"
Content="How do I get app-specific password?" />

View File

@@ -21,6 +21,7 @@ namespace Wino.Core.UWP.Dialogs
public static readonly DependencyProperty IsSpecialImapServerPartVisibleProperty = DependencyProperty.Register(nameof(IsSpecialImapServerPartVisible), typeof(bool), typeof(NewAccountDialog), new PropertyMetadata(false));
public static readonly DependencyProperty SelectedMailProviderProperty = DependencyProperty.Register(nameof(SelectedMailProvider), typeof(ProviderDetail), typeof(NewAccountDialog), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedProviderChanged)));
/// <summary>
/// Gets or sets current selected mail provider in the dialog.
/// </summary>
@@ -69,6 +70,17 @@ namespace Wino.Core.UWP.Dialogs
private void CreateClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (IsSpecialImapServerPartVisible)
{
// Special imap detail input.
var details = new SpecialImapProviderDetails(SpecialImapAddress.Text.Trim(), AppSpecificPassword.Password.Trim(), DisplayNameTextBox.Text.Trim(), SelectedMailProvider.SpecialImapProvider);
Result = new AccountCreationDialogResult(SelectedMailProvider.Type, AccountNameTextbox.Text.Trim(), details);
Hide();
return;
}
Validate();
if (IsSecondaryButtonEnabled)
@@ -85,7 +97,7 @@ namespace Wino.Core.UWP.Dialogs
}
else
{
Result = new AccountCreationDialogResult(SelectedMailProvider.Type, AccountNameTextbox.Text.Trim());
Result = new AccountCreationDialogResult(SelectedMailProvider.Type, AccountNameTextbox.Text.Trim(), null);
Hide();
}
}
@@ -106,7 +118,9 @@ namespace Wino.Core.UWP.Dialogs
bool shouldEnable = SelectedMailProvider != null
&& SelectedMailProvider.IsSupported
&& !string.IsNullOrEmpty(AccountNameTextbox.Text)
&& (IsSpecialImapServerPartVisible ? (!string.IsNullOrEmpty(AppSpecificPassword.Password) && EmailValidation.EmailValidator.Validate(SpecialImapAddress.Text)) : true);
&& (IsSpecialImapServerPartVisible ? (!string.IsNullOrEmpty(AppSpecificPassword.Password)
&& !string.IsNullOrEmpty(DisplayNameTextBox.Text)
&& EmailValidation.EmailValidator.Validate(SpecialImapAddress.Text)) : true);
IsPrimaryButtonEnabled = shouldEnable;
}

View File

@@ -132,7 +132,7 @@ namespace Wino.Core.UWP.Services
return file;
}
public virtual IAccountCreationDialog GetAccountCreationDialog(MailProviderType type)
public virtual IAccountCreationDialog GetAccountCreationDialog(AccountCreationDialogResult accountCreationDialogResult)
{
return new AccountCreationDialog
{

View File

@@ -84,6 +84,9 @@
<ItemGroup>
<Compile Include="Activation\ActivationHandler.cs" />
<Compile Include="BasePage.cs" />
<Compile Include="Controls\AccountCreationDialogControl.xaml.cs">
<DependentUpon>AccountCreationDialogControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\ControlConstants.cs" />
<Compile Include="Controls\CustomWrapPanel.cs" />
<Compile Include="Controls\EqualGridPanel.cs" />
@@ -115,7 +118,6 @@
<Compile Include="Dialogs\AccountPickerDialog.xaml.cs">
<DependentUpon>AccountPickerDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\BaseAccountCreationDialog.cs" />
<Compile Include="Dialogs\CustomMessageDialogInformationContainer.cs" />
<Compile Include="Dialogs\CustomThemeBuilderDialog.xaml.cs">
<DependentUpon>CustomThemeBuilderDialog.xaml</DependentUpon>
@@ -341,6 +343,10 @@
</Content>
</ItemGroup>
<ItemGroup>
<Page Include="Controls\AccountCreationDialogControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\WinoAppTitleBar.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>