merge branch 'ErrorWindow'

This commit is contained in:
2026-05-03 18:33:43 +03:00
5 changed files with 81 additions and 38 deletions

View File

@@ -37,24 +37,24 @@ public partial class LockedRepositoryViewModel : ViewModelBase
if (e.Message == PassStoreFileException.ContentHMACMismatch.Message || if (e.Message == PassStoreFileException.ContentHMACMismatch.Message ||
e.Message == PassStoreFileException.InvalidBeginMarker.Message) e.Message == PassStoreFileException.InvalidBeginMarker.Message)
{ {
await parent.ShowErrorPopup("Incorrect password or corrupted file"); await parent.ShowErrorPopup("Incorrect password or corrupted file", "Check password");
} else if (e.Message == PassStoreFileException.UnexpectedEndOfFile.Message || } else if (e.Message == PassStoreFileException.UnexpectedEndOfFile.Message ||
e.Message == PassStoreFileException.IncorrectMagicNumber.Message || e.Message == PassStoreFileException.IncorrectMagicNumber.Message ||
e.Message == PassStoreFileException.InvalidCryptoHeader.Message || e.Message == PassStoreFileException.InvalidCryptoHeader.Message ||
e.Message == PassStoreFileException.InvalidPassStoreEntry.Message) e.Message == PassStoreFileException.InvalidPassStoreEntry.Message)
{ {
await parent.ShowErrorPopup("Corrupted file"); await parent.ShowErrorPopup("Corrupted file", "Password store error");
} else if (e.Message == PassStoreFileException.UnsupportedVersion.Message) } else if (e.Message == PassStoreFileException.UnsupportedVersion.Message)
{ {
await parent.ShowErrorPopup("Unsupported store file version"); await parent.ShowErrorPopup("Unsupported store file version", "Password store error");
} else } else
{ {
await parent.ShowErrorPopup("Unknown password store unlock error"); await parent.ShowErrorPopup("Unknown unlock error", "Password store error");
} }
} catch (Exception e) } catch (Exception e)
{ {
Console.WriteLine(e); Console.WriteLine(e);
await parent.ShowErrorPopup("Cannot open the password store file"); await parent.ShowErrorPopup("Cannot open the password store file", "Password store error");
} }
} }
} }

View File

@@ -16,7 +16,7 @@ public partial class RepositoryWindowViewModel : ViewModelBase
private DateTime _timerStart; private DateTime _timerStart;
private string _lockTimerDisplay = string.Empty; private string _lockTimerDisplay = string.Empty;
public Func<string, Task> ShowErrorPopup; public Func<string, string, Task> ShowErrorPopup;
public object CurrentPage public object CurrentPage
{ {

View File

@@ -1,31 +1,67 @@
<Window xmlns="https://github.com/avaloniaui" <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="KeyKeeper.Views.ErrorDialog" x:Class="KeyKeeper.Views.ErrorDialog"
Width="350" Height="120" Width="400" Height="180"
Background="White" WindowStartupLocation="CenterOwner"
Background="#F9F9F9"
CanResize="False" CanResize="False"
Title="Error"> Title="Access Error"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<Grid Margin="10" RowDefinitions="*,Auto"> <Grid Margin="20" RowDefinitions="*, Auto">
<TextBlock x:Name="MessageText" <!-- Main Content -->
Grid.Row="0" <StackPanel Grid.Row="0" Orientation="Horizontal" Spacing="15" VerticalAlignment="Center">
Foreground="Red" <!-- Error Icon (Material Design Style) -->
FontSize="18" <Path Data="M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z"
TextWrapping="Wrap" /> Fill="#E74C3C"
Width="40" Height="40"
Stretch="Uniform" />
<StackPanel VerticalAlignment="Center" Width="280">
<TextBlock x:Name="MessageTitle"
FontWeight="Bold"
FontSize="16"
Foreground="#333"
Margin="0,0,0,4"/>
<TextBlock x:Name="MessageText"
Foreground="#666"
FontSize="14"
TextWrapping="Wrap"
LineHeight="20"/>
</StackPanel>
</StackPanel>
<!-- Action Button -->
<Button Grid.Row="1" <Button Grid.Row="1"
Content="OK" x:Name="OkButton"
HorizontalAlignment="Center" Content="Got it"
Margin="0,10,0,0"
Click="Ok_Click" Click="Ok_Click"
Background="#aaa" /> IsDefault="True"
<Grid.Styles> IsCancel="True"
<Style Selector="Button /template/ ContentPresenter"> HorizontalAlignment="Right"
<Setter Property="Foreground" Value="#333" /> Padding="25,8"
</Style> BorderThickness="0"
<Style Selector="Button:pointerover /template/ ContentPresenter"> CornerRadius="4"
<Setter Property="Background" Value="#ccc" /> Cursor="Hand">
<Setter Property="Foreground" Value="#444" /> <Button.Styles>
</Style> <Style Selector="Button">
</Grid.Styles> <Setter Property="Background" Value="#E0E0E0"/>
<Setter Property="Foreground" Value="#333"/>
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.1" />
<BrushTransition Property="Background" Duration="0:0:0.2" />
</Transitions>
</Setter>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="#D5D5D5"/>
</Style>
<Style Selector="Button:pressed">
<Setter Property="RenderTransform" Value="scale(0.95)"/>
</Style>
</Button.Styles>
</Button>
</Grid> </Grid>
</Window> </Window>

View File

@@ -1,20 +1,27 @@
using System;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading;
namespace KeyKeeper.Views; namespace KeyKeeper.Views;
public partial class ErrorDialog : Window public partial class ErrorDialog : Window
{ {
public ErrorDialog(string message) public ErrorDialog(string message, string title = "Oops! Something went wrong")
{ {
InitializeComponent(); InitializeComponent();
MinWidth = 400;
MinHeight = 200;
MessageText.Text = message; MessageText.Text = message;
MessageTitle.Text = title;
} }
private void Ok_Click(object sender, RoutedEventArgs e) private void Ok_Click(object? sender, RoutedEventArgs e)
{ {
Close(); Close();
} }
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
OkButton.Focus();
}
} }

View File

@@ -23,9 +23,9 @@ public partial class RepositoryWindow : Window
MinHeight = 500; MinHeight = 500;
DataContext = model; DataContext = model;
model.ShowErrorPopup = async (string message) => model.ShowErrorPopup = async (string message, string title) =>
{ {
await new ErrorDialog(message).ShowDialog(this); await new ErrorDialog(message, title).ShowDialog(this);
}; };
} }