2026-03-06 03:42:08 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using Wino.Core.Domain;
|
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
using Wino.Core.Domain.Models.Navigation;
|
2026-04-19 20:13:09 +02:00
|
|
|
using Wino.Core.Domain.Validation;
|
2026-03-06 03:42:08 +01:00
|
|
|
using Wino.Mail.ViewModels.Data;
|
|
|
|
|
using Wino.Messaging.Client.Navigation;
|
|
|
|
|
|
|
|
|
|
namespace Wino.Mail.ViewModels;
|
|
|
|
|
|
|
|
|
|
public partial class SpecialImapCredentialsPageViewModel : MailBaseViewModel
|
|
|
|
|
{
|
2026-04-16 13:45:11 +02:00
|
|
|
private readonly IAccountService _accountService;
|
|
|
|
|
private readonly IDialogServiceBase _dialogService;
|
2026-03-06 03:42:08 +01:00
|
|
|
private static readonly Dictionary<SpecialImapProvider, string> AppPasswordHelpLinks = new()
|
|
|
|
|
{
|
|
|
|
|
{ SpecialImapProvider.iCloud, "https://support.apple.com/en-us/102654" },
|
|
|
|
|
{ SpecialImapProvider.Yahoo, "http://help.yahoo.com/kb/SLN15241.html" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly INativeAppService _nativeAppService;
|
|
|
|
|
|
|
|
|
|
public WelcomeWizardContext WizardContext { get; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string DisplayName { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string EmailAddress { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string AppSpecificPassword { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
2026-04-20 19:38:30 +02:00
|
|
|
[NotifyPropertyChangedFor(nameof(RequiresAppSpecificPassword))]
|
2026-03-06 03:42:08 +01:00
|
|
|
public partial int SelectedCalendarModeIndex { get; set; }
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial bool CanProceed { get; set; }
|
|
|
|
|
|
2026-04-20 19:38:30 +02:00
|
|
|
public bool IsCalendarModeSelectionVisible => WizardContext.IsCalendarAccessEnabled;
|
|
|
|
|
public bool RequiresAppSpecificPassword => WizardContext.IsMailAccessEnabled || SelectedCalendarModeIndex == 1;
|
|
|
|
|
|
2026-03-06 03:42:08 +01:00
|
|
|
public string AppPasswordHelpUrl
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (WizardContext.SelectedProvider == null) return null;
|
|
|
|
|
AppPasswordHelpLinks.TryGetValue(WizardContext.SelectedProvider.SpecialImapProvider, out var url);
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CalendarModeCalDavDescription
|
|
|
|
|
=> WizardContext.SelectedProvider?.SpecialImapProvider == SpecialImapProvider.iCloud
|
|
|
|
|
? Translator.ProviderSelection_CalendarMode_CalDavDescription_Apple
|
|
|
|
|
: Translator.ProviderSelection_CalendarMode_CalDavDescription_Yahoo;
|
|
|
|
|
|
|
|
|
|
public SpecialImapCredentialsPageViewModel(
|
2026-04-16 13:45:11 +02:00
|
|
|
IAccountService accountService,
|
|
|
|
|
IDialogServiceBase dialogService,
|
2026-03-06 03:42:08 +01:00
|
|
|
INativeAppService nativeAppService,
|
|
|
|
|
WelcomeWizardContext wizardContext)
|
|
|
|
|
{
|
2026-04-16 13:45:11 +02:00
|
|
|
_accountService = accountService;
|
|
|
|
|
_dialogService = dialogService;
|
2026-03-06 03:42:08 +01:00
|
|
|
_nativeAppService = nativeAppService;
|
|
|
|
|
WizardContext = wizardContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnNavigatedTo(NavigationMode mode, object parameters)
|
|
|
|
|
{
|
|
|
|
|
base.OnNavigatedTo(mode, parameters);
|
|
|
|
|
|
|
|
|
|
// Restore from context when navigating back
|
|
|
|
|
DisplayName = WizardContext.DisplayName;
|
|
|
|
|
EmailAddress = WizardContext.EmailAddress;
|
|
|
|
|
AppSpecificPassword = WizardContext.AppSpecificPassword;
|
|
|
|
|
|
|
|
|
|
SelectedCalendarModeIndex = WizardContext.CalendarSupportMode switch
|
|
|
|
|
{
|
|
|
|
|
ImapCalendarSupportMode.CalDav => 1,
|
|
|
|
|
ImapCalendarSupportMode.LocalOnly => 2,
|
|
|
|
|
_ => 0
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-20 19:38:30 +02:00
|
|
|
if (!WizardContext.IsCalendarAccessEnabled)
|
|
|
|
|
{
|
|
|
|
|
SelectedCalendarModeIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 03:42:08 +01:00
|
|
|
OnPropertyChanged(nameof(AppPasswordHelpUrl));
|
|
|
|
|
OnPropertyChanged(nameof(CalendarModeCalDavDescription));
|
2026-04-20 19:38:30 +02:00
|
|
|
OnPropertyChanged(nameof(IsCalendarModeSelectionVisible));
|
|
|
|
|
OnPropertyChanged(nameof(RequiresAppSpecificPassword));
|
2026-03-06 03:42:08 +01:00
|
|
|
|
|
|
|
|
Validate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnDisplayNameChanged(string value) => Validate();
|
|
|
|
|
partial void OnEmailAddressChanged(string value) => Validate();
|
|
|
|
|
partial void OnAppSpecificPasswordChanged(string value) => Validate();
|
2026-04-20 19:38:30 +02:00
|
|
|
partial void OnSelectedCalendarModeIndexChanged(int value)
|
|
|
|
|
{
|
|
|
|
|
OnPropertyChanged(nameof(RequiresAppSpecificPassword));
|
|
|
|
|
Validate();
|
|
|
|
|
}
|
2026-03-06 03:42:08 +01:00
|
|
|
|
|
|
|
|
private void Validate()
|
|
|
|
|
{
|
|
|
|
|
CanProceed = !string.IsNullOrWhiteSpace(DisplayName)
|
|
|
|
|
&& !string.IsNullOrWhiteSpace(EmailAddress)
|
2026-04-19 20:13:09 +02:00
|
|
|
&& MailAccountAddressValidator.IsValid(EmailAddress)
|
2026-04-20 19:38:30 +02:00
|
|
|
&& (!RequiresAppSpecificPassword || !string.IsNullOrWhiteSpace(AppSpecificPassword));
|
2026-03-06 03:42:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
2026-04-16 13:45:11 +02:00
|
|
|
private async Task ProceedAsync()
|
2026-03-06 03:42:08 +01:00
|
|
|
{
|
|
|
|
|
if (!CanProceed) return;
|
|
|
|
|
|
2026-04-22 09:55:13 +02:00
|
|
|
if (await _accountService.AccountAddressExistsAsync(EmailAddress))
|
2026-04-16 13:45:11 +02:00
|
|
|
{
|
|
|
|
|
await _dialogService.ShowMessageAsync(
|
|
|
|
|
Translator.DialogMessage_AccountAddressExistsMessage,
|
|
|
|
|
Translator.DialogMessage_AccountExistsTitle,
|
|
|
|
|
WinoCustomMessageDialogIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 03:42:08 +01:00
|
|
|
WizardContext.DisplayName = DisplayName?.Trim();
|
|
|
|
|
WizardContext.EmailAddress = EmailAddress?.Trim();
|
|
|
|
|
WizardContext.AppSpecificPassword = AppSpecificPassword?.Trim();
|
2026-04-20 19:38:30 +02:00
|
|
|
WizardContext.CalendarSupportMode = WizardContext.IsCalendarAccessEnabled
|
|
|
|
|
? SelectedCalendarModeIndex switch
|
|
|
|
|
{
|
|
|
|
|
1 => ImapCalendarSupportMode.CalDav,
|
|
|
|
|
2 => ImapCalendarSupportMode.LocalOnly,
|
|
|
|
|
_ => ImapCalendarSupportMode.Disabled
|
|
|
|
|
}
|
|
|
|
|
: ImapCalendarSupportMode.Disabled;
|
2026-03-06 03:42:08 +01:00
|
|
|
|
|
|
|
|
Messenger.Send(new BreadcrumbNavigationRequested(
|
|
|
|
|
Translator.WelcomeWizard_Step3Title,
|
|
|
|
|
WinoPage.AccountSetupProgressPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
private async Task OpenAppPasswordHelp()
|
|
|
|
|
{
|
|
|
|
|
var url = AppPasswordHelpUrl;
|
|
|
|
|
if (url != null)
|
|
|
|
|
await _nativeAppService.LaunchUriAsync(new Uri(url));
|
|
|
|
|
}
|
|
|
|
|
}
|