mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Error messages are now caught at the app level (see if it's a good solution in the long term)
Redesign of the create key file button
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Data.Json;
|
||||
@@ -29,9 +30,23 @@ namespace ModernKeePass
|
||||
{
|
||||
InitializeComponent();
|
||||
Suspending += OnSuspending;
|
||||
UnhandledException += OnUnhandledException;
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
|
||||
{
|
||||
// TODO: catch only save errors for now, rethrow (do not handle) otherwise
|
||||
var exception = unhandledExceptionEventArgs.Exception;
|
||||
MessageDialogHelper.ShowErrorDialog(
|
||||
exception is TargetInvocationException &&
|
||||
exception.InnerException != null
|
||||
? exception.InnerException
|
||||
: exception);
|
||||
unhandledExceptionEventArgs.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
||||
/// will be used such as when the application is launched to open a specific file.
|
||||
@@ -126,6 +141,7 @@ namespace ModernKeePass
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
UnhandledException -= OnUnhandledException;
|
||||
Database.Save();
|
||||
deferral.Complete();
|
||||
}
|
||||
@@ -143,6 +159,7 @@ namespace ModernKeePass
|
||||
Window.Current.Content = rootFrame;
|
||||
Window.Current.Activate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -105,6 +105,7 @@ namespace ModernKeePass.Common
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = (int)DatabaseStatus.Error;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,38 +113,20 @@ namespace ModernKeePass.Common
|
||||
/// Save the current database to another file and open it
|
||||
/// </summary>
|
||||
/// <param name="file">The new database file</param>
|
||||
public bool Save(StorageFile file)
|
||||
public void Save(StorageFile file)
|
||||
{
|
||||
DatabaseFile = file;
|
||||
try
|
||||
{
|
||||
_pwDatabase.SaveAs(IOConnectionInfo.FromFile(DatabaseFile), true, new NullStatusLogger());
|
||||
Status = (int)DatabaseStatus.Opened;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pwDatabase.SaveAs(IOConnectionInfo.FromFile(DatabaseFile), true, new NullStatusLogger());
|
||||
Status = (int)DatabaseStatus.Opened;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commit the changes to the currently opened database to file
|
||||
/// </summary>
|
||||
public bool Save()
|
||||
public void Save()
|
||||
{
|
||||
if (_pwDatabase == null || !_pwDatabase.IsOpen) return false;
|
||||
try
|
||||
{
|
||||
_pwDatabase.Save(new NullStatusLogger());
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
// TODO: put this at a better place (e.g. in views)
|
||||
MessageDialogHelper.ShowErrorDialog(ex);
|
||||
}
|
||||
if (_pwDatabase == null || !_pwDatabase.IsOpen) return;
|
||||
_pwDatabase.Save(new NullStatusLogger());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -26,6 +26,7 @@ namespace ModernKeePass.Common
|
||||
|
||||
public static async void ShowErrorDialog(Exception exception)
|
||||
{
|
||||
if (exception == null) return;
|
||||
// Create the message dialog and set its content
|
||||
var messageDialog = new MessageDialog(exception.Message, "Error occured");
|
||||
|
||||
|
@@ -48,7 +48,9 @@
|
||||
Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0" Content="{Binding KeyFileText}" IsEnabled="{Binding HasKeyFile}" Click="KeyFileButton_Click" />
|
||||
<Button Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Content="Create new key" Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding HasKeyFile}" Click="CreateKeyFileButton_Click" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding HasKeyFile}" Click="CreateKeyFileButton_Click">
|
||||
<SymbolIcon Symbol="Add" />
|
||||
</HyperlinkButton>
|
||||
<Button Grid.Column="0" Grid.Row="2" Content="OK" Click="OpenButton_OnClick" Background="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" Foreground="{ThemeResource TextBoxBackgroundThemeBrush}" IsEnabled="{Binding IsValid}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="2" Height="28" FontSize="14" FontWeight="Light" HorizontalAlignment="Right" Text="{Binding Status}" Foreground="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" />
|
||||
</Grid>
|
||||
|
@@ -20,8 +20,8 @@ namespace ModernKeePass.Interfaces
|
||||
|
||||
void Open(CompositeKey key, bool createNew);
|
||||
void UpdateCompositeKey(CompositeKey key);
|
||||
bool Save();
|
||||
bool Save(StorageFile file);
|
||||
void Save();
|
||||
void Save(StorageFile file);
|
||||
void CreateRecycleBin();
|
||||
void AddDeletedItem(PwUuid id);
|
||||
void Close();
|
||||
|
@@ -24,14 +24,15 @@ namespace ModernKeePass.Pages
|
||||
{
|
||||
ListView_SelectionChanged(sender, e);
|
||||
var selectedItem = Model.SelectedItem as MainMenuItemVm;
|
||||
selectedItem?.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter);
|
||||
if (selectedItem == null) MenuFrame.Navigate(typeof(WelcomePage));
|
||||
else selectedItem.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter);
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
DataContext = new MainVm(Frame, MenuFrame);
|
||||
if (Model.SelectedItem == null) MenuFrame.Navigate(typeof(WelcomePage));
|
||||
//if (Model.SelectedItem == null) MenuFrame.Navigate(typeof(WelcomePage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -16,8 +13,6 @@ namespace ModernKeePass.Pages
|
||||
/// </summary>
|
||||
public sealed partial class NewDatabasePage
|
||||
{
|
||||
private Frame _mainFrame;
|
||||
|
||||
public NewVm Model => (NewVm)DataContext;
|
||||
|
||||
public NewDatabasePage()
|
||||
@@ -25,12 +20,6 @@ namespace ModernKeePass.Pages
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
}
|
||||
|
||||
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var savePicker = new FileSavePicker
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
@@ -105,7 +106,15 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public bool OpenDatabase(bool createNew)
|
||||
{
|
||||
Database.Open(CreateCompositeKey(), createNew);
|
||||
var error = string.Empty;
|
||||
try
|
||||
{
|
||||
Database.Open(CreateCompositeKey(), createNew);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error = $"Error: {e.Message}";
|
||||
}
|
||||
switch ((DatabaseHelper.DatabaseStatus)Database.Status)
|
||||
{
|
||||
case DatabaseHelper.DatabaseStatus.Opened:
|
||||
@@ -118,6 +127,9 @@ namespace ModernKeePass.ViewModels
|
||||
if (HasKeyFile) errorMessage.Append("key file");
|
||||
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
|
||||
break;
|
||||
case DatabaseHelper.DatabaseStatus.Error:
|
||||
UpdateStatus(error, StatusTypes.Error);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -16,10 +16,11 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void Save(bool close = true)
|
||||
{
|
||||
if (close && _database.Save()) _database.Close();
|
||||
_database.Save();
|
||||
if (close) _database.Close();
|
||||
}
|
||||
|
||||
internal void Save(StorageFile file)
|
||||
public void Save(StorageFile file)
|
||||
{
|
||||
_database.Save(file);
|
||||
}
|
||||
|
Reference in New Issue
Block a user