Skip to content

Commit

Permalink
优化账户页面初次加载时卡顿的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Nov 30, 2024
1 parent 0d0dfe0 commit 65ce108
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace WonderLab.ViewModels.Dialog.Auth;

public sealed partial class MicrosoftAuthDialogViewModel : ObservableObject {
private readonly AccountService _accountService;

private CancellationTokenSource _cancellationTokenSource;
private readonly CancellationTokenSource _cancellationTokenSource = new();

[ObservableProperty] private string _verificationUrl;

Expand Down Expand Up @@ -49,12 +48,12 @@ private void Close() => Dispatcher.UIThread.InvokeAsync(() => {
DialogHost.Close("PART_DialogHost");

try {
_cancellationTokenSource.Cancel();
_cancellationTokenSource?.Cancel();
} catch (System.Exception) {}
});

[RelayCommand]
private void OpenUrl() => Dispatcher.UIThread.InvokeAsync(() => {
private void OpenUrl() => Task.Run(() => {
Process.Start(new ProcessStartInfo(VerificationUrl) {
UseShellExecute = true,
Verb = "open"
Expand Down
9 changes: 6 additions & 3 deletions WonderLab/ViewModels/Page/Setting/AccountPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ public sealed partial class AccountPageViewModel : ObservableObject {

public AccountPageViewModel(AccountService accountService) {
_accountService = accountService;

_accountService.CollectionChanged += OnCollectionChanged;
Accounts = _accountService.Accounts;
HasAccount = Accounts?.Count > 0;
}

private void OnCollectionChanged(object sender, EventArgs e) {
HasAccount = Accounts?.Count > 0;
}

[RelayCommand]
private Task OnLoaded() => Task.Run(() => {
Accounts = _accountService.Accounts;
HasAccount = Accounts?.Count > 0;
});

[RelayCommand]
private Task CreateAccount() => Dispatcher.UIThread.InvokeAsync(async () => {
ChooseAccountTypeDialog dialog = new() {
Expand Down
6 changes: 6 additions & 0 deletions WonderLab/Views/Page/Setting/AccountPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
xmlns:wc="using:WonderLab.Controls"
xmlns:wb="using:WonderLab.Controls.Media.Behaviors"
x:Class="WonderLab.Views.Page.Setting.AccountPage">
<Interaction.Behaviors>
<EventTriggerBehavior EventName="Loaded">
<InvokeCommandAction Command="{Binding LoadedCommand}"/>
</EventTriggerBehavior>
</Interaction.Behaviors>

<ScrollViewer VerticalScrollBarVisibility="Hidden">
<ItemsControl MaxWidth="1000"
Margin="0 24 0 16">
Expand Down

0 comments on commit 65ce108

Please sign in to comment.