Better suspend/resume handling

This commit is contained in:
BONNEVILLE Geoffroy
2018-06-21 16:40:04 +02:00
parent 4393aada3e
commit d533abada5
7 changed files with 33 additions and 27 deletions

View File

@@ -37,7 +37,6 @@ namespace ModernKeePass
UnhandledException += OnUnhandledException; UnhandledException += OnUnhandledException;
} }
#region Event Handlers #region Event Handlers
private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
@@ -133,28 +132,24 @@ namespace ModernKeePass
Window.Current.Activate(); Window.Current.Activate();
} }
private async void OnResuming(object sender, object e) private void OnResuming(object sender, object e)
{ {
var currentFrame = Window.Current.Content as Frame; var currentFrame = Window.Current.Content as Frame;
var database = DatabaseService.Instance; var database = DatabaseService.Instance;
if (!database.IsOpen)
{
#if DEBUG
ToastNotificationHelper.ShowGenericToast("App suspended", "Nothing to do, no previous database opened");
#endif
return;
}
try try
{ {
if (database.CompositeKey != null) database.ReOpen(); database.ReOpen();
#if DEBUG
ToastNotificationHelper.ShowGenericToast(database.Name, "Database reopened (changes were saved)");
#endif
} }
catch (Exception ex) catch (Exception)
{ {
currentFrame?.Navigate(typeof(MainPage)); currentFrame?.Navigate(typeof(MainPage));
#if DEBUG #if DEBUG
await MessageDialogHelper.ShowErrorDialog(ex); ToastNotificationHelper.ShowGenericToast("App resumed", "Nothing to do, no previous database opened");
#endif #endif
ToastNotificationHelper.ShowGenericToast("App suspended", "Database was closed (changes were saved)");
} }
} }
@@ -163,7 +158,7 @@ namespace ModernKeePass
/// </summary> /// </summary>
/// <param name="sender">The Frame which failed navigation</param> /// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param> /// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e) private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{ {
throw new NavigationException(e.SourcePageType); throw new NavigationException(e.SourcePageType);
} }

View File

@@ -12,7 +12,6 @@ namespace ModernKeePass.Interfaces
bool RecycleBinEnabled { get; set; } bool RecycleBinEnabled { get; set; }
GroupVm RootGroup { get; set; } GroupVm RootGroup { get; set; }
GroupVm RecycleBin { get; set; } GroupVm RecycleBin { get; set; }
CompositeKey CompositeKey { get; set; }
PwUuid DataCipher { get; set; } PwUuid DataCipher { get; set; }
PwCompressionAlgorithm CompressionAlgorithm { get; set; } PwCompressionAlgorithm CompressionAlgorithm { get; set; }
KdfParameters KeyDerivation { get; set; } KdfParameters KeyDerivation { get; set; }
@@ -26,5 +25,6 @@ namespace ModernKeePass.Interfaces
void CreateRecycleBin(string title); void CreateRecycleBin(string title);
void AddDeletedItem(PwUuid id); void AddDeletedItem(PwUuid id);
void Close(bool releaseFile = true); void Close(bool releaseFile = true);
void UpdateCompositeKey(CompositeKey newCompositeKey);
} }
} }

View File

@@ -20,6 +20,7 @@ namespace ModernKeePass.Services
private readonly ISettingsService _settings; private readonly ISettingsService _settings;
private StorageFile _databaseFile; private StorageFile _databaseFile;
private GroupVm _recycleBin; private GroupVm _recycleBin;
private CompositeKey _compositeKey;
public GroupVm RootGroup { get; set; } public GroupVm RootGroup { get; set; }
@@ -40,9 +41,7 @@ namespace ModernKeePass.Services
get { return _pwDatabase.RecycleBinEnabled; } get { return _pwDatabase.RecycleBinEnabled; }
set { _pwDatabase.RecycleBinEnabled = value; } set { _pwDatabase.RecycleBinEnabled = value; }
} }
public CompositeKey CompositeKey { get; set; }
public PwUuid DataCipher public PwUuid DataCipher
{ {
get { return _pwDatabase.DataCipherUuid; } get { return _pwDatabase.DataCipherUuid; }
@@ -87,12 +86,16 @@ namespace ModernKeePass.Services
{ {
try try
{ {
if (databaseFile == null)
{
throw new ArgumentNullException(nameof(databaseFile));
}
if (key == null) if (key == null)
{ {
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
} }
CompositeKey = key; _compositeKey = key;
var ioConnection = IOConnectionInfo.FromFile(databaseFile); var ioConnection = IOConnectionInfo.FromFile(databaseFile);
if (createNew) if (createNew)
{ {
@@ -122,7 +125,7 @@ namespace ModernKeePass.Services
public void ReOpen() public void ReOpen()
{ {
Open(_databaseFile, CompositeKey); Open(_databaseFile, _compositeKey);
} }
/// <summary> /// <summary>
@@ -180,6 +183,11 @@ namespace ModernKeePass.Services
RecycleBin.IsSelected = true; RecycleBin.IsSelected = true;
RecycleBin.IconId = (int)PwIcon.TrashBin; RecycleBin.IconId = (int)PwIcon.TrashBin;
} }
public void UpdateCompositeKey(CompositeKey newCompositeKey)
{
if (newCompositeKey != null) _compositeKey = newCompositeKey;
}
private void CreateSampleData() private void CreateSampleData()
{ {

View File

@@ -151,7 +151,7 @@ namespace ModernKeePass.ViewModels
public void UpdateKey() public void UpdateKey()
{ {
Database.CompositeKey = CreateCompositeKey(); Database.UpdateCompositeKey(CreateCompositeKey());
UpdateStatus(_resource.GetResourceValue("CompositeKeyUpdated"), StatusTypes.Success); UpdateStatus(_resource.GetResourceValue("CompositeKeyUpdated"), StatusTypes.Success);
} }

View File

@@ -1,3 +1,5 @@
Entry history feature added Entry history feature added
App now uses Windows theme color as its base color
Design improvements Design improvements
Bug corrections
KeePassLib version bump to 2.39.1 KeePassLib version bump to 2.39.1

View File

@@ -1,3 +1,5 @@
Ajout de la fonctionnalite d'historique des entrees Ajout de la fonctionnalite d'historique des entrees
L'application utilise la couleur de theme de Windows en tant que couleur principale
Ameliorations de design Ameliorations de design
Corrections de bugs
Version de la KeePassLib passe a 2.39.1 Version de la KeePassLib passe a 2.39.1

View File

@@ -16,12 +16,6 @@ namespace ModernKeePassApp.Test.Mock
public PwCompressionAlgorithm CompressionAlgorithm { get; set; } public PwCompressionAlgorithm CompressionAlgorithm { get; set; }
public CompositeKey CompositeKey
{
get { return _compositeKey; }
set { _compositeKey = value; }
}
public PwUuid DataCipher { get; set; } public PwUuid DataCipher { get; set; }
public KdfParameters KeyDerivation { get; set; } public KdfParameters KeyDerivation { get; set; }
@@ -48,6 +42,11 @@ namespace ModernKeePassApp.Test.Mock
_isOpen = false; _isOpen = false;
} }
public void UpdateCompositeKey(CompositeKey newCompositeKey)
{
_compositeKey = newCompositeKey;
}
public void CreateRecycleBin(string title) public void CreateRecycleBin(string title)
{ {
throw new NotImplementedException(); throw new NotImplementedException();