manual lock setting

This commit is contained in:
Kyle Spearrin 2016-05-21 23:26:35 -04:00
parent 29236f7462
commit 8e8272c6fd
4 changed files with 37 additions and 28 deletions

View File

@ -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);
}
}
}

View File

@ -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))

View File

@ -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)

View File

@ -29,8 +29,6 @@ namespace Bit.iOS
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
private App.App _app;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
@ -49,13 +47,11 @@ namespace Bit.iOS
SetIoc();
}
_app = new App.App(
LoadApplication(new App.App(
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>());
LoadApplication(_app);
Resolver.Resolve<ISettings>()));
return base.FinishedLaunching(app, options);
}
@ -112,8 +108,7 @@ namespace Bit.iOS
private void SendLockMessage()
{
MessagingCenter.Send(_app, "Lock");
MessagingCenter.Send(Xamarin.Forms.Application.Current, "Lock", false);
}
private void SetIoc()