From a0718fc4f86a72e9d287d0ccf364824c9518199e Mon Sep 17 00:00:00 2001 From: JieXu Date: Tue, 18 Nov 2025 19:11:35 +0800 Subject: [PATCH] Update AppBuilderExtension.cs --- .../Common/AppBuilderExtension.cs | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs b/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs index c0702938..6e2e7b33 100644 --- a/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs +++ b/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs @@ -1,14 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using Avalonia; +using Avalonia.Media; + namespace v2rayN.Desktop.Common; public static class AppBuilderExtension { public static AppBuilder WithFontByDefault(this AppBuilder appBuilder) { - var uri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC"); - return appBuilder.With(new FontManagerOptions() + var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC")); + + var fallbacks = new List { - //DefaultFamilyName = uri, - FontFallbacks = new[] { new FontFallback { FontFamily = new FontFamily(uri) } } + new() { FontFamily = notoSansSc } + }; + + if (OperatingSystem.IsLinux()) + { + var emojiFamily = DetectLinuxEmojiFamily(); + if (!string.IsNullOrWhiteSpace(emojiFamily)) + { + fallbacks.Add(new FontFallback + { + FontFamily = new FontFamily(emojiFamily) + }); + } + } + + return appBuilder.With(new FontManagerOptions + { + FontFallbacks = fallbacks.ToArray() }); } + + private static string? DetectLinuxEmojiFamily() + { + try + { + var psi = new ProcessStartInfo + { + FileName = "/bin/bash", + ArgumentList = + { + "-c", + "fc-match -f \"%{family[0]}\\n\" \"emoji\" | head -n 1" + }, + RedirectStandardOutput = true, + RedirectStandardError = false, + UseShellExecute = false + }; + + using var p = Process.Start(psi); + if (p == null) + return null; + + var output = p.StandardOutput.ReadToEnd().Trim(); + return string.IsNullOrWhiteSpace(output) ? null : output; + } + catch + { + return null; + } + } }