mirror of
https://github.com/bitwarden/mobile
synced 2026-01-02 08:33:17 +00:00
manual lock setting
This commit is contained in:
@@ -41,16 +41,16 @@ namespace Bit.App
|
||||
|
||||
MainPage.BackgroundColor = Color.FromHex("ecf0f5");
|
||||
|
||||
MessagingCenter.Subscribe<App>(this, "Lock", async (sender) =>
|
||||
MessagingCenter.Subscribe<Application, bool>(Current, "Lock", async (sender, args) =>
|
||||
{
|
||||
await CheckLockAsync();
|
||||
await CheckLockAsync(args);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
// Handle when your app starts
|
||||
CheckLockAsync();
|
||||
CheckLockAsync(false);
|
||||
_databaseService.CreateTables();
|
||||
|
||||
Debug.WriteLine("OnStart");
|
||||
@@ -68,7 +68,7 @@ namespace Bit.App
|
||||
Debug.WriteLine("OnResume");
|
||||
}
|
||||
|
||||
private async Task CheckLockAsync()
|
||||
private async Task CheckLockAsync(bool forceLock)
|
||||
{
|
||||
// Only lock if they are logged in
|
||||
if(!_authService.IsAuthenticated)
|
||||
@@ -76,19 +76,23 @@ namespace Bit.App
|
||||
return;
|
||||
}
|
||||
|
||||
// Lock seconds tells if if they want to lock the app or not
|
||||
var lockSeconds = _settings.GetValueOrDefault<int?>(Constants.SettingLockSeconds);
|
||||
if(!lockSeconds.HasValue)
|
||||
// Are we forcing a lock? (i.e. clicking a button to lock the app manually, immediately)
|
||||
if(!forceLock)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Lock seconds tells if if they want to lock the app or not
|
||||
var lockSeconds = _settings.GetValueOrDefault<int?>(Constants.SettingLockSeconds);
|
||||
if(!lockSeconds.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Has it been longer than lockSeconds since the last time the app was backgrounded?
|
||||
var now = DateTime.UtcNow;
|
||||
var lastBackground = _settings.GetValueOrDefault(Constants.SettingLastBackgroundedDate, now.AddYears(-1));
|
||||
if((now - lastBackground).TotalSeconds < lockSeconds.Value)
|
||||
{
|
||||
return;
|
||||
// Has it been longer than lockSeconds since the last time the app was backgrounded?
|
||||
var now = DateTime.UtcNow;
|
||||
var lastBackground = _settings.GetValueOrDefault(Constants.SettingLastBackgroundedDate, now.AddYears(-1));
|
||||
if((now - lastBackground).TotalSeconds < lockSeconds.Value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// What method are we using to unlock?
|
||||
@@ -100,7 +104,7 @@ namespace Bit.App
|
||||
{
|
||||
if(Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockFingerprintPage == null)
|
||||
{
|
||||
await Current.MainPage.Navigation.PushModalAsync(new LockFingerprintPage(), false);
|
||||
await Current.MainPage.Navigation.PushModalAsync(new LockFingerprintPage(!forceLock), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,11 @@ namespace Bit.App.Pages
|
||||
private readonly IAuthService _authService;
|
||||
private readonly IUserDialogs _userDialogs;
|
||||
private readonly ISettings _settings;
|
||||
private readonly bool _checkFingerprintImmediately;
|
||||
|
||||
public LockFingerprintPage()
|
||||
public LockFingerprintPage(bool checkFingerprintImmediately)
|
||||
{
|
||||
_checkFingerprintImmediately = checkFingerprintImmediately;
|
||||
_fingerprint = Resolver.Resolve<IFingerprint>();
|
||||
_authService = Resolver.Resolve<IAuthService>();
|
||||
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
||||
@@ -31,8 +33,6 @@ namespace Bit.App.Pages
|
||||
|
||||
public void Init()
|
||||
{
|
||||
CheckFingerprintAsync();
|
||||
|
||||
var fingerprintButton = new Button
|
||||
{
|
||||
Text = "Use Fingerprint to Unlock",
|
||||
@@ -55,6 +55,16 @@ namespace Bit.App.Pages
|
||||
Content = stackLayout;
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
if(_checkFingerprintImmediately)
|
||||
{
|
||||
CheckFingerprintAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LogoutAsync()
|
||||
{
|
||||
if(!await _userDialogs.ConfirmAsync("Are you sure you want to log out?", null, AppResources.Yes, AppResources.Cancel))
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace Bit.App.Pages
|
||||
|
||||
private void LockCell_Tapped(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
MessagingCenter.Send(Application.Current, "Lock", true);
|
||||
}
|
||||
|
||||
private async void LogOutCell_Tapped(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user