-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a936dc0
commit e0e273d
Showing
6 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/ScriptRunner/ScriptRunner.GUI/ViewModels/VaultViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using ReactiveUI; | ||
using ScriptRunner.GUI.Settings; | ||
|
||
namespace ScriptRunner.GUI.ViewModels | ||
{ | ||
public class VaultViewModel : ViewModelBase | ||
{ | ||
public ObservableCollection<VaultEntry> Entries | ||
{ | ||
get => _entries; | ||
set => this.RaiseAndSetIfChanged(ref _entries, value); | ||
} | ||
|
||
private ObservableCollection<VaultEntry> _entries; | ||
|
||
|
||
public VaultViewModel() | ||
{ | ||
var vaultPath = AppSettingsService.GetSettingsPathFor("Vault.dat"); | ||
if (File.Exists(vaultPath)) | ||
{ | ||
File.Decrypt(vaultPath); | ||
var content = File.ReadAllText(vaultPath); | ||
File.Encrypt(vaultPath); | ||
var data = JsonSerializer.Deserialize<List<VaultEntry>>(content); | ||
Entries = new ObservableCollection<VaultEntry>(data?? new List<VaultEntry>()); | ||
} | ||
else | ||
{ | ||
Entries = new ObservableCollection<VaultEntry>() | ||
{ | ||
|
||
}; | ||
} | ||
|
||
} | ||
|
||
public void AddNewVaultEntry() | ||
{ | ||
Entries.Add(new VaultEntry()); | ||
} | ||
|
||
public void SaveVault() | ||
{ | ||
var date = Entries.ToList(); | ||
var vaultPath = AppSettingsService.GetSettingsPathFor("Vault.dat"); | ||
File.WriteAllText(vaultPath, JsonSerializer.Serialize(date), Encoding.UTF8); | ||
File.Encrypt(vaultPath); | ||
} | ||
} | ||
|
||
public class VaultEntry | ||
{ | ||
public string Name { get; set; } | ||
public string Secret { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:viewModels="clr-namespace:ScriptRunner.GUI.ViewModels" | ||
xmlns:avalonia="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
Width="800" | ||
Height="450" | ||
x:Class="ScriptRunner.GUI.Views.Vault" | ||
Title="Vault"> | ||
<Design.DataContext> | ||
<viewModels:VaultViewModel /> | ||
</Design.DataContext> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"></RowDefinition> | ||
<RowDefinition Height="Auto"></RowDefinition> | ||
</Grid.RowDefinitions> | ||
<StackPanel> | ||
<ItemsControl Items="{Binding Entries}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Grid Margin="10,10,10,0"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"></ColumnDefinition> | ||
<ColumnDefinition Width="0.5*"></ColumnDefinition> | ||
<ColumnDefinition Width="Auto"></ColumnDefinition> | ||
<ColumnDefinition Width="0.5*"></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<Label Margin="0,0,10,0" VerticalAlignment="Center">Key</Label> | ||
<TextBox Grid.Column="1" Text="{Binding Name, Mode=TwoWay}"></TextBox> | ||
<Label Grid.Column="2" Margin="10,0,10,0" VerticalAlignment="Center">Value</Label> | ||
<TextBox PasswordChar="*" Grid.Column="3" Text="{Binding Secret, Mode=TwoWay}"></TextBox> | ||
</Grid> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
<Button Command="{Binding AddNewVaultEntry}" Margin="20"> | ||
<StackPanel Orientation="Horizontal"> | ||
<avalonia:Icon Value="fa fa-plus" Margin="4,0"/> | ||
<TextBlock>Add new vault entry</TextBlock> | ||
</StackPanel> | ||
</Button> | ||
</StackPanel> | ||
<StackPanel Grid.Row="1" HorizontalAlignment="Right"> | ||
<Button Margin="10" Click="CloseVaultDialog"> Close</Button> | ||
</StackPanel> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using ScriptRunner.GUI.ViewModels; | ||
|
||
namespace ScriptRunner.GUI.Views | ||
{ | ||
public partial class Vault : Window | ||
{ | ||
public Vault() | ||
{ | ||
InitializeComponent(); | ||
DataContext = this.ViewModel = new VaultViewModel(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
} | ||
|
||
public VaultViewModel ViewModel { get; set; } | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
private void CloseVaultDialog(object? sender, RoutedEventArgs e) | ||
{ | ||
ViewModel.SaveVault(); | ||
Close(); | ||
} | ||
} | ||
} |