1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-10 13:23:39 +00:00

EC-255 fix crash when scanning TOTP; BeginInvokeOnMainThread doesn't bubble up the exception, just crashes because it throws the exception to the current main thread context; so it was changed to InvokeOnMainThreadAsync which does bubble up the exception. (#1942)

This commit is contained in:
Federico Maccaroni
2022-06-07 11:46:48 -03:00
committed by GitHub
parent 0a64e4c918
commit b223f5f16e

View File

@@ -45,6 +45,8 @@ namespace Bit.App.Pages
_autofocusCts = new CancellationTokenSource(TimeSpan.FromMinutes(3)); _autofocusCts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
var autofocusCts = _autofocusCts; var autofocusCts = _autofocusCts;
// this task is needed to be awaited OnDisappearing to avoid some crashes
// when changing the value of _zxing.IsScanning
_continuousAutofocusTask = Task.Run(async () => _continuousAutofocusTask = Task.Run(async () =>
{ {
try try
@@ -52,7 +54,7 @@ namespace Bit.App.Pages
while (!autofocusCts.IsCancellationRequested) while (!autofocusCts.IsCancellationRequested)
{ {
await Task.Delay(TimeSpan.FromSeconds(2), autofocusCts.Token); await Task.Delay(TimeSpan.FromSeconds(2), autofocusCts.Token);
Device.BeginInvokeOnMainThread(() => await Device.InvokeOnMainThreadAsync(() =>
{ {
if (!autofocusCts.IsCancellationRequested) if (!autofocusCts.IsCancellationRequested)
{ {
@@ -73,7 +75,10 @@ namespace Bit.App.Pages
{ {
_autofocusCts?.Cancel(); _autofocusCts?.Cancel();
await _continuousAutofocusTask; if (_continuousAutofocusTask != null)
{
await _continuousAutofocusTask;
}
_zxing.IsScanning = false; _zxing.IsScanning = false;
base.OnDisappearing(); base.OnDisappearing();