add timeout on timers

This commit is contained in:
Kyle Spearrin 2018-02-01 21:20:35 -05:00
parent dfd39ebc95
commit dd334858ff
4 changed files with 20 additions and 16 deletions

View file

@ -11,7 +11,8 @@ namespace Bit.App.Pages
{
private readonly ZXingScannerView _zxing;
private readonly OverlayGrid _overlay;
private bool _pageDisappeared = true;
private DateTime? _timerStarted = null;
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(3);
public ScanPage(Action<string> callback)
: base(updateActivity: false, requireAuth: false)
@ -79,12 +80,12 @@ namespace Bit.App.Pages
protected override void OnAppearing()
{
_pageDisappeared = false;
base.OnAppearing();
_zxing.IsScanning = true;
_timerStarted = DateTime.Now;
Device.StartTimer(new TimeSpan(0, 0, 2), () =>
{
if(_pageDisappeared)
if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength)
{
return false;
}
@ -96,7 +97,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing()
{
_pageDisappeared = true;
_timerStarted = null;
_zxing.IsScanning = false;
base.OnDisappearing();
}

View file

@ -13,7 +13,8 @@ namespace Bit.App.Pages
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IAppInfoService _appInfoService;
private readonly IDeviceActionService _deviceActionService;
private bool _pageDisappeared = false;
private DateTime? _timerStarted = null;
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
public ToolsAccessibilityServicePage()
{
@ -175,12 +176,12 @@ namespace Bit.App.Pages
protected override void OnAppearing()
{
_pageDisappeared = false;
UpdateEnabled();
_timerStarted = DateTime.Now;
Device.StartTimer(new TimeSpan(0, 0, 3), () =>
{
System.Diagnostics.Debug.WriteLine("Check timer on accessibility");
if(_pageDisappeared)
if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength)
{
return false;
}
@ -194,7 +195,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing()
{
_pageDisappeared = true;
_timerStarted = null;
base.OnDisappearing();
}

View file

@ -13,7 +13,8 @@ namespace Bit.App.Pages
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly IAppInfoService _appInfoService;
private readonly IDeviceActionService _deviceActionService;
private bool _pageDisappeared = false;
private DateTime? _timerStarted = null;
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
public ToolsAutofillServicePage()
{
@ -126,12 +127,12 @@ namespace Bit.App.Pages
protected override void OnAppearing()
{
_pageDisappeared = false;
UpdateEnabled();
_timerStarted = DateTime.Now;
Device.StartTimer(new TimeSpan(0, 0, 2), () =>
{
System.Diagnostics.Debug.WriteLine("Check timer on autofill");
if(_pageDisappeared)
if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength)
{
return false;
}
@ -145,7 +146,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing()
{
_pageDisappeared = true;
_timerStarted = null;
base.OnDisappearing();
}

View file

@ -21,7 +21,8 @@ namespace Bit.App.Pages
private readonly ICipherService _cipherService;
private readonly IDeviceActionService _deviceActionService;
private readonly ITokenService _tokenService;
private bool _pageDisappeared = true;
private DateTime? _timerStarted = null;
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
public VaultViewCipherPage(CipherType type, string cipherId)
{
@ -273,7 +274,6 @@ namespace Bit.App.Pages
protected async override void OnAppearing()
{
_pageDisappeared = false;
NotesCell.Tapped += NotesCell_Tapped;
EditItem?.InitEvents();
@ -291,7 +291,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing()
{
_pageDisappeared = true;
_timerStarted = null;
NotesCell.Tapped -= NotesCell_Tapped;
EditItem?.Dispose();
CleanupAttachmentCells();
@ -382,9 +382,10 @@ namespace Bit.App.Pages
if(!string.IsNullOrWhiteSpace(Model.LoginTotpCode))
{
TotpTick(totpKey);
_timerStarted = DateTime.Now;
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
{
if(_pageDisappeared)
if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength)
{
return false;
}