55using System . Text . Json . Serialization ;
66
77using Avalonia . Collections ;
8+ using Avalonia . Media ;
89
910using CommunityToolkit . Mvvm . ComponentModel ;
1011
@@ -38,6 +39,16 @@ public static Preference Instance
3839
3940 _instance . Repositories . RemoveAll ( x => ! Directory . Exists ( x . FullPath ) ) ;
4041
42+ if ( _instance . DefaultFont == null )
43+ {
44+ _instance . DefaultFont = FontManager . Current . DefaultFontFamily ;
45+ }
46+
47+ if ( _instance . MonospaceFont == null )
48+ {
49+ _instance . MonospaceFont = new FontFamily ( "fonts:SourceGit#JetBrains Mono" ) ;
50+ }
51+
4152 if ( ! _instance . IsGitConfigured )
4253 {
4354 _instance . GitInstallPath = Native . OS . FindGitExecutable ( ) ;
@@ -71,13 +82,15 @@ public string Theme
7182 }
7283 }
7384
74- public string DefaultFont
85+ [ JsonConverter ( typeof ( FontFamilyConverter ) ) ]
86+ public FontFamily DefaultFont
7587 {
7688 get => _defaultFont ;
7789 set => SetProperty ( ref _defaultFont , value ) ;
7890 }
7991
80- public string MonospaceFont
92+ [ JsonConverter ( typeof ( FontFamilyConverter ) ) ]
93+ public FontFamily MonospaceFont
8194 {
8295 get => _monospaceFont ;
8396 set => SetProperty ( ref _monospaceFont , value ) ;
@@ -364,8 +377,8 @@ private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<Reposi
364377
365378 private string _locale = "en_US" ;
366379 private string _theme = "Default" ;
367- private string _defaultFont = string . Empty ;
368- private string _monospaceFont = "fonts:SourceGit#JetBrains Mono" ;
380+ private FontFamily _defaultFont = null ;
381+ private FontFamily _monospaceFont = null ;
369382
370383 private int _maxHistoryCommits = 20000 ;
371384 private bool _restoreTabs = false ;
@@ -388,6 +401,20 @@ private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<Reposi
388401 private AvaloniaList < RepositoryNode > _repositoryNodes = new AvaloniaList < RepositoryNode > ( ) ;
389402 }
390403
404+ public class FontFamilyConverter : JsonConverter < FontFamily >
405+ {
406+ public override FontFamily Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
407+ {
408+ var name = reader . GetString ( ) ;
409+ return new FontFamily ( name ) ;
410+ }
411+
412+ public override void Write ( Utf8JsonWriter writer , FontFamily value , JsonSerializerOptions options )
413+ {
414+ writer . WriteStringValue ( value . ToString ( ) ) ;
415+ }
416+ }
417+
391418 [ JsonSourceGenerationOptions ( WriteIndented = true , IgnoreReadOnlyFields = true , IgnoreReadOnlyProperties = true ) ]
392419 [ JsonSerializable ( typeof ( Preference ) ) ]
393420 internal partial class JsonSerializationCodeGen : JsonSerializerContext { }
0 commit comments