Minor refactor for new dialog
MODIFY
WalletWasabi.Fluent/Models/WebcamQrReader.cs
WalletWasabi.Fluent/Models/WebcamQrReader.cs
@@ -47,9 +47,10 @@ namespace WalletWasabi.Fluent.Models
}
ScanningTask = Task.Run(() =>
{
- using VideoCapture? camera = new();
+ VideoCapture? camera = null;
try
{
+ camera = new();
if (!camera.Open(DefaultCameraId))
{
throw new InvalidOperationException("Could not open webcam.");
@@ -65,6 +66,7 @@ namespace WalletWasabi.Fluent.Models
finally
{
camera?.Release();
+ camera?.Dispose();
}
});
}
@@ -129,6 +131,7 @@ namespace WalletWasabi.Fluent.Models
catch (OpenCVException exc)
{
Logger.LogWarning(exc);
+ ErrorOccured?.Invoke(this, exc);
}
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs
@@ -2,33 +2,25 @@ using Avalonia.Media.Imaging;
using NBitcoin;
using ReactiveUI;
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
-using System.Text;
-using System.Threading.Tasks;
using WalletWasabi.Fluent.Models;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
using WalletWasabi.Fluent.Views.Dialogs;
namespace WalletWasabi.Fluent.ViewModels.Dialogs
{
- [NavigationMetaData(Title = "QrCamera")]
+ [NavigationMetaData(Title = "Camera")]
public partial class ShowQrCameraDialogViewModel : DialogViewModelBase<string?>
{
[AutoNotify] private WriteableBitmap? _qrImage;
- [AutoNotify] private bool _isQrPanelVisible;
- [AutoNotify] private bool _isCameraLoadingAnimationVisible;
private WebcamQrReader _qrReader;
public ShowQrCameraDialogViewModel(Network network)
{
_qrReader = new(network);
- _isQrPanelVisible = false;
- _isCameraLoadingAnimationVisible = false;
SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
@@ -36,11 +28,6 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(args =>
{
- if (IsCameraLoadingAnimationVisible == true)
- {
- IsCameraLoadingAnimationVisible = false;
- }
-
if (QrImage == null)
{
QrImage = args.EventArgs;
@@ -53,12 +40,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
Observable.FromEventPattern<string>(_qrReader, nameof(_qrReader.CorrectAddressFound))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(async args =>
- {
- Close(DialogResultKind.Normal, args.EventArgs);
- await _qrReader.StopScanningAsync();
- IsQrPanelVisible = false;
- });
+ .Subscribe(args => Close(DialogResultKind.Normal, args.EventArgs));
Observable.FromEventPattern<string>(_qrReader, nameof(_qrReader.InvalidAddressFound))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -68,10 +50,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(async args =>
{
- IsCameraLoadingAnimationVisible = false;
- IsQrPanelVisible = false;
Close();
- await _qrReader.StopScanningAsync();
await ShowErrorAsync(Title, args.EventArgs.Message, "Something went wrong");
});
}
@@ -79,7 +58,6 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
protected override void OnNavigatedFrom(bool isInHistory)
{
base.OnNavigatedFrom(isInHistory);
-
RxApp.MainThreadScheduler.Schedule(async () => await _qrReader.StopScanningAsync());
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
@@ -97,7 +97,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
QRCommand = ReactiveCommand.Create(async () =>
{
ShowQrCameraDialogViewModel dialog = new(_wallet.Network);
- var result = await NavigateDialogAsync(dialog);
+ var result = await NavigateDialogAsync(dialog, NavigationTarget.CompactDialogScreen);
if (!string.IsNullOrWhiteSpace(result.Result))
{
To = result.Result;

MODIFY
WalletWasabi.Fluent/Views/Dialogs/ShowQrCameraDialogView.axaml
WalletWasabi.Fluent/Views/Dialogs/ShowQrCameraDialogView.axaml
x:CompileBindings="True"
x:Class="WalletWasabi.Fluent.Views.Dialogs.ShowQrCameraDialogView">
<c:ContentArea EnableNext="False"
+ EnableCancel="{Binding EnableCancel}"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<!-- QR Camera -->
- <Panel>
- <c:ProgressRing IsIndeterminate="True" IsVisible="{Binding QrImage,Converter={x:Static ObjectConverters.IsNull}}" />
- <Image Source="{Binding QrImage}" Width="275" Height="275" IsVisible="{Binding QrImage,Converter={x:Static ObjectConverters.IsNotNull}}" />
+ <Panel Width="400" Height="300">
+ <c:ProgressRing IsIndeterminate="True" Height="100" IsVisible="{Binding QrImage,Converter={x:Static ObjectConverters.IsNull}}" />
+ <Image Name="qrImage" Source="{Binding QrImage}" IsVisible="{Binding QrImage,Converter={x:Static ObjectConverters.IsNotNull}}" />
</Panel>
</c:ContentArea>
</UserControl>

Minor refactor for new dialog