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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -45,6 +45,8 @@ namespace Bit.App.Pages
_autofocusCts = new CancellationTokenSource(TimeSpan.FromMinutes(3));
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 () =>
{
try
@ -52,7 +54,7 @@ namespace Bit.App.Pages
while (!autofocusCts.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(2), autofocusCts.Token);
Device.BeginInvokeOnMainThread(() =>
await Device.InvokeOnMainThreadAsync(() =>
{
if (!autofocusCts.IsCancellationRequested)
{
@ -73,7 +75,10 @@ namespace Bit.App.Pages
{
_autofocusCts?.Cancel();
await _continuousAutofocusTask;
if (_continuousAutofocusTask != null)
{
await _continuousAutofocusTask;
}
_zxing.IsScanning = false;
base.OnDisappearing();