mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-23 11:45:38 +01:00
prevent rapid clicking actions that crash app
This commit is contained in:
parent
3415be4c56
commit
bc6ff3e3bc
@ -16,6 +16,7 @@ namespace Bit.App.Pages
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IUserDialogs _userDialogs;
|
||||
private readonly ISettings _settings;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public HomePage()
|
||||
: base(updateActivity: false)
|
||||
@ -92,11 +93,23 @@ namespace Bit.App.Pages
|
||||
|
||||
public async Task LoginAsync()
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
await Navigation.PushForDeviceAsync(new LoginPage());
|
||||
}
|
||||
|
||||
public async Task RegisterAsync()
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
await Navigation.PushForDeviceAsync(new RegisterPage(this));
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ namespace Bit.App.Pages
|
||||
private readonly ISettings _settings;
|
||||
private readonly IAppSettingsService _appSettings;
|
||||
private readonly bool _checkFingerprintImmediately;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public LockFingerprintPage(bool checkFingerprintImmediately)
|
||||
{
|
||||
@ -79,6 +80,12 @@ namespace Bit.App.Pages
|
||||
|
||||
public async Task CheckFingerprintAsync()
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
var result = await _fingerprint.AuthenticateAsync(AppResources.FingerprintDirection);
|
||||
if(result.Authenticated)
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ namespace Bit.App.Pages
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IAppSettingsService _appSettingsService;
|
||||
private readonly ICryptoService _cryptoService;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public LockPasswordPage()
|
||||
{
|
||||
@ -111,6 +112,12 @@ namespace Bit.App.Pages
|
||||
|
||||
protected async Task CheckPasswordAsync()
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
|
||||
{
|
||||
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
|
||||
|
@ -13,6 +13,7 @@ namespace Bit.App.Pages
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IAppSettingsService _appSettingsService;
|
||||
private TapGestureRecognizer _tgr;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public LockPinPage()
|
||||
{
|
||||
@ -91,6 +92,12 @@ namespace Bit.App.Pages
|
||||
|
||||
protected void PinEntered(object sender, EventArgs args)
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(Model.PIN == _authService.PIN)
|
||||
{
|
||||
_appSettingsService.Locked = false;
|
||||
|
@ -17,6 +17,7 @@ namespace Bit.App.Pages
|
||||
private readonly IUserDialogs _userDialogs;
|
||||
private readonly IConnectivity _connectivity;
|
||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public SettingsAddFolderPage()
|
||||
{
|
||||
@ -56,6 +57,12 @@ namespace Bit.App.Pages
|
||||
|
||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
|
@ -17,6 +17,7 @@ namespace Bit.App.Pages
|
||||
private readonly IUserDialogs _userDialogs;
|
||||
private readonly IConnectivity _connectivity;
|
||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public SettingsEditFolderPage(string folderId)
|
||||
{
|
||||
@ -73,6 +74,12 @@ namespace Bit.App.Pages
|
||||
|
||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
|
@ -27,6 +27,7 @@ namespace Bit.App.Pages
|
||||
private readonly string _defaultUri;
|
||||
private readonly string _defaultName;
|
||||
private readonly bool _fromAutofill;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public VaultAddLoginPage(string defaultUri = null, string defaultName = null, bool fromAutofill = false)
|
||||
{
|
||||
@ -135,6 +136,12 @@ namespace Bit.App.Pages
|
||||
|
||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
|
@ -19,6 +19,7 @@ namespace Bit.App.Pages
|
||||
private readonly IUserDialogs _userDialogs;
|
||||
private readonly IConnectivity _connectivity;
|
||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private DateTime? _lastAction;
|
||||
|
||||
public VaultEditLoginPage(string loginId)
|
||||
{
|
||||
@ -146,6 +147,12 @@ namespace Bit.App.Pages
|
||||
|
||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||
{
|
||||
if(_lastAction.LastActionWasRecent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_lastAction = DateTime.UtcNow;
|
||||
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
|
@ -106,5 +106,16 @@ namespace Bit.App
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LastActionWasRecent(this DateTime? lastAction, int milliseconds = 1000)
|
||||
{
|
||||
if(lastAction.HasValue && (DateTime.UtcNow - lastAction.Value).TotalMilliseconds < milliseconds)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Last action occurred recently.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user