11using System ;
22using System . IO ;
3+ using System . Linq ;
34using System . Net . Http ;
45using System . Text . Json ;
56using System . Threading . Tasks ;
6-
77using Avalonia ;
88using Avalonia . Controls ;
99using Avalonia . Controls . ApplicationLifetimes ;
1414using Avalonia . Platform ;
1515using Avalonia . Styling ;
1616using Avalonia . Threading ;
17+ using SourceGit . Models ;
1718
1819namespace SourceGit
1920{
2021 public partial class App : Application
2122 {
2223 #region App Entry Point
24+
2325 [ STAThread ]
2426 public static void Main ( string [ ] args )
2527 {
@@ -56,10 +58,7 @@ public static AppBuilder BuildAvaloniaApp()
5658 builder . UsePlatformDetect ( ) ;
5759 builder . LogToTrace ( ) ;
5860 builder . WithInterFont ( ) ;
59- builder . With ( new FontManagerOptions ( )
60- {
61- DefaultFamilyName = "fonts:Inter#Inter"
62- } ) ;
61+ builder . With ( new FontManagerOptions ( ) { DefaultFamilyName = "fonts:Inter#Inter" } ) ;
6362 builder . ConfigureFonts ( manager =>
6463 {
6564 var monospace = new EmbeddedFontCollection (
@@ -71,9 +70,11 @@ public static AppBuilder BuildAvaloniaApp()
7170 Native . OS . SetupApp ( builder ) ;
7271 return builder ;
7372 }
73+
7474 #endregion
7575
7676 #region Utility Functions
77+
7778 public static async Task < bool > AskConfirmAsync ( string message , Models . ConfirmButtonType buttonType = Models . ConfirmButtonType . OkCancel )
7879 {
7980 if ( Current ? . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow : { } owner } )
@@ -117,17 +118,21 @@ app.Resources[finalLocaleKey] is not ResourceDictionary targetLocale ||
117118 app . _activeLocale = targetLocale ;
118119 }
119120
120- public static void SetTheme ( string theme , string themeOverridesFile )
121+ public static void SetTheme ( ThemeOverrides theme )
121122 {
122123 if ( Current is not App app )
123124 return ;
124125
125- if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
126+ string themeOverridesFile = string . Empty ;
127+
128+ if ( theme . Name . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
126129 app . RequestedThemeVariant = ThemeVariant . Light ;
127- else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
130+ else if ( theme . Name . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
128131 app . RequestedThemeVariant = ThemeVariant . Dark ;
129- else
132+ else if ( theme . Name . Equals ( "Default" , StringComparison . OrdinalIgnoreCase ) )
130133 app . RequestedThemeVariant = ThemeVariant . Default ;
134+ else
135+ themeOverridesFile = theme . FilePath ;
131136
132137 if ( app . _themeOverrides != null )
133138 {
@@ -234,16 +239,18 @@ public static void Quit(int exitCode)
234239 else
235240 Environment . Exit ( exitCode ) ;
236241 }
242+
237243 #endregion
238244
239245 #region Overrides
246+
240247 public override void Initialize ( )
241248 {
242249 AvaloniaXamlLoader . Load ( this ) ;
243250
244251 var pref = ViewModels . Preferences . Instance ;
245252 SetLocale ( pref . Locale ) ;
246- SetTheme ( pref . Theme , pref . ThemeOverrides ) ;
253+ SetTheme ( pref . Themes . FirstOrDefault ( m => m . Name == pref . Theme ) ?? new ThemeOverrides ( "Default" ) ) ;
247254 SetFonts ( pref . DefaultFontFamily , pref . MonospaceFontFamily ) ;
248255 }
249256
@@ -276,9 +283,11 @@ public override void OnFrameworkInitializationCompleted()
276283 TryLaunchAsNormal ( desktop ) ;
277284 }
278285 }
286+
279287 #endregion
280288
281289 #region Launch Ways
290+
282291 private static bool TryLaunchAsRebaseTodoEditor ( string [ ] args , out int exitCode )
283292 {
284293 exitCode = - 1 ;
@@ -362,17 +371,11 @@ private bool TryLaunchAsFileHistoryViewer(IClassicDesktopStyleApplicationLifetim
362371 var relativePath = Path . GetRelativePath ( repo , fullPath ) . Replace ( '\\ ' , '/' ) ;
363372 if ( File . Exists ( fullPath ) )
364373 {
365- desktop . MainWindow = new Views . FileHistories ( )
366- {
367- DataContext = new ViewModels . FileHistories ( repo , relativePath )
368- } ;
374+ desktop . MainWindow = new Views . FileHistories ( ) { DataContext = new ViewModels . FileHistories ( repo , relativePath ) } ;
369375 }
370376 else if ( Directory . Exists ( fullPath ) )
371377 {
372- desktop . MainWindow = new Views . DirHistories ( )
373- {
374- DataContext = new ViewModels . DirHistories ( repo , relativePath . TrimEnd ( '/' ) )
375- } ;
378+ desktop . MainWindow = new Views . DirHistories ( ) { DataContext = new ViewModels . DirHistories ( repo , relativePath . TrimEnd ( '/' ) ) } ;
376379 }
377380 else
378381 {
@@ -410,10 +413,7 @@ private bool TryLaunchAsBlameViewer(IClassicDesktopStyleApplicationLifetime desk
410413 }
411414
412415 var relFile = Path . GetRelativePath ( repo , file ) ;
413- var viewer = new Views . Blame ( )
414- {
415- DataContext = new ViewModels . Blame ( repo , relFile , head )
416- } ;
416+ var viewer = new Views . Blame ( ) { DataContext = new ViewModels . Blame ( repo , relFile , head ) } ;
417417 desktop . MainWindow = viewer ;
418418 return true ;
419419 }
@@ -532,9 +532,11 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
532532 Check4Update ( ) ;
533533#endif
534534 }
535+
535536 #endregion
536537
537538 #region Check for Updates
539+
538540 private void Check4Update ( bool manually = false )
539541 {
540542 if ( _launcher != null )
@@ -595,6 +597,7 @@ private void ShowSelfUpdateResult(object data)
595597 // Ignore exceptions.
596598 }
597599 }
600+
598601 #endregion
599602
600603 private Models . IpcChannel _ipcChannel = null ;
0 commit comments