Fix cross-thread error on AccoundSettings.Saved event

This commit is contained in:
Michael Bucari-Tovo 2025-08-04 14:18:04 -06:00
parent 82a48db57b
commit 29be091a4b
2 changed files with 4 additions and 3 deletions

View File

@ -68,7 +68,8 @@ namespace LibationAvalonia.ViewModels
MainWindow.Loaded += (_, _) => MainWindow.Loaded += (_, _) =>
{ {
refreshImportMenu(); refreshImportMenu();
AccountsSettingsPersister.Saved += refreshImportMenu; AccountsSettingsPersister.Saved += (_, _)
=> Avalonia.Threading.Dispatcher.UIThread.Invoke(refreshImportMenu);
}; };
AutoScanChecked = Configuration.Instance.AutoScan; AutoScanChecked = Configuration.Instance.AutoScan;
@ -222,7 +223,7 @@ namespace LibationAvalonia.ViewModels
} }
} }
private void refreshImportMenu(object? _ = null, EventArgs? __ = null) private void refreshImportMenu()
{ {
using var persister = AudibleApiStorage.GetAccountsSettingsPersister(); using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
AccountsCount = persister.AccountsSettings.Accounts.Count; AccountsCount = persister.AccountsSettings.Accounts.Count;

View File

@ -16,7 +16,7 @@ namespace LibationWinForms
private void Configure_ScanManual() private void Configure_ScanManual()
{ {
this.Load += refreshImportMenu; this.Load += refreshImportMenu;
AccountsSettingsPersister.Saved += refreshImportMenu; AccountsSettingsPersister.Saved += (_, _) => Invoke(refreshImportMenu, null, null);
} }
private void refreshImportMenu(object _, EventArgs __) private void refreshImportMenu(object _, EventArgs __)