merge important changes from feature/repository-window-locking

This commit is contained in:
2025-12-05 02:59:53 +03:00
6 changed files with 96 additions and 10 deletions

View File

@@ -52,7 +52,20 @@
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:LockedRepositoryViewModel}">
<StackPanel Margin="20"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBox x:Name="UnlockPasswordEdit"
Text="{Binding UnlockPassword, Mode=TwoWay}"
PasswordChar="*"
Width="450" />
<Button x:Name="UnlockButton"
Command="{Binding TryUnlock}"
HorizontalAlignment="Center"
Foreground="Black"
Content="Unlock!" />
</StackPanel>
</DataTemplate>
</Window.DataTemplates>

View File

@@ -7,8 +7,6 @@ namespace KeyKeeper;
public partial class RepositoryWindow: Window
{
public IPassStore? PassStore { private get; init; }
public RepositoryWindow()
{
InitializeComponent();
@@ -17,7 +15,5 @@ public partial class RepositoryWindow: Window
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
if (PassStore!.Locked)
PassStore.Unlock(new CompositeKey("blablabla", null));
}
}

View File

@@ -1,5 +1,44 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using KeyKeeper.PasswordStore;
using KeyKeeper.PasswordStore.Crypto;
namespace KeyKeeper.ViewModels;
public class LockedRepositoryViewModel : ViewModelBase
public partial class LockedRepositoryViewModel : ViewModelBase
{
RepositoryWindowViewModel parent;
private IPassStore passStore;
private string password;
public LockedRepositoryViewModel(IPassStore store, RepositoryWindowViewModel parent)
{
passStore = store;
this.parent = parent;
}
public string UnlockPassword
{
get => password;
set { password = value; OnPropertyChanged(nameof(UnlockPassword)); }
}
[RelayCommand]
public void TryUnlock()
{
try
{
passStore.Unlock(new CompositeKey(UnlockPassword, null));
parent.UpdateLockStatus();
} catch (PassStoreFileException e)
{
// TODO
Console.WriteLine("pass store file exception: " + e.Message);
} catch (Exception e)
{
// TODO
Console.WriteLine(e);
}
}
}

View File

@@ -1,11 +1,42 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using KeyKeeper.PasswordStore;
namespace KeyKeeper.ViewModels;
public class RepositoryWindowViewModel : ViewModelBase
public partial class RepositoryWindowViewModel : ViewModelBase
{
private object currentPage = new LockedRepositoryViewModel();
private object currentPage;
private IPassStore passStore;
public object CurrentPage
{
get => currentPage;
set { currentPage = value; OnPropertyChanged(nameof(CurrentPage)); }
}
public RepositoryWindowViewModel(IPassStore store)
{
passStore = store;
UpdateLockStatus();
}
public void UpdateLockStatus()
{
if ((currentPage == null || currentPage is LockedRepositoryViewModel) && !passStore.Locked)
SwitchToUnlocked();
else if ((currentPage == null || currentPage is UnlockedRepositoryViewModel) && passStore.Locked)
SwitchToLocked();
}
private void SwitchToUnlocked()
{
CurrentPage = new UnlockedRepositoryViewModel(passStore);
}
private void SwitchToLocked()
{
CurrentPage = new LockedRepositoryViewModel(passStore, this);
}
}

View File

@@ -1,5 +1,13 @@
using KeyKeeper.PasswordStore;
namespace KeyKeeper.ViewModels;
public class UnlockedRepositoryViewModel : ViewModelBase
{
private IPassStore passStore;
public UnlockedRepositoryViewModel(IPassStore store)
{
passStore = store;
}
}

View File

@@ -84,8 +84,7 @@ namespace KeyKeeper.Views
{
var repositoryWindow = new RepositoryWindow()
{
DataContext = new RepositoryWindowViewModel(),
PassStore = store,
DataContext = new RepositoryWindowViewModel(store),
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
repositoryWindow.Closed += (s, e) => this.Show();