From fc8d09693fd89791ea8f5145ca36118257f806ee Mon Sep 17 00:00:00 2001 From: rmbgame Date: Tue, 27 Apr 2021 21:54:15 +0800 Subject: [PATCH] save --- .../Application/UI/Views/Pages/LocalAuthPage.axaml | 4 ++-- src/ST.Client.Desktop/Services/Mvvm/AuthService.cs | 10 +++++----- .../UI/ViewModels/Pages/LocalAuthPageViewModel.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/LocalAuthPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/LocalAuthPage.axaml index 75ee2b5fc..489a06936 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/LocalAuthPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/LocalAuthPage.axaml @@ -19,7 +19,7 @@ TextWrapping="WrapWithOverflow" VerticalAlignment="Center" HorizontalAlignment="Center"> - + @@ -55,7 +55,7 @@ - diff --git a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs index 97431eceb..07951a162 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs @@ -26,11 +26,11 @@ namespace System.Application.Services public static AuthService Current { get; } = new(); #endregion - public SourceList Authenticators { get; } + public SourceCache Authenticators { get; } public AuthService() { - Authenticators = new SourceList(); + Authenticators = new SourceCache(t => t.Id); } public async void Initialize(bool isSync = false) @@ -39,7 +39,7 @@ namespace System.Application.Services var list = await repository.GetAllAsync(); if (list.Any_Nullable()) { - Authenticators.AddRange(list.Select(s => new MyAuthenticator(s))); + Authenticators.AddOrUpdate(list.Select(s => new MyAuthenticator(s))); if (isSync) { @@ -470,7 +470,7 @@ namespace System.Application.Services { return; } - Current.Authenticators.Add(auth); + Current.Authenticators.AddOrUpdate(auth); } public static async void DeleteSaveAuthenticators(MyAuthenticator auth) @@ -481,7 +481,7 @@ namespace System.Application.Services await repository.DeleteAsync(auth.AuthenticatorData.ServerId.Value); } await repository.DeleteAsync(auth.AuthenticatorData.Id); - await MainThreadDesktop.InvokeOnMainThreadAsync(() => Current.Authenticators.Remove(auth)); + Current.Authenticators.Remove(auth); } } } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs index 283d576c0..e22347b21 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs @@ -49,7 +49,7 @@ namespace System.Application.UI.ViewModels .Connect() //.Filter(scriptFilter) .ObserveOn(RxApp.MainThreadScheduler) - //.Sort(SortExpressionComparer.Ascending(x=>x.Name)) + .Sort(SortExpressionComparer.Ascending(x => x.Index).ThenBy(x => x.Name)) .Bind(out _Authenticators) .Subscribe(_ => this.RaisePropertyChanged(nameof(IsAuthenticatorsEmpty))); }