Fix Font NullReferenceException

This commit is contained in:
2023-02-22 17:47:12 +01:00
parent 3db5945cfd
commit 28bc479ee4
2 changed files with 6 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ namespace FileTime.GuiApp.Services;
public class FontService : IFontService
{
private readonly IOptionsMonitor<FontConfiguration> _fontConfiguration;
private readonly BehaviorSubject<string?> _mainFont = new(null);
public IObservable<string?> MainFont => _mainFont.DistinctUntilChanged();
@@ -17,7 +17,7 @@ public class FontService : IFontService
{
_fontConfiguration = fontConfiguration;
fontConfiguration.OnChange(UpdateFonts);
UpdateFonts(fontConfiguration.CurrentValue, null);
}
@@ -29,6 +29,6 @@ public class FontService : IFontService
public string? GetMainFont()
{
var installedFonts = FontManager.Current.GetInstalledFontFamilyNames().ToList();
return _fontConfiguration.CurrentValue.Main.FirstOrDefault(f => installedFonts.Contains(f));
return _fontConfiguration.CurrentValue.Main.Find(installedFonts.Contains);
}
}