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
+1 -1
View File
@@ -473,7 +473,7 @@ public class Global
"zh-Hans", "zh-Hans",
"zh-Hant", "zh-Hant",
"en", "en",
"fa-Ir", "fa",
"fr", "fr",
"ru", "ru",
"hu" "hu"
@@ -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"> <data name="menuNewUpdate" xml:space="preserve">
<value>New Update</value> <value>New Update</value>
</data> </data>
</root> </root>
+1 -1
View File
@@ -57,7 +57,7 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
</Compile> </Compile>
<EmbeddedResource Update="Resx\ResUI.fa-Ir.resx"> <EmbeddedResource Update="Resx\ResUI.fa.resx">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator> <Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource> </EmbeddedResource>
@@ -2,24 +2,48 @@ namespace v2rayN.Desktop.Common;
public static class AppBuilderExtension public static class AppBuilderExtension
{ {
private static readonly string DefaultFontFamilyName =
Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
public static AppBuilder WithFontByDefault(this AppBuilder appBuilder) public static AppBuilder WithFontByDefault(this AppBuilder appBuilder)
{ {
var fallbacks = new List<FontFallback>(); var fallbacks = new List<FontFallback>();
var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC")); var notoSansSc = new FontFamily(DefaultFontFamilyName);
fallbacks.Add(new FontFallback { FontFamily = notoSansSc });
if (OperatingSystem.IsLinux()) fallbacks.Add(new FontFallback
{ {
fallbacks.Add(new FontFallback FontFamily = notoSansSc
{ });
FontFamily = new FontFamily("Noto Color Emoji")
}); 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 return appBuilder.With(new FontManagerOptions
{ {
DefaultFamilyName = DefaultFontFamilyName,
FontFallbacks = fallbacks.ToArray() FontFallbacks = fallbacks.ToArray()
}); });
} }
private static void AddFontFallback(List<FontFallback> fallbacks, string fontFamilyName)
{
fallbacks.Add(new FontFallback
{
FontFamily = new FontFamily(fontFamilyName)
});
}
} }
@@ -1,3 +1,4 @@
using Avalonia.Media;
using v2rayN.Desktop.Base; using v2rayN.Desktop.Base;
using v2rayN.Desktop.Common; 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.EnableStatistics, v => v.togEnableStatistics.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.DisplayRealTimeSpeed, v => v.togDisplayRealTimeSpeed.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.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.AutoHideStartup, v => v.togAutoHideStartup.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Hide2TrayWhenClose, v => v.togHide2TrayWhenClose.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); 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>(); var lstFonts = new List<string>();
try try
{ {
var lst = Avalonia.Media.FontManager.Current.SystemFonts var lst = FontManager.Current.SystemFonts
.Select(t => t.Name) .Select(t => t.Name)
.Where(t => t.IsNotEmpty()) .Append(GetDefaultFontFamilyName())
.Where(IsInstalledFontFamilyName)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(t => t) .OrderBy(t => t)
.ToList(); .ToList();
@@ -181,6 +182,20 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
return lstFonts; 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) private void ClbdestOverride_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{ {
if (ViewModel != null) if (ViewModel != null)