diff --git a/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs b/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs index 6e2e7b33..1b0bd8fa 100644 --- a/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs +++ b/v2rayN/v2rayN.Desktop/Common/AppBuilderExtension.cs @@ -1,68 +1,20 @@ -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) { - public static AppBuilder WithFontByDefault(this AppBuilder appBuilder) + var fallbacks = new List(); + + var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC")); + fallbacks.Add(new FontFallback { FontFamily = notoSansSc }); + + if (OperatingSystem.IsLinux()) { - var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC")); - - var fallbacks = new List + fallbacks.Add(new FontFallback { - 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() + FontFamily = new FontFamily("Noto Color Emoji") }); } - private static string? DetectLinuxEmojiFamily() + return appBuilder.With(new FontManagerOptions { - 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; - } - } + FontFallbacks = fallbacks.ToArray() + }); }