mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-05-19 05:55:47 -04:00
#1811 - fix UI threading
This commit is contained in:
@@ -2,6 +2,7 @@ using ApplicationServices;
|
||||
using AudibleUtilities;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Threading;
|
||||
using LibationFileManager;
|
||||
using LibationUiBase;
|
||||
using LibationUiBase.Forms;
|
||||
@@ -71,8 +72,8 @@ public partial class MainVM
|
||||
AutoScanChecked = Configuration.Instance.AutoScan;
|
||||
|
||||
setyNumScanningAccounts(0);
|
||||
LibraryCommands.ScanBegin += (_, accountsLength) => setyNumScanningAccounts(accountsLength);
|
||||
LibraryCommands.ScanEnd += (_, newCount) => setyNumScanningAccounts(0);
|
||||
LibraryCommands.ScanBegin += (_, accountsLength) => Dispatcher.UIThread.Post(() => setyNumScanningAccounts(accountsLength));
|
||||
LibraryCommands.ScanEnd += (_, _) => Dispatcher.UIThread.Post(() => setyNumScanningAccounts(0));
|
||||
|
||||
if (!Design.IsDesignMode)
|
||||
RemoveButtonsVisible = false;
|
||||
|
||||
@@ -13,6 +13,13 @@ public partial class Form1
|
||||
|
||||
private void LibraryCommands_ScanBegin(object? sender, int accountsLength)
|
||||
{
|
||||
// ImportAccountAsync (incl. auto-scan) runs on a worker thread; ToolStrip must be touched on the UI thread.
|
||||
if (InvokeRequired)
|
||||
{
|
||||
BeginInvoke(LibraryCommands_ScanBegin, sender, accountsLength);
|
||||
return;
|
||||
}
|
||||
|
||||
removeLibraryBooksToolStripMenuItem.Enabled = false;
|
||||
removeAllAccountsToolStripMenuItem.Enabled = false;
|
||||
removeSomeAccountsToolStripMenuItem.Enabled = false;
|
||||
@@ -30,6 +37,12 @@ public partial class Form1
|
||||
|
||||
private void LibraryCommands_ScanEnd(object? sender, int newCount)
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
BeginInvoke(LibraryCommands_ScanEnd, sender, newCount);
|
||||
return;
|
||||
}
|
||||
|
||||
removeLibraryBooksToolStripMenuItem.Enabled = true;
|
||||
removeAllAccountsToolStripMenuItem.Enabled = true;
|
||||
removeSomeAccountsToolStripMenuItem.Enabled = true;
|
||||
|
||||
Reference in New Issue
Block a user