From c63dba2e282b0b85b517e73fa0ebc693b5729943 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Wed, 7 Jul 2021 09:55:35 +0800 Subject: [PATCH] fix --- .../Pages/LocalAuthPageViewModel.cs | 203 +----------------- 1 file changed, 3 insertions(+), 200 deletions(-) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs index 54394872a..0a7ba0af2 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs @@ -1,217 +1,20 @@ using ReactiveUI; -using System.Application.Models; -using System.Application.Services; -using System.Application.UI.Resx; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Properties; using System.Reactive; -using System.Threading.Tasks; -using System.Windows; -using System.Threading; -using System.Reactive.Linq; -using DynamicData.Binding; -using DynamicData; -using System.Application.Repositories; -using System.Linq; namespace System.Application.UI.ViewModels { - public class LocalAuthPageViewModel : TabItemViewModel + partial class LocalAuthPageViewModel : TabItemViewModel { - public LocalAuthPageViewModel() - { - IconKey = nameof(LocalAuthPageViewModel).Replace("ViewModel", "Svg"); - - AddAuthCommand = ReactiveCommand.Create(AddAuthMenu_Click); - RefreshAuthCommand = ReactiveCommand.Create(() => AuthService.Current.Initialize(true)); - EncryptionAuthCommand = ReactiveCommand.Create(ShowEncryptionAuthWindow); - ExportAuthCommand = ReactiveCommand.Create(ShowExportAuthAuthWindow); - LockCommand = ReactiveCommand.Create(async () => - { - var result = await AuthService.Current.HasPasswordEncryption(); - if (result) - { - AuthService.Current.Authenticators.Clear(); - Activation(); - } - else - { - Toast.Show(AppResources.LocalAuth_LockError); - } - }); - - MenuItems = new ObservableCollection() - { - //new MenuItemViewModel(nameof(AppResources.LocalAuth_EditAuth)) - //{ - // Items = new[] - // { - new MenuItemViewModel(nameof(AppResources.Add)) { IconKey="AddDrawing", - Command = AddAuthCommand }, - new MenuItemViewModel(nameof(AppResources.Encrypt)) {IconKey="ShieldLockDrawing", - Command = EncryptionAuthCommand }, - //new MenuItemViewModel(nameof(AppResources.Edit)) { IconKey="EditDrawing" }, - new MenuItemViewModel(nameof(AppResources.Export)) { IconKey="ExportDrawing", - Command = ExportAuthCommand }, - new MenuItemViewModel(), - new MenuItemViewModel(nameof(AppResources.Lock)) {IconKey="LockDrawing", - Command = LockCommand }, - new MenuItemViewModel(nameof(AppResources.Refresh)) {IconKey="RefreshDrawing", - Command = RefreshAuthCommand }, - //new MenuItemViewModel(), - //new MenuItemViewModel(nameof(AppResources.Encrypt)) {IconKey="LockDrawing" }, - //new MenuItemViewModel(nameof(AppResources.CloudSync)) {IconKey="CloudDrawing" }, - // } - //}, - }; - - - AuthService.Current.Authenticators - .Connect() - //.Filter(scriptFilter) - .ObserveOn(RxApp.MainThreadScheduler) - .Sort(SortExpressionComparer.Ascending(x => x.Index).ThenBy(x => x.Name)) - .Bind(out _Authenticators) - .Subscribe(_ => this.RaisePropertyChanged(nameof(IsAuthenticatorsEmpty))); - } - public override string Name { - get => AppResources.LocalAuth; + get => DisplayName; protected set { throw new NotImplementedException(); } } - private readonly ReadOnlyObservableCollection _Authenticators; - public ReadOnlyObservableCollection Authenticators => _Authenticators; - - public bool IsAuthenticatorsEmpty => !AuthService.Current.Authenticators.Items.Any_Nullable(); - - public bool IsAuthenticatorsEmptyAndHasPassword => SourceAuthCount > 0 && IsAuthenticatorsEmpty == true; - - public int SourceAuthCount { get; set; } - public ReactiveCommand AddAuthCommand { get; } public ReactiveCommand EncryptionAuthCommand { get; } - public ReactiveCommand LockCommand { get; } - - public ReactiveCommand RefreshAuthCommand { get; } - public ReactiveCommand ExportAuthCommand { get; } - - public async override void Activation() - { - SourceAuthCount = await AuthService.Current.GetRealAuthenticatorCount(); - //if (IsFirstActivation) - if (IsAuthenticatorsEmptyAndHasPassword) - AuthService.Current.Initialize(); - base.Activation(); - } - - public void Refreshing() - { - AuthService.Current.Initialize(); - } - - void AddAuthMenu_Click() - { - if (!AppSettings.IsOfficialChannelPackage) return; - IShowWindowService.Instance.Show(CustomWindow.AddAuth); - } - - public void ShowAuthCode(MyAuthenticator auth) - { - if (auth.IsShowCode == false) - { - auth.IsShowCode = true; - var max = 100; - auth.CodeCountdown = max; - Task.Run(async () => - { - while (auth.IsShowCode) - { - auth.CurrentCode = string.Empty; - auth.CodeCountdown -= 5; - if (auth.CodeCountdown == 0) - { - auth.CodeCountdown = max; - auth.IsShowCode = false; - } - await Task.Delay(100); - } - }).ContinueWith(s => s.Dispose()); - } - } - - public void CopyCodeCilp(MyAuthenticator auth) - { - DI.Get().SetClipboardText(auth.CurrentCode); - ToastService.Current.Notify(AppResources.LocalAuth_CopyAuthTip + auth.Name); - } - - public async void DeleteAuth(MyAuthenticator auth) - { - var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); - if (result.success) - { - var r = await MessageBoxCompat.ShowAsync(@AppResources.LocalAuth_DeleteAuthTip, ThisAssembly.AssemblyTrademark, MessageBoxButtonCompat.OKCancel); - if (r == MessageBoxResultCompat.OK) - { - AuthService.DeleteSaveAuthenticators(auth); - } - } - } - - public async void ShowSteamAuthData(MyAuthenticator auth) - { - var result = await AuthService.Current.HasPasswordEncryptionShowPassWordWindow(); - if (result.success) - { - if (auth.AuthenticatorData.Value is GAPAuthenticatorValueDTO.SteamAuthenticator) - { - await IShowWindowService.Instance.Show(CustomWindow.ShowAuth, new ShowAuthWindowViewModel(auth), string.Empty, ResizeModeCompat.CanResize); - } - } - } - - public void ShowSteamAuthTrade(MyAuthenticator auth) - { - if (auth.AuthenticatorData.Value is GAPAuthenticatorValueDTO.SteamAuthenticator) - { - IShowWindowService.Instance.Show(CustomWindow.AuthTrade, new AuthTradeWindowViewModel(auth), string.Empty, ResizeModeCompat.CanResize); - } - } - - public async void ShowEncryptionAuthWindow() - { - //if (await AuthService.Current.HasPasswordEncryptionShowPassWordWindow()) - //{ - await IShowWindowService.Instance.Show(CustomWindow.EncryptionAuth, new EncryptionAuthWindowViewModel(), string.Empty, ResizeModeCompat.CanResize); - //} - } - - public async void ShowExportAuthAuthWindow() - { - //if (await AuthService.Current.HasPasswordEncryptionShowPassWordWindow()) - //{ - await IShowWindowService.Instance.Show(CustomWindow.ExportAuth, new ExportAuthWindowViewModel(), string.Empty, ResizeModeCompat.CanResize); - //} - } - - public void UpMoveOrderById(MyAuthenticator auth) - { - MoveOrderById(auth, true); - } - public void DownMoveOrderById(MyAuthenticator auth) - { - MoveOrderById(auth, false); - } - - async void MoveOrderById(MyAuthenticator auth, bool upOrDown) - { - var row = await DI.Get().MoveOrderByIdAsync(AuthService.Current.Authenticators.Items.Select(x => x.AuthenticatorData).ToList(), auth.Id, upOrDown); - } } -} +} \ No newline at end of file