From 2906c0eced6585a3fe38a39428ddb0100e38609b Mon Sep 17 00:00:00 2001 From: Mateusz Kierepka Date: Thu, 10 Oct 2024 20:59:17 +0200 Subject: [PATCH] =?UTF-8?q?Aktualizacja=20-=20ustawienia=20Sporo=20zmian?= =?UTF-8?q?=20dotycz=C4=85cych=20wczytywania=20tablic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChatAAC/App.axaml.cs | 4 +- .../Converters/StringConverterAllowNumber.cs | 31 ++ .../StringNotEmptyToBoolConverter.cs | 21 ++ ChatAAC/Models/ConfigData.cs | 17 + ChatAAC/Models/Obf/Button.cs | 4 +- ChatAAC/Models/Obf/Grid.cs | 3 +- ChatAAC/Models/Obf/ObfLoader.cs | 94 ++++-- ChatAAC/ViewModels/ConfigViewModel.cs | 291 +++++++++++------- ChatAAC/ViewModels/MainViewModel.cs | 117 +++++-- ChatAAC/Views/ConfigWindow.axaml | 49 ++- .../obj/Debug/net8.0/ChatAAC.AssemblyInfo.cs | 2 +- global.json | 7 + 12 files changed, 457 insertions(+), 183 deletions(-) create mode 100644 ChatAAC/Converters/StringConverterAllowNumber.cs create mode 100644 ChatAAC/Converters/StringNotEmptyToBoolConverter.cs create mode 100644 ChatAAC/Models/ConfigData.cs create mode 100644 global.json diff --git a/ChatAAC/App.axaml.cs b/ChatAAC/App.axaml.cs index 91e0b5b..51f0234 100644 --- a/ChatAAC/App.axaml.cs +++ b/ChatAAC/App.axaml.cs @@ -35,7 +35,7 @@ private void OpenConfigWindow() { var configWindow = new ConfigWindow() { - DataContext = new ConfigViewModel() + DataContext = ConfigViewModel.Instance }; var mainWindow = (Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime) ?.MainWindow; @@ -52,7 +52,7 @@ private void OpenAboutWindow() { DataContext = new AboutViewModel() }; - var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime) + var mainWindow = (Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime) ?.MainWindow; if (mainWindow != null) aboutWindow.ShowDialog(mainWindow); diff --git a/ChatAAC/Converters/StringConverterAllowNumber.cs b/ChatAAC/Converters/StringConverterAllowNumber.cs new file mode 100644 index 0000000..e508028 --- /dev/null +++ b/ChatAAC/Converters/StringConverterAllowNumber.cs @@ -0,0 +1,31 @@ +using System; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace ChatAAC.Converters; + +public class StringConverterAllowNumber : JsonConverter +{ + public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return reader.TokenType switch + { + // Obsługa wartości null + JsonTokenType.Null => null, + // Obsługa ciągów znaków + JsonTokenType.String => reader.GetString(), + // Obsługa liczb + JsonTokenType.Number => reader.GetDouble().ToString(CultureInfo.InvariantCulture), + // Obsługa wartości logicznych + JsonTokenType.True or JsonTokenType.False => reader.GetBoolean().ToString(), + _ => throw new JsonException( + $"Nieoczekiwany typ tokenu {reader.TokenType} podczas parsowania ciągu znaków.") + }; + } + + public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) + { + writer.WriteStringValue(value); + } +} \ No newline at end of file diff --git a/ChatAAC/Converters/StringNotEmptyToBoolConverter.cs b/ChatAAC/Converters/StringNotEmptyToBoolConverter.cs new file mode 100644 index 0000000..01c884a --- /dev/null +++ b/ChatAAC/Converters/StringNotEmptyToBoolConverter.cs @@ -0,0 +1,21 @@ +using Avalonia.Data.Converters; +using System; +using System.Globalization; + +namespace ChatAAC.Converters +{ + public class StringNotEmptyToBoolConverter : IValueConverter + { + public static StringNotEmptyToBoolConverter Instance { get; } = new StringNotEmptyToBoolConverter(); + + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + return !string.IsNullOrEmpty(value as string); + } + + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/ChatAAC/Models/ConfigData.cs b/ChatAAC/Models/ConfigData.cs new file mode 100644 index 0000000..0af048f --- /dev/null +++ b/ChatAAC/Models/ConfigData.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace ChatAAC.Models; + +public class ConfigData +{ + public string OllamaAddress { get; set; } = string.Empty; + public string SelectedModel { get; set; } = string.Empty; + public bool ShowSex { get; set; } + public bool ShowViolence { get; set; } + public bool ShowAac { get; set; } + public bool ShowSchematic { get; set; } + public string? SelectedLanguage { get; set; } + public int LoadedIconsCount { get; set; } + public string DefaultBoardPath { get; set; } = string.Empty; + public List BoardPaths { get; set; } = new(); +} \ No newline at end of file diff --git a/ChatAAC/Models/Obf/Button.cs b/ChatAAC/Models/Obf/Button.cs index 1f1a401..10187db 100644 --- a/ChatAAC/Models/Obf/Button.cs +++ b/ChatAAC/Models/Obf/Button.cs @@ -6,9 +6,7 @@ namespace ChatAAC.Models.Obf; // Class for Button public class Button { - [JsonPropertyName("id")] - [JsonConverter(typeof(IntFromStringConverter))] - public int? Id { get; set; } + [JsonPropertyName("id")] public string Id { get; set; } = string.Empty; [JsonPropertyName("label")] public string Label { get; set; } = string.Empty; diff --git a/ChatAAC/Models/Obf/Grid.cs b/ChatAAC/Models/Obf/Grid.cs index f35ad1c..0b56815 100644 --- a/ChatAAC/Models/Obf/Grid.cs +++ b/ChatAAC/Models/Obf/Grid.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -9,5 +10,5 @@ public class Grid [JsonPropertyName("columns")] public int Columns { get; set; } - [JsonPropertyName("order")] public List> Order { get; set; } = new(); + [JsonPropertyName("order")] public string?[][] Order { get; set; } = []; } \ No newline at end of file diff --git a/ChatAAC/Models/Obf/ObfLoader.cs b/ChatAAC/Models/Obf/ObfLoader.cs index e8644bb..6b972f3 100644 --- a/ChatAAC/Models/Obf/ObfLoader.cs +++ b/ChatAAC/Models/Obf/ObfLoader.cs @@ -18,7 +18,11 @@ public static partial class ObfLoader { PropertyNameCaseInsensitive = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - Converters = { new IntFromStringConverter() } + Converters = + { + new StringConverterAllowNumber(), + new IntFromStringConverter() + } }; public static string ObfCacheDirectory { get; } = Path.Combine( @@ -59,19 +63,19 @@ public static partial class ObfLoader return null; } - + // Pobierz katalog bazowy oryginalnego pliku OBF var obfBaseDirectory = Path.GetDirectoryName(filePath) ?? string.Empty; - + // Przetwarzaj obrazy w pliku OBF, przekazując katalog bazowy await ProcessImagesAsync(obfFile, obfBaseDirectory); foreach (var button in obfFile.Buttons) { - // Find the corresponding image + // Znajdź odpowiadający obraz button.Image = obfFile.Images.Find(image => image.Id == button.ImageId); - if (button.Image is null) + if (button.Image == null) { Console.WriteLine($"Brak obrazu dla przycisku o ID: {button.Id}"); } @@ -124,16 +128,16 @@ private static async Task ProcessImagesAsync(ObfFile obfFile, string obfBaseDire } // Próba zapisania obrazu z różnych źródeł - if (!await SaveImageFromDataAsync(image, image.ImagePath)) - { - if (!await SaveImageFromUrlAsync(image, image.ImagePath)) - { - if (!await SaveImageFromPathAsync(image, image.ImagePath, obfBaseDirectory)) - { - LogError($"Nie udało się zapisać obrazu: {image.Id}"); - } - } - } + if (!string.IsNullOrEmpty(image.Data) || !string.IsNullOrWhiteSpace(image.DataUrl)) + if (await SaveImageFromDataAsync(image, image.ImagePath)) + continue; + + if (!string.IsNullOrEmpty(image.Url)) + if (await SaveImageFromUrlAsync(image, image.ImagePath)) + continue; + + if (await SaveImageFromPathAsync(image, image.ImagePath, obfBaseDirectory)) continue; + LogError($"Nie udało się zapisać obrazu: {image.Id}"); } } @@ -152,12 +156,23 @@ private static string GenerateImageFileName(Image image) /// private static async Task SaveImageFromDataAsync(Image image, string destinationPath) { - if (string.IsNullOrEmpty(image.Data)) - return false; + var data = image.Data; + + if (!(string.IsNullOrEmpty(image.DataUrl))) + { + var response = await HttpClient.GetAsync(image.DataUrl); + if (response.IsSuccessStatusCode) + { + data = await response.Content.ReadAsStringAsync(); + Log($"Downloaded image data from URL: {destinationPath}"); + } + } + + if (string.IsNullOrEmpty(data)) return false; try { - var base64Data = ExtractBase64Data(image.Data); + var base64Data = ExtractBase64Data(data); var imageBytes = Convert.FromBase64String(base64Data); await File.WriteAllBytesAsync(destinationPath, imageBytes); Log($"Saved image from Base64 data: {destinationPath}"); @@ -188,11 +203,9 @@ private static async Task SaveImageFromUrlAsync(Image image, string destin Log($"Downloaded and saved image from URL: {destinationPath}"); return true; } - else - { - LogError($"Failed to download image from URL: {image.Url}. Status code: {response.StatusCode}"); - return false; - } + + LogError($"Failed to download image from URL: {image.Url}. Status code: {response.StatusCode}"); + return false; } catch (Exception ex) { @@ -202,7 +215,7 @@ private static async Task SaveImageFromUrlAsync(Image image, string destin } /// - /// Attempts to save the image from a file path, using only the filename. + /// Próbuje zapisać obraz z podanej ścieżki, używając tylko nazwy pliku. /// private static async Task SaveImageFromPathAsync(Image image, string destinationPath, string obfBaseDirectory) @@ -227,9 +240,12 @@ private static async Task SaveImageFromPathAsync(Image image, string desti return false; } - if (File.Exists(fullImagePath)) + // Sprawdź asynchronicznie, czy plik istnieje + bool fileExists = await Task.Run(() => File.Exists(fullImagePath)); + if (fileExists) { - File.Copy(fullImagePath, destinationPath); + // Skopiuj plik asynchronicznie + await CopyFileAsync(fullImagePath, destinationPath); Log($"Skopiowano obraz z {fullImagePath} do {destinationPath}"); return true; } @@ -246,9 +262,10 @@ private static async Task SaveImageFromPathAsync(Image image, string desti foreach (var path in potentialPaths) { - if (File.Exists(path)) + bool exists = await Task.Run(() => File.Exists(path)); + if (exists) { - File.Copy(path, destinationPath); + await CopyFileAsync(path, destinationPath); Log($"Skopiowano obraz z {path} do {destinationPath}"); return true; } @@ -264,7 +281,25 @@ private static async Task SaveImageFromPathAsync(Image image, string desti return false; } } - + + private static async Task CopyFileAsync(string sourceFilePath, string destinationFilePath) + { + const int bufferSize = 81920; // Domyślny rozmiar bufora + + // Upewnij się, że katalog docelowy istnieje + var destinationDirectory = Path.GetDirectoryName(destinationFilePath); + if (!string.IsNullOrEmpty(destinationDirectory) && !Directory.Exists(destinationDirectory)) + { + Directory.CreateDirectory(destinationDirectory); + } + + await using var sourceStream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, + bufferSize, useAsync: true); + await using var destinationStream = new FileStream(destinationFilePath, FileMode.Create, FileAccess.Write, + FileShare.None, bufferSize, useAsync: true); + await sourceStream.CopyToAsync(destinationStream); + } + private static string SanitizeImagePath(string imagePath) { // Zamień backslashes na slashe @@ -280,6 +315,7 @@ private static string SanitizeImagePath(string imagePath) // Pomijamy niebezpieczne segmenty continue; } + sanitizedSegments.Add(segment); } diff --git a/ChatAAC/ViewModels/ConfigViewModel.cs b/ChatAAC/ViewModels/ConfigViewModel.cs index d46822c..09d4a6c 100644 --- a/ChatAAC/ViewModels/ConfigViewModel.cs +++ b/ChatAAC/ViewModels/ConfigViewModel.cs @@ -1,9 +1,9 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Reactive; +using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; @@ -11,6 +11,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform.Storage; +using ChatAAC.Models; using OllamaSharp; using ReactiveUI; @@ -18,11 +19,39 @@ namespace ChatAAC.ViewModels { public class ConfigViewModel : ReactiveObject { + #region Singleton Implementation + private static ConfigViewModel? _instance; private static readonly object Lock = new(); + /// + /// Singleton instance of ConfigViewModel. + /// + public static ConfigViewModel Instance + { + get + { + if (_instance != null) return _instance; + lock (Lock) + { + _instance ??= new ConfigViewModel(); + } + + return _instance; + } + } + private string? _message; + public string? Message + { + get => _message; + set => this.RaiseAndSetIfChanged(ref _message, value); + } + #endregion + + #region Fields + private string _ollamaAddress = "http://localhost:11434"; - private string _selectedModel = string.Empty; + private string _selectedModel = "gemma2"; private bool _showSex; private bool _showViolence; private bool _showAac; @@ -30,96 +59,113 @@ public class ConfigViewModel : ReactiveObject private string? _selectedLanguage; private int _loadedIconsCount; - [JsonIgnore] - public ObservableCollection Models { get; } = new(); - [JsonIgnore] - public ObservableCollection Languages { get; } = new(); - [JsonIgnore] - public ObservableCollection BoardPaths { get; } = new(); - [JsonIgnore] - public ReactiveCommand SaveCommand { get; } - [JsonIgnore] - public ICommand AddBoardCommand { get; } - [JsonIgnore] - public ICommand RemoveBoardCommand { get; } - - private const string ConfigFilePath = "config.json"; - - // Properties + private string _defaultBoardPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "ChatAAC", + "communikate-20.obz"); + + private readonly string _configFilePath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ChatAAC", "config.json"); + + #endregion + + #region Properties + public string OllamaAddress { get => _ollamaAddress; - set => this.RaiseAndSetIfChanged(ref _ollamaAddress, value); + set => SetAndSave(ref _ollamaAddress, value); } public string SelectedModel { get => _selectedModel; - set => this.RaiseAndSetIfChanged(ref _selectedModel, value); + set => SetAndSave(ref _selectedModel, value); } public bool ShowSex { get => _showSex; - set => this.RaiseAndSetIfChanged(ref _showSex, value); + set => SetAndSave(ref _showSex, value); } public bool ShowViolence { get => _showViolence; - set => this.RaiseAndSetIfChanged(ref _showViolence, value); + set => SetAndSave(ref _showViolence, value); } public bool ShowAac { get => _showAac; - set => this.RaiseAndSetIfChanged(ref _showAac, value); + set => SetAndSave(ref _showAac, value); } public bool ShowSchematic { get => _showSchematic; - set => this.RaiseAndSetIfChanged(ref _showSchematic, value); + set => SetAndSave(ref _showSchematic, value); } public string? SelectedLanguage { get => _selectedLanguage; - set => this.RaiseAndSetIfChanged(ref _selectedLanguage, value); + set => SetAndSave(ref _selectedLanguage, value); } public int LoadedIconsCount { get => _loadedIconsCount; - set => this.RaiseAndSetIfChanged(ref _loadedIconsCount, value); + set => SetAndSave(ref _loadedIconsCount, value); } - public static ConfigViewModel Instance + public string DefaultBoardPath { - get - { - if (_instance != null) return _instance; - lock (Lock) - { - _instance ??= new ConfigViewModel(); - } - return _instance; - } + get => _defaultBoardPath; + set => SetAndSave(ref _defaultBoardPath, value); } - public ConfigViewModel() + [JsonIgnore] public ObservableCollection Models { get; } = []; + + [JsonIgnore] public ObservableCollection Languages { get; } = ["Polski", "English"]; + + [JsonIgnore] public ObservableCollection BoardPaths { get; } = []; + + #endregion + + #region Commands + + [JsonIgnore] public ReactiveCommand SaveCommand { get; } + + [JsonIgnore] public ICommand AddBoardCommand { get; } + + [JsonIgnore] public ICommand RemoveBoardCommand { get; } + + #endregion + + #region Constructor + + private ConfigViewModel() { LoadConfiguration(); NormalizeOllamaAddress(); + + // Initialize commands SaveCommand = ReactiveCommand.Create(SaveConfiguration); AddBoardCommand = ReactiveCommand.CreateFromTask(AddBoardPathAsync); RemoveBoardCommand = ReactiveCommand.Create(RemoveBoardPath); - InitializeData(); - if (string.IsNullOrEmpty(_selectedModel)) - _selectedModel = "gemma2"; + // Initialize models asynchronously + _ = InitializeModelsAsync(); } + #endregion + + #region Methods + + /// + /// Adds a board path to the list of board paths. + /// private async Task AddBoardPathAsync() { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) @@ -131,13 +177,13 @@ private async Task AddBoardPathAsync() { Title = "Wybierz plik tablicy AAC", AllowMultiple = false, - FileTypeFilter = new[] - { - new FilePickerFileType("Pliki OBZ") + FileTypeFilter = + [ + new FilePickerFileType("Pliki OBZ lub OBF") { - Patterns = new[] { "*.obz" } + Patterns = ["*.obz", "*.obf"] } - } + ] }); var file = files.FirstOrDefault(); @@ -152,6 +198,9 @@ private async Task AddBoardPathAsync() } } + /// + /// Removes a board path from the list of board paths. + /// private void RemoveBoardPath(string path) { if (BoardPaths.Contains(path)) @@ -160,6 +209,9 @@ private void RemoveBoardPath(string path) } } + /// + /// Normalizes the Ollama address to ensure it has the correct format. + /// private void NormalizeOllamaAddress() { if (!OllamaAddress.StartsWith("http")) @@ -169,19 +221,9 @@ private void NormalizeOllamaAddress() OllamaAddress += ":11434"; } - private void InitializeData() - { - Languages.Add("Polski"); - Languages.Add("English"); - - if (string.IsNullOrEmpty(DefaultBoardPath)) - { - DefaultBoardPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ChatAAC", "communikate-20.obz"); - } - - Task.Run(InitializeModelsAsync); - } - + /// + /// Initializes the list of models by fetching them from the Ollama API. + /// private async Task InitializeModelsAsync() { try @@ -202,77 +244,104 @@ private async Task InitializeModelsAsync() } } + /// + /// Loads the configuration from the config file. + /// private void LoadConfiguration() { - if (!File.Exists(ConfigFilePath)) return; - var json = File.ReadAllText(ConfigFilePath); - var options = new JsonSerializerOptions + if (!File.Exists(_configFilePath)) return; + try { - PropertyNameCaseInsensitive = true - }; - var config = JsonSerializer.Deserialize(json, options); - if (config == null) return; - OllamaAddress = config.OllamaAddress; - SelectedModel = config.SelectedModel; - ShowSex = config.ShowSex; - ShowViolence = config.ShowViolence; - ShowAac = config.ShowAac; - ShowSchematic = config.ShowSchematic; - SelectedLanguage = config.SelectedLanguage; - LoadedIconsCount = config.LoadedIconsCount; - DefaultBoardPath = config.DefaultBoardPath; - - BoardPaths.Clear(); - foreach (var path in config.BoardPaths) + var json = File.ReadAllText(_configFilePath); + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }; + var config = JsonSerializer.Deserialize(json, options); + if (config == null) return; + OllamaAddress = config.OllamaAddress; + SelectedModel = config.SelectedModel; + ShowSex = config.ShowSex; + ShowViolence = config.ShowViolence; + ShowAac = config.ShowAac; + ShowSchematic = config.ShowSchematic; + SelectedLanguage = config.SelectedLanguage ?? SelectedLanguage; + LoadedIconsCount = config.LoadedIconsCount; + DefaultBoardPath = config.DefaultBoardPath; + + BoardPaths.Clear(); + foreach (var path in config.BoardPaths.Where(path => !BoardPaths.Contains(path))) + { + BoardPaths.Add(path); + } + } + catch (Exception ex) { - BoardPaths.Add(path); + Console.WriteLine($"Error loading configuration: {ex.Message}"); } } + /// + /// Saves the current configuration to the config file. + /// private void SaveConfiguration() { - var configData = new ConfigData + try { - OllamaAddress = OllamaAddress, - SelectedModel = SelectedModel, - ShowSex = ShowSex, - ShowViolence = ShowViolence, - ShowAac = ShowAac, - ShowSchematic = ShowSchematic, - SelectedLanguage = SelectedLanguage, - LoadedIconsCount = LoadedIconsCount, - DefaultBoardPath = DefaultBoardPath, - BoardPaths = BoardPaths.ToList() - }; - - var options = new JsonSerializerOptions + var configData = new ConfigData + { + OllamaAddress = OllamaAddress, + SelectedModel = SelectedModel, + ShowSex = ShowSex, + ShowViolence = ShowViolence, + ShowAac = ShowAac, + ShowSchematic = ShowSchematic, + SelectedLanguage = SelectedLanguage, + LoadedIconsCount = LoadedIconsCount, + DefaultBoardPath = DefaultBoardPath, + BoardPaths = BoardPaths.ToList() + }; + + var options = new JsonSerializerOptions + { + WriteIndented = true + }; + var json = JsonSerializer.Serialize(configData, options); + File.WriteAllText(_configFilePath, json); + + // Wywołaj interakcję po zapisaniu konfiguracji + //CloseWindowInteraction.Handle(Unit.Default).Subscribe(); + } + catch (Exception ex) { - WriteIndented = true - }; - var json = JsonSerializer.Serialize(configData, options); - File.WriteAllText(ConfigFilePath, json); + Console.WriteLine($"Error saving configuration: {ex.Message}"); + } } - public string DefaultBoardPath { get; set; } = string.Empty; + /// + /// Helper method to set a property value and save configuration. + /// + private void SetAndSave(ref T field, T value, [CallerMemberName] string? propertyName = null) + { + this.RaiseAndSetIfChanged(ref field, value, propertyName); + } + /// + /// Updates the count of loaded icons. + /// public void UpdateLoadedIconsCount(int count) { LoadedIconsCount = count; - SaveConfiguration(); } - } - public class ConfigData - { - public string OllamaAddress { get; set; } = string.Empty; - public string SelectedModel { get; set; } = string.Empty; - public bool ShowSex { get; set; } - public bool ShowViolence { get; set; } - public bool ShowAac { get; set; } - public bool ShowSchematic { get; set; } - public string? SelectedLanguage { get; set; } - public int LoadedIconsCount { get; set; } - public string DefaultBoardPath { get; set; } = string.Empty; - public List BoardPaths { get; set; } = new(); + /// + /// Reloads settings from the configuration file. + /// + public void ReloadSettings() + { + LoadConfiguration(); + } + + #endregion } } \ No newline at end of file diff --git a/ChatAAC/ViewModels/MainViewModel.cs b/ChatAAC/ViewModels/MainViewModel.cs index c0edb58..4920b7f 100644 --- a/ChatAAC/ViewModels/MainViewModel.cs +++ b/ChatAAC/ViewModels/MainViewModel.cs @@ -25,7 +25,7 @@ namespace ChatAAC.ViewModels { - public class MainViewModel : ViewModelBase + public partial class MainViewModel : ViewModelBase { #region Fields @@ -46,6 +46,7 @@ public class MainViewModel : ViewModelBase private int _gridRows; private int _gridColumns; private bool _isInitialized; + private readonly string _historyFilePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ChatAAC", @@ -156,11 +157,16 @@ public int GridColumns public MainViewModel() { + + // Wczytujemy ustawienia + ConfigViewModel.Instance.ReloadSettings(); + + // Initialize TTS service based on the platform _ttsService = InitializeTtsService(); // Initialize commands - OpenSettingsCommand = ReactiveCommand.Create(OpenSettings); + OpenSettingsCommand = ReactiveCommand.Create(() => OpenSettings()); LoadMainBoardCommand = ReactiveCommand.CreateFromTask(LoadInitialFileAsync); ClearSelectedCommand = ReactiveCommand.Create(ClearSelected); ButtonClickedCommand = ReactiveCommand.CreateFromTask