Crunchy-Downloader/CRD/ViewModels/Utils/ContentDialogInputLoginViewModel.cs
Elwador dc570bf420 - Added **toggle to also download description audio** for selected dubs
- Added **automatic history backups** retained for up to 5 days
- Improved **season tab** to display series more effectively
- Improved **history saving** for increased data safety
- Removed **"None" option** from the hardsub selection popup
2025-11-06 20:44:03 +01:00

56 lines
No EOL
1.9 KiB
C#

using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CRD.Downloader.Crunchyroll;
using CRD.Utils.Structs;
using FluentAvalonia.UI.Controls;
namespace CRD.ViewModels.Utils;
public partial class ContentDialogInputLoginViewModel : ViewModelBase{
private readonly ContentDialog dialog;
private readonly TaskCompletionSource<bool> _loginTcs = new();
public Task LoginCompleted => _loginTcs.Task;
[ObservableProperty]
private string _email;
[ObservableProperty]
private string _password;
private AccountPageViewModel? accountPageViewModel;
public ContentDialogInputLoginViewModel(ContentDialog dialog, AccountPageViewModel? accountPageViewModel = null){
if (dialog is null){
throw new ArgumentNullException(nameof(dialog));
}
this.dialog = dialog;
dialog.Closed += DialogOnClosed;
dialog.PrimaryButtonClick += LoginButton;
this.accountPageViewModel = accountPageViewModel;
}
private async void LoginButton(ContentDialog sender, ContentDialogButtonClickEventArgs args){
dialog.PrimaryButtonClick -= LoginButton;
try{
await CrunchyrollManager.Instance.CrAuthEndpoint1.Auth(new AuthData{ Password = Password, Username = Email });
if (!string.IsNullOrEmpty(CrunchyrollManager.Instance.CrAuthEndpoint2.AuthSettings.Endpoint)){
await CrunchyrollManager.Instance.CrAuthEndpoint2.Auth(new AuthData{ Password = Password, Username = Email });
}
accountPageViewModel?.UpdatetProfile();
_loginTcs.TrySetResult(true);
} catch (Exception ex){
_loginTcs.TrySetException(ex);
}
}
private void DialogOnClosed(ContentDialog sender, ContentDialogClosedEventArgs args){
dialog.Closed -= DialogOnClosed;
}
}