Update AppBuilderExtension.cs && Fix Bug (#9483)

* Update AppBuilderExtension.cs

* Update OptionSettingWindow.axaml.cs

* Update OptionSettingWindow.axaml.cs

* Update Global.cs

* Rename ResUI.fa-Ir.resx to ResUI.fa.resx

* Update ServiceLib.csproj
This commit is contained in:
JieXu
2026-06-06 11:09:53 +08:00
committed by GitHub
parent eb9c974436
commit 4dc9c60b85
5 changed files with 52 additions and 13 deletions

View File

@@ -473,7 +473,7 @@ public class Global
"zh-Hans",
"zh-Hant",
"en",
"fa-Ir",
"fa",
"fr",
"ru",
"hu"

View File

@@ -1746,4 +1746,4 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="menuNewUpdate" xml:space="preserve">
<value>New Update</value>
</data>
</root>
</root>

View File

@@ -57,7 +57,7 @@
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<EmbeddedResource Update="Resx\ResUI.fa-Ir.resx">
<EmbeddedResource Update="Resx\ResUI.fa.resx">
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>

View File

@@ -2,24 +2,48 @@ namespace v2rayN.Desktop.Common;
public static class AppBuilderExtension
{
private static readonly string DefaultFontFamilyName =
Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
public static AppBuilder WithFontByDefault(this AppBuilder appBuilder)
{
var fallbacks = new List<FontFallback>();
var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC"));
fallbacks.Add(new FontFallback { FontFamily = notoSansSc });
var notoSansSc = new FontFamily(DefaultFontFamilyName);
if (OperatingSystem.IsLinux())
fallbacks.Add(new FontFallback
{
fallbacks.Add(new FontFallback
{
FontFamily = new FontFamily("Noto Color Emoji")
});
FontFamily = notoSansSc
});
if (OperatingSystem.IsWindows())
{
AddFontFallback(fallbacks, "Segoe UI Symbol");
AddFontFallback(fallbacks, "Segoe UI Emoji");
}
else if (OperatingSystem.IsMacOS())
{
AddFontFallback(fallbacks, "Apple Symbols");
AddFontFallback(fallbacks, "Apple Color Emoji");
}
else if (OperatingSystem.IsLinux())
{
AddFontFallback(fallbacks, "Noto Sans Symbols");
AddFontFallback(fallbacks, "Noto Color Emoji");
}
return appBuilder.With(new FontManagerOptions
{
DefaultFamilyName = DefaultFontFamilyName,
FontFallbacks = fallbacks.ToArray()
});
}
private static void AddFontFallback(List<FontFallback> fallbacks, string fontFamilyName)
{
fallbacks.Add(new FontFallback
{
FontFamily = new FontFamily(fontFamilyName)
});
}
}

View File

@@ -1,3 +1,4 @@
using Avalonia.Media;
using v2rayN.Desktop.Base;
using v2rayN.Desktop.Common;
@@ -88,7 +89,6 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
this.Bind(ViewModel, vm => vm.EnableStatistics, v => v.togEnableStatistics.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.DisplayRealTimeSpeed, v => v.togDisplayRealTimeSpeed.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KeepOlderDedupl, v => v.togKeepOlderDedupl.IsChecked).DisposeWith(disposables);
//this.Bind(ViewModel, vm => vm.EnableAutoAdjustMainLvColWidth, v => v.togEnableAutoAdjustMainLvColWidth.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoHideStartup, v => v.togAutoHideStartup.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Hide2TrayWhenClose, v => v.togHide2TrayWhenClose.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MacOSShowInDock, v => v.togMacOSShowInDock.IsChecked).DisposeWith(disposables);
@@ -166,9 +166,10 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
var lstFonts = new List<string>();
try
{
var lst = Avalonia.Media.FontManager.Current.SystemFonts
var lst = FontManager.Current.SystemFonts
.Select(t => t.Name)
.Where(t => t.IsNotEmpty())
.Append(GetDefaultFontFamilyName())
.Where(IsInstalledFontFamilyName)
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(t => t)
.ToList();
@@ -181,6 +182,20 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
return lstFonts;
}
private static string GetDefaultFontFamilyName() => "Noto Sans SC";
private static bool IsInstalledFontFamilyName(string fontFamilyName)
{
return fontFamilyName.IsNotEmpty()
&& !IsCssFontFamilyAlias(fontFamilyName);
}
private static bool IsCssFontFamilyAlias(string fontFamilyName)
{
return fontFamilyName.StartsWith("-", StringComparison.Ordinal)
|| fontFamilyName.Equals("BlinkMacSystemFont", StringComparison.OrdinalIgnoreCase);
}
private void ClbdestOverride_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (ViewModel != null)