Renew the Start/StopScanning methods
MODIFY
WalletWasabi.Fluent/Models/WebcamQrReader.cs
WalletWasabi.Fluent/Models/WebcamQrReader.cs
using Avalonia.Media.Imaging;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using Avalonia;
@@ -11,24 +8,27 @@ using System.Runtime.InteropServices;
using WalletWasabi.Logging;
using WalletWasabi.Userfacing;
using NBitcoin;
-using System.Threading;
+using Nito.AsyncEx;
namespace WalletWasabi.Fluent.Models
{
public class WebcamQrReader
{
+ private AsyncLock ScanningTaskLock { get; set; }
public bool RequestEnd { get; set; }
public Network Network { get; }
public Task? ScanningTask { get; set; }
+ public bool IsRunning => ScanningTask is not null;
public WebcamQrReader(Network network)
{
+ ScanningTaskLock = new();
Network = network;
}
- public void StartScanning()
+ public async Task StartScanningAsync()
{
- if (ScanningTask is not { })
+ using (await ScanningTaskLock.LockAsync().ConfigureAwait(false))
{
ScanningTask = Task.Run(() =>
{
@@ -57,6 +57,8 @@ namespace WalletWasabi.Fluent.Models
}
public async Task StopScanningAsync()
+ {
+ using (await ScanningTaskLock.LockAsync().ConfigureAwait(false))
{
if (ScanningTask is { } task)
{
@@ -66,6 +68,7 @@ namespace WalletWasabi.Fluent.Models
ScanningTask = null;
}
}
+ }
private void Scan(VideoCapture camera)
{

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
@@ -127,14 +127,14 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
PasteCommand = ReactiveCommand.CreateFromTask(async () => await OnPasteAsync());
AutoPasteCommand = ReactiveCommand.CreateFromTask(async () => await OnAutoPasteAsync());
- QRCommand = ReactiveCommand.Create(() =>
+ QRCommand = ReactiveCommand.Create(async () =>
{
- if (IsQrPanelVisible == false)
+ if (!_qrReader.IsRunning)
{
IsCameraLoading = true;
- }
IsQrPanelVisible = true;
- _qrReader.StartScanning();
+ await _qrReader.StartScanningAsync();
+ }
});
var nextCommandCanExecute =

Renew the Start/StopScanning methods