Move code to `OnNavigatedTo` and add dispose logic
MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/ShowQrCameraDialogViewModel.cs
@@ -24,6 +24,17 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
_qrReader = new(network);
SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
+ }
+
+ protected override void OnNavigatedFrom(bool isInHistory)
+ {
+ base.OnNavigatedFrom(isInHistory);
+ RxApp.MainThreadScheduler.Schedule(async () => await _qrReader.StopScanningAsync());
+ }
+
+ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
+ {
+ base.OnNavigatedTo(isInHistory, disposables);
Observable.FromEventPattern<WriteableBitmap>(_qrReader, nameof(_qrReader.NewImageArrived))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -37,15 +48,18 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
{
ShowQrCameraDialogView.QrImage?.InvalidateVisual();
}
- });
+ })
+ .DisposeWith(disposables);
Observable.FromEventPattern<string>(_qrReader, nameof(_qrReader.CorrectAddressFound))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(args => Close(DialogResultKind.Normal, args.EventArgs));
+ .Subscribe(args => Close(DialogResultKind.Normal, args.EventArgs))
+ .DisposeWith(disposables);
Observable.FromEventPattern<string>(_qrReader, nameof(_qrReader.InvalidAddressFound))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(args => Message = $"Invalid QR code.");
+ .Subscribe(args => Message = $"Invalid QR code.")
+ .DisposeWith(disposables);
Observable.FromEventPattern<Exception>(_qrReader, nameof(_qrReader.ErrorOccured))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -56,18 +70,9 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
Title,
args.EventArgs.Message,
"Something went wrong");
- });
- }
-
- protected override void OnNavigatedFrom(bool isInHistory)
- {
- base.OnNavigatedFrom(isInHistory);
- RxApp.MainThreadScheduler.Schedule(async () => await _qrReader.StopScanningAsync());
- }
+ })
+ .DisposeWith(disposables);
- protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
- {
- base.OnNavigatedTo(isInHistory, disposables);
RxApp.MainThreadScheduler.Schedule(async () => await _qrReader.StartScanningAsync());
}
}

Move code to `OnNavigatedTo` and add dispose logic