mirror of
https://github.com/2dust/v2rayN.git
synced 2025-12-13 18:32:42 +00:00
Update AppBuilderExtension.cs
This commit is contained in:
parent
2ebd2b28a8
commit
a0718fc4f8
1 changed files with 58 additions and 4 deletions
|
|
@ -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;
|
namespace v2rayN.Desktop.Common;
|
||||||
|
|
||||||
public static class AppBuilderExtension
|
public static class AppBuilderExtension
|
||||||
{
|
{
|
||||||
public static AppBuilder WithFontByDefault(this AppBuilder appBuilder)
|
public static AppBuilder WithFontByDefault(this AppBuilder appBuilder)
|
||||||
{
|
{
|
||||||
var uri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
|
var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC"));
|
||||||
return appBuilder.With(new FontManagerOptions()
|
|
||||||
|
var fallbacks = new List<FontFallback>
|
||||||
{
|
{
|
||||||
//DefaultFamilyName = uri,
|
new() { FontFamily = notoSansSc }
|
||||||
FontFallbacks = new[] { new FontFallback { FontFamily = new FontFamily(uri) } }
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue