diff --git a/src/KeyKeeper/App.axaml.cs b/src/KeyKeeper/App.axaml.cs index e61b9f4..0ae18f0 100644 --- a/src/KeyKeeper/App.axaml.cs +++ b/src/KeyKeeper/App.axaml.cs @@ -19,6 +19,7 @@ public partial class App : Application public override void OnFrameworkInitializationCompleted() { + AppSettings.Load(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { // Avoid duplicate validations from both Avalonia and the CommunityToolkit. diff --git a/src/KeyKeeper/AppSettings.cs b/src/KeyKeeper/AppSettings.cs new file mode 100644 index 0000000..24af0f8 --- /dev/null +++ b/src/KeyKeeper/AppSettings.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Text.Json; + +namespace KeyKeeper; + +public static class AppSettings +{ + private static readonly string FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "KeyKeeper", "settings.json"); + + public static bool ExitOnRepositoryClose { get; set; } = false; + + // Сохранение в файл + public static void Save() + { + var directory = Path.GetDirectoryName(FilePath); + if (!string.IsNullOrEmpty(directory)) + Directory.CreateDirectory(directory); + + var data = new { ExitOnRepositoryClose }; + string json = JsonSerializer.Serialize(data); + File.WriteAllText(FilePath, json); + } + + // Загрузка из файла + public static void Load() + { + if (File.Exists(FilePath)) + { + try + { + string json = File.ReadAllText(FilePath); + var data = JsonSerializer.Deserialize(json); + if (data != null) + { + ExitOnRepositoryClose = data.ExitOnRepositoryClose; + } + } + catch { /* Если файл поврежден, просто используем значения по умолчанию */ } + } + } + + private class SettingsData + { + public bool ExitOnRepositoryClose { get; set; } + } +} diff --git a/src/KeyKeeper/SettingsWindow.cs b/src/KeyKeeper/SettingsWindow.cs index 3f0911f..6f38710 100644 --- a/src/KeyKeeper/SettingsWindow.cs +++ b/src/KeyKeeper/SettingsWindow.cs @@ -1,25 +1,61 @@ -using Avalonia.Controls; -using Avalonia.Controls.Shapes; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Layout; using Avalonia.Media; namespace KeyKeeper.Views; + public class SettingsWindow : Window { public SettingsWindow() { + // Базовые параметры окна this.Title = "Settings"; - this.MinWidth = 500; - this.MinHeight = 400; - this.Width = 400; - this.Height = 300; - var textBlock = new TextBlock + this.Width = 450; + this.Height = 250; + this.MinWidth = 450; + this.MinHeight = 250; + this.WindowStartupLocation = WindowStartupLocation.CenterOwner; + this.Padding = new Thickness(25); + + // Контейнер, который выравнивает элементы по вертикали + var mainStack = new StackPanel { - Text = "Settings window", - HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, - VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, - FontSize = 16 + Spacing = 15, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top }; - this.Content = textBlock; + // Заголовок окна + var titleText = new TextBlock + { + Text = "App Settings", + FontSize = 20, + FontWeight = FontWeight.Bold, + Margin = new Thickness(0, 0, 0, 10) + }; + + // Чекбокс (Галочка) + var exitOnCloseCheckBox = new CheckBox + { + Content = "Exit KeyKeeper when closing vault", + FontSize = 14, + // Подгружаем сохраненное состояние из статического класса + IsChecked = AppSettings.ExitOnRepositoryClose + }; + + // Событие: когда пользователь щелкает по галочке, данные сразу улетают в AppSettings + exitOnCloseCheckBox.IsCheckedChanged += (s, e) => + { + AppSettings.ExitOnRepositoryClose = exitOnCloseCheckBox.IsChecked ?? false; + AppSettings.Save(); + }; + + // Добавляем элементы в стек + mainStack.Children.Add(titleText); + mainStack.Children.Add(exitOnCloseCheckBox); + + // Назначаем стек основным контентом окна + this.Content = mainStack; } } diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs index aea5e39..b2edd6e 100644 --- a/src/KeyKeeper/Views/MainWindow.axaml.cs +++ b/src/KeyKeeper/Views/MainWindow.axaml.cs @@ -100,9 +100,19 @@ namespace KeyKeeper.Views { WindowStartupLocation = WindowStartupLocation.CenterScreen }; - repositoryWindow.Closed += (s, e) => this.Close(); + repositoryWindow.Closed += (s, e) => + { + if (AppSettings.ExitOnRepositoryClose) + { + this.Close(); + } + else + { + this.Show(); + } + }; repositoryWindow.Show(); - this.Hide(); + this.Hide(); } } }