From c808d62188024ebc8f46b6a1abe3375709a30020 Mon Sep 17 00:00:00 2001 From: Exest Date: Thu, 13 Aug 2026 16:21:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=202.0.8:?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20=D1=88=D1=80=D0=B8=D1=84?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D0=B0=20=D0=B2=20=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Настройки: выпадающий список «Шрифт» со всеми системными шрифтами (+ «По умолчанию»), с превью каждого шрифта в себе самом - шрифт применяется ко всему приложению (ресурс AppFontFamily + стиль Window), сохраняется и восстанавливается при старте Co-Authored-By: Claude Opus 4.8 --- installer/ElfisaPharmacy.iss | 2 +- src/Elfisa.Avalonia/App.axaml | 7 ++++++ src/Elfisa.Avalonia/App.axaml.cs | 14 ++++++++++++ src/Elfisa.Avalonia/Elfisa.Avalonia.csproj | 6 ++--- .../ViewModels/SettingsViewModel.cs | 22 +++++++++++++++++++ .../Views/SettingsWindow.axaml | 14 +++++++++++- .../Views/SettingsWindow.axaml.cs | 3 +++ src/Elfisa.Core/SettingsStore.cs | 1 + 8 files changed, 64 insertions(+), 5 deletions(-) diff --git a/installer/ElfisaPharmacy.iss b/installer/ElfisaPharmacy.iss index 768fc1b..5a6c953 100644 --- a/installer/ElfisaPharmacy.iss +++ b/installer/ElfisaPharmacy.iss @@ -3,7 +3,7 @@ #define MyAppName "Электронная Фармация" #define MyAppBrand "ЭльФиСА" -#define MyAppVersion "2.0.7" +#define MyAppVersion "2.0.8" #define MyAppPublisher "PharmData" #define MyAppURL "https://cdn.24pharmdata.ru" #define MyAppSupportURL "https://24pharmdata.ru" diff --git a/src/Elfisa.Avalonia/App.axaml b/src/Elfisa.Avalonia/App.axaml index dd9e0f1..c2a57d4 100644 --- a/src/Elfisa.Avalonia/App.axaml +++ b/src/Elfisa.Avalonia/App.axaml @@ -41,11 +41,18 @@ + + + Segoe UI + + diff --git a/src/Elfisa.Avalonia/App.axaml.cs b/src/Elfisa.Avalonia/App.axaml.cs index cecd0c5..52ec1c3 100644 --- a/src/Elfisa.Avalonia/App.axaml.cs +++ b/src/Elfisa.Avalonia/App.axaml.cs @@ -4,6 +4,7 @@ using Avalonia.Data.Core; using Avalonia.Data.Core.Plugins; using System.Linq; using Avalonia.Markup.Xaml; +using Avalonia.Media; using Elfisa.Avalonia.ViewModels; using Elfisa.Avalonia.Views; @@ -11,17 +12,30 @@ namespace Elfisa.Avalonia; public partial class App : Application { + /// Дефолтный шрифт интерфейса (когда «По умолчанию»). + public const string DefaultFont = "Segoe UI"; + public override void Initialize() { AvaloniaXamlLoader.Load(this); } + /// Применяет шрифт ко всему приложению (ресурс наследуется всеми окнами). + public static void ApplyFont(string? name) + { + var family = string.IsNullOrWhiteSpace(name) ? DefaultFont : name!; + if (Current is { } app) + app.Resources["AppFontFamily"] = new FontFamily(family); + } + public override void OnFrameworkInitializationCompleted() { RequestedThemeVariant = Elfisa.Core.SettingsStore.Current.Theme == "Dark" ? global::Avalonia.Styling.ThemeVariant.Dark : global::Avalonia.Styling.ThemeVariant.Light; + ApplyFont(Elfisa.Core.SettingsStore.Current.FontFamily); + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow diff --git a/src/Elfisa.Avalonia/Elfisa.Avalonia.csproj b/src/Elfisa.Avalonia/Elfisa.Avalonia.csproj index fa58a39..30e2be0 100644 --- a/src/Elfisa.Avalonia/Elfisa.Avalonia.csproj +++ b/src/Elfisa.Avalonia/Elfisa.Avalonia.csproj @@ -5,9 +5,9 @@ enable app.manifest true - 2.0.7 - 2.0.7.0 - 2.0.7.0 + 2.0.8 + 2.0.8.0 + 2.0.8.0 ЭльФиСА — Электронная Фармация PharmData diff --git a/src/Elfisa.Avalonia/ViewModels/SettingsViewModel.cs b/src/Elfisa.Avalonia/ViewModels/SettingsViewModel.cs index 61db261..03ccaf9 100644 --- a/src/Elfisa.Avalonia/ViewModels/SettingsViewModel.cs +++ b/src/Elfisa.Avalonia/ViewModels/SettingsViewModel.cs @@ -2,6 +2,7 @@ using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; +using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; using Elfisa.Core; @@ -11,10 +12,17 @@ public partial class SettingsViewModel : ViewModelBase { private readonly ApiClient _api = new(); + /// Пункт «По умолчанию» в списке шрифтов. + public const string DefaultFontLabel = "По умолчанию"; + [ObservableProperty] private string _apiBaseUrl = ""; public string[] Themes { get; } = { "Светлая", "Тёмная" }; [ObservableProperty] private int _themeIndex; + /// Все системные шрифты + «По умолчанию» первым. + public ObservableCollection Fonts { get; } = new(); + [ObservableProperty] private string _selectedFont = DefaultFontLabel; + public ObservableCollection Locations { get; } = new(); [ObservableProperty] private BuyerLocationDto? _selectedLocation; @@ -23,6 +31,20 @@ public partial class SettingsViewModel : ViewModelBase _api.SetToken(Session.Current.Token); ApiBaseUrl = SettingsStore.Current.ApiBaseUrl ?? AppConfig.DefaultApiBaseUrl; ThemeIndex = SettingsStore.Current.Theme == "Dark" ? 1 : 0; + + Fonts.Add(DefaultFontLabel); + foreach (var f in FontManager.Current.SystemFonts + .Select(x => x.Name) + .Where(n => !string.IsNullOrWhiteSpace(n)) + .Distinct() + .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase)) + Fonts.Add(f); + + var saved = SettingsStore.Current.FontFamily; + SelectedFont = !string.IsNullOrWhiteSpace(saved) && Fonts.Contains(saved!) + ? saved! + : DefaultFontLabel; + if (Session.Current.IsAuthenticated) _ = LoadLocationsAsync(); } diff --git a/src/Elfisa.Avalonia/Views/SettingsWindow.axaml b/src/Elfisa.Avalonia/Views/SettingsWindow.axaml index d350377..243588a 100644 --- a/src/Elfisa.Avalonia/Views/SettingsWindow.axaml +++ b/src/Elfisa.Avalonia/Views/SettingsWindow.axaml @@ -3,7 +3,7 @@ xmlns:vm="using:Elfisa.Avalonia.ViewModels" x:Class="Elfisa.Avalonia.Views.SettingsWindow" x:DataType="vm:SettingsViewModel" - Width="460" Height="440" CanResize="False" + Width="460" Height="520" CanResize="False" WindowStartupLocation="CenterOwner" Background="{DynamicResource Bg}" Title="Настройки"> @@ -21,6 +21,18 @@ + + + + + + + + + + + diff --git a/src/Elfisa.Avalonia/Views/SettingsWindow.axaml.cs b/src/Elfisa.Avalonia/Views/SettingsWindow.axaml.cs index f867800..05f1cf9 100644 --- a/src/Elfisa.Avalonia/Views/SettingsWindow.axaml.cs +++ b/src/Elfisa.Avalonia/Views/SettingsWindow.axaml.cs @@ -42,11 +42,14 @@ public partial class SettingsWindow : Window { SettingsStore.Current.ApiBaseUrl = string.IsNullOrWhiteSpace(vm.ApiBaseUrl) ? null : vm.ApiBaseUrl.Trim().TrimEnd('/'); SettingsStore.Current.Theme = vm.ThemeIndex == 1 ? "Dark" : "Light"; + var font = vm.SelectedFont == SettingsViewModel.DefaultFontLabel ? null : vm.SelectedFont; + SettingsStore.Current.FontFamily = font; SettingsStore.Current.DefaultLocationId = vm.SelectedLocation?.BuyerLocationId; SettingsStore.Save(); if (Application.Current is { } app) app.RequestedThemeVariant = vm.ThemeIndex == 1 ? ThemeVariant.Dark : ThemeVariant.Light; + App.ApplyFont(font); // применяем сразу ко всем окнам } Close(); } diff --git a/src/Elfisa.Core/SettingsStore.cs b/src/Elfisa.Core/SettingsStore.cs index c0a1364..f504da1 100644 --- a/src/Elfisa.Core/SettingsStore.cs +++ b/src/Elfisa.Core/SettingsStore.cs @@ -6,6 +6,7 @@ public sealed class AppSettings { public string? ApiBaseUrl { get; set; } public string Theme { get; set; } = "Light"; // Light | Dark + public string? FontFamily { get; set; } // шрифт интерфейса (null = по умолчанию) public string? DefaultLocationId { get; set; } public string? Token { get; set; } // сохранённая сессия public string? Role { get; set; }