make unlocking work, no exception handling yet

This commit is contained in:
2025-12-05 02:57:20 +03:00
parent 27682c343e
commit aa9075af89
3 changed files with 42 additions and 6 deletions

View File

@@ -56,10 +56,12 @@
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!" />

View File

@@ -1,13 +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)
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,8 +1,11 @@
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;
private IPassStore passStore;
@@ -19,7 +22,7 @@ public class RepositoryWindowViewModel : ViewModelBase
UpdateLockStatus();
}
private void UpdateLockStatus()
public void UpdateLockStatus()
{
if ((currentPage == null || currentPage is LockedRepositoryViewModel) && !passStore.Locked)
SwitchToUnlocked();
@@ -29,11 +32,11 @@ public class RepositoryWindowViewModel : ViewModelBase
private void SwitchToUnlocked()
{
currentPage = new UnlockedRepositoryViewModel(passStore);
CurrentPage = new UnlockedRepositoryViewModel(passStore);
}
private void SwitchToLocked()
{
currentPage = new LockedRepositoryViewModel(passStore);
CurrentPage = new LockedRepositoryViewModel(passStore, this);
}
}