Update AppBuilderExtension.cs

This commit is contained in:
JieXu 2025-11-17 23:15:07 +08:00 committed by GitHub
parent 036dda7a11
commit a660409f06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using Avalonia.Media; using Avalonia.Media;
namespace v2rayN.Desktop.Common; namespace v2rayN.Desktop.Common;
@ -18,20 +17,24 @@ public static class AppBuilderExtension
{ {
FontFallbacks = new[] FontFallbacks = new[]
{ {
new FontFallback new FontFallback { FontFamily = new FontFamily(uri) }
{
FontFamily = new FontFamily(uri)
}
} }
}); });
} }
var fallbacks = new List<FontFallback>(); var fallbacks = new List<FontFallback>();
var emojiFamily = DetectFontFamily("emoji"); string? zhFamily = RunFcMatchFamily("sans:lang=zh-cn");
if (!string.IsNullOrWhiteSpace(zhFamily))
{
fallbacks.Add(new FontFallback
{
FontFamily = new FontFamily(zhFamily)
});
}
if (!string.IsNullOrWhiteSpace(emojiFamily) && string? emojiFamily = RunFcMatchFamily("emoji");
emojiFamily.Contains("Noto Color Emoji", StringComparison.OrdinalIgnoreCase)) if (!string.IsNullOrWhiteSpace(emojiFamily))
{ {
fallbacks.Add(new FontFallback fallbacks.Add(new FontFallback
{ {
@ -39,10 +42,10 @@ public static class AppBuilderExtension
}); });
} }
var notoScUri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC"); var notoUri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
fallbacks.Add(new FontFallback fallbacks.Add(new FontFallback
{ {
FontFamily = new FontFamily(notoScUri) FontFamily = new FontFamily(notoUri)
}); });
return appBuilder.With(new FontManagerOptions return appBuilder.With(new FontManagerOptions
@ -51,7 +54,7 @@ public static class AppBuilderExtension
}); });
} }
private static string? DetectFontFamily(string pattern) private static string? RunFcMatchFamily(string pattern)
{ {
try try
{ {
@ -61,10 +64,10 @@ public static class AppBuilderExtension
ArgumentList = ArgumentList =
{ {
"-c", "-c",
$"fc-match -f \"%{{family}}\\n\" \"{pattern}\" | head -n 1" $"fc-match -f \"%{{family[0]}}\\n\" \"{pattern}\" | head -n 1"
}, },
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = false,
UseShellExecute = false UseShellExecute = false
}; };
@ -72,15 +75,8 @@ public static class AppBuilderExtension
if (p == null) if (p == null)
return null; return null;
p.WaitForExit(2000); var output = p.StandardOutput.ReadToEnd().Trim();
return string.IsNullOrWhiteSpace(output) ? null : output;
var output = p.StandardOutput.ReadToEnd();
var family = output
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault()
?.Trim();
return string.IsNullOrWhiteSpace(family) ? null : family;
} }
catch catch
{ {