From d533abada512cc8eaacd3e59e699b767dcd7a9c1 Mon Sep 17 00:00:00 2001 From: BONNEVILLE Geoffroy Date: Thu, 21 Jun 2018 16:40:04 +0200 Subject: [PATCH] Better suspend/resume handling --- ModernKeePass/App.xaml.cs | 23 ++++++++----------- ModernKeePass/Interfaces/IDatabaseService.cs | 2 +- ModernKeePass/Services/DatabaseService.cs | 18 +++++++++++---- ModernKeePass/ViewModels/CompositeKeyVm.cs | 2 +- .../en-us/baselisting/releaseNotes.txt | 2 ++ .../fr-fr/baselisting/releaseNotes.txt | 2 ++ .../Mock/DatabaseServiceMock.cs | 11 ++++----- 7 files changed, 33 insertions(+), 27 deletions(-) diff --git a/ModernKeePass/App.xaml.cs b/ModernKeePass/App.xaml.cs index 6255ae4..739c050 100644 --- a/ModernKeePass/App.xaml.cs +++ b/ModernKeePass/App.xaml.cs @@ -37,7 +37,6 @@ namespace ModernKeePass UnhandledException += OnUnhandledException; } - #region Event Handlers private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) @@ -133,28 +132,24 @@ namespace ModernKeePass 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 database = DatabaseService.Instance; - if (!database.IsOpen) - { -#if DEBUG - ToastNotificationHelper.ShowGenericToast("App suspended", "Nothing to do, no previous database opened"); -#endif - return; - } + 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)); #if DEBUG - await MessageDialogHelper.ShowErrorDialog(ex); + ToastNotificationHelper.ShowGenericToast("App resumed", "Nothing to do, no previous database opened"); #endif - ToastNotificationHelper.ShowGenericToast("App suspended", "Database was closed (changes were saved)"); } } @@ -163,7 +158,7 @@ namespace ModernKeePass /// /// The Frame which failed navigation /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) + private void OnNavigationFailed(object sender, NavigationFailedEventArgs e) { throw new NavigationException(e.SourcePageType); } diff --git a/ModernKeePass/Interfaces/IDatabaseService.cs b/ModernKeePass/Interfaces/IDatabaseService.cs index 23bbe7c..f527c3b 100644 --- a/ModernKeePass/Interfaces/IDatabaseService.cs +++ b/ModernKeePass/Interfaces/IDatabaseService.cs @@ -12,7 +12,6 @@ namespace ModernKeePass.Interfaces bool RecycleBinEnabled { get; set; } GroupVm RootGroup { get; set; } GroupVm RecycleBin { get; set; } - CompositeKey CompositeKey { get; set; } PwUuid DataCipher { get; set; } PwCompressionAlgorithm CompressionAlgorithm { get; set; } KdfParameters KeyDerivation { get; set; } @@ -26,5 +25,6 @@ namespace ModernKeePass.Interfaces void CreateRecycleBin(string title); void AddDeletedItem(PwUuid id); void Close(bool releaseFile = true); + void UpdateCompositeKey(CompositeKey newCompositeKey); } } \ No newline at end of file diff --git a/ModernKeePass/Services/DatabaseService.cs b/ModernKeePass/Services/DatabaseService.cs index 99a6c07..11d5991 100644 --- a/ModernKeePass/Services/DatabaseService.cs +++ b/ModernKeePass/Services/DatabaseService.cs @@ -20,6 +20,7 @@ namespace ModernKeePass.Services private readonly ISettingsService _settings; private StorageFile _databaseFile; private GroupVm _recycleBin; + private CompositeKey _compositeKey; public GroupVm RootGroup { get; set; } @@ -40,9 +41,7 @@ namespace ModernKeePass.Services get { return _pwDatabase.RecycleBinEnabled; } set { _pwDatabase.RecycleBinEnabled = value; } } - - public CompositeKey CompositeKey { get; set; } - + public PwUuid DataCipher { get { return _pwDatabase.DataCipherUuid; } @@ -87,12 +86,16 @@ namespace ModernKeePass.Services { try { + if (databaseFile == null) + { + throw new ArgumentNullException(nameof(databaseFile)); + } if (key == null) { throw new ArgumentNullException(nameof(key)); } - CompositeKey = key; + _compositeKey = key; var ioConnection = IOConnectionInfo.FromFile(databaseFile); if (createNew) { @@ -122,7 +125,7 @@ namespace ModernKeePass.Services public void ReOpen() { - Open(_databaseFile, CompositeKey); + Open(_databaseFile, _compositeKey); } /// @@ -180,6 +183,11 @@ namespace ModernKeePass.Services RecycleBin.IsSelected = true; RecycleBin.IconId = (int)PwIcon.TrashBin; } + + public void UpdateCompositeKey(CompositeKey newCompositeKey) + { + if (newCompositeKey != null) _compositeKey = newCompositeKey; + } private void CreateSampleData() { diff --git a/ModernKeePass/ViewModels/CompositeKeyVm.cs b/ModernKeePass/ViewModels/CompositeKeyVm.cs index dd5b39b..6a0ab17 100644 --- a/ModernKeePass/ViewModels/CompositeKeyVm.cs +++ b/ModernKeePass/ViewModels/CompositeKeyVm.cs @@ -151,7 +151,7 @@ namespace ModernKeePass.ViewModels public void UpdateKey() { - Database.CompositeKey = CreateCompositeKey(); + Database.UpdateCompositeKey(CreateCompositeKey()); UpdateStatus(_resource.GetResourceValue("CompositeKeyUpdated"), StatusTypes.Success); } diff --git a/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt b/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt index 7031cb7..42efec4 100644 --- a/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt +++ b/ModernKeePass/appMetadata/en-us/baselisting/releaseNotes.txt @@ -1,3 +1,5 @@ Entry history feature added +App now uses Windows theme color as its base color Design improvements +Bug corrections KeePassLib version bump to 2.39.1 \ No newline at end of file diff --git a/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt b/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt index 46fdffa..46e3b0e 100644 --- a/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt +++ b/ModernKeePass/appMetadata/fr-fr/baselisting/releaseNotes.txt @@ -1,3 +1,5 @@ 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 +Corrections de bugs Version de la KeePassLib passe a 2.39.1 \ No newline at end of file diff --git a/ModernKeePassApp.Test/Mock/DatabaseServiceMock.cs b/ModernKeePassApp.Test/Mock/DatabaseServiceMock.cs index 20f6731..856adab 100644 --- a/ModernKeePassApp.Test/Mock/DatabaseServiceMock.cs +++ b/ModernKeePassApp.Test/Mock/DatabaseServiceMock.cs @@ -16,12 +16,6 @@ namespace ModernKeePassApp.Test.Mock public PwCompressionAlgorithm CompressionAlgorithm { get; set; } - public CompositeKey CompositeKey - { - get { return _compositeKey; } - set { _compositeKey = value; } - } - public PwUuid DataCipher { get; set; } public KdfParameters KeyDerivation { get; set; } @@ -48,6 +42,11 @@ namespace ModernKeePassApp.Test.Mock _isOpen = false; } + public void UpdateCompositeKey(CompositeKey newCompositeKey) + { + _compositeKey = newCompositeKey; + } + public void CreateRecycleBin(string title) { throw new NotImplementedException();