@@ -22,6 +22,7 @@ namespace SourceGit
2222{
2323 public partial class App : Application
2424 {
25+ #region App Entry Point
2526 [ STAThread ]
2627 public static void Main ( string [ ] args )
2728 {
@@ -74,35 +75,9 @@ public static AppBuilder BuildAvaloniaApp()
7475 Native . OS . SetupApp ( builder ) ;
7576 return builder ;
7677 }
78+ #endregion
7779
78- public override void Initialize ( )
79- {
80- AvaloniaXamlLoader . Load ( this ) ;
81-
82- var pref = ViewModels . Preference . Instance ;
83- pref . PropertyChanged += ( _ , _ ) => pref . Save ( ) ;
84-
85- SetLocale ( pref . Locale ) ;
86- SetTheme ( pref . Theme , pref . ThemeOverrides ) ;
87- SetFonts ( pref . DefaultFontFamily , pref . MonospaceFontFamily , pref . OnlyUseMonoFontInEditor ) ;
88- }
89-
90- public override void OnFrameworkInitializationCompleted ( )
91- {
92- if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
93- {
94- BindingPlugins . DataValidators . RemoveAt ( 0 ) ;
95-
96- if ( TryLaunchedAsCoreEditor ( desktop ) )
97- return ;
98-
99- if ( TryLaunchedAsAskpass ( desktop ) )
100- return ;
101-
102- TryLaunchedAsNormal ( desktop ) ;
103- }
104- }
105-
80+ #region Utility Functions
10681 public static void OpenDialog ( Window window )
10782 {
10883 if ( Current ? . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow : { } owner } )
@@ -304,21 +279,6 @@ public static ViewModels.Launcher GetLauncer()
304279 return Current is App app ? app . _launcher : null ;
305280 }
306281
307- public static ViewModels . Repository FindOpenedRepository ( string repoPath )
308- {
309- if ( Current is App app && app . _launcher != null )
310- {
311- foreach ( var page in app . _launcher . Pages )
312- {
313- var id = page . Node . Id . Replace ( "\\ " , "/" ) ;
314- if ( id == repoPath && page . Data is ViewModels . Repository repo )
315- return repo ;
316- }
317- }
318-
319- return null ;
320- }
321-
322282 public static void Quit ( int exitCode )
323283 {
324284 if ( Current ? . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
@@ -331,18 +291,38 @@ public static void Quit(int exitCode)
331291 Environment . Exit ( exitCode ) ;
332292 }
333293 }
294+ #endregion
334295
335- private static void CopyTextBlock ( TextBlock textBlock )
296+ #region Overrides
297+ public override void Initialize ( )
336298 {
337- if ( textBlock == null )
338- return ;
299+ AvaloniaXamlLoader . Load ( this ) ;
339300
340- if ( textBlock . Inlines is { Count : > 0 } inlines )
341- CopyText ( inlines . Text ) ;
342- else if ( ! string . IsNullOrEmpty ( textBlock . Text ) )
343- CopyText ( textBlock . Text ) ;
301+ var pref = ViewModels . Preference . Instance ;
302+ pref . PropertyChanged += ( _ , _ ) => pref . Save ( ) ;
303+
304+ SetLocale ( pref . Locale ) ;
305+ SetTheme ( pref . Theme , pref . ThemeOverrides ) ;
306+ SetFonts ( pref . DefaultFontFamily , pref . MonospaceFontFamily , pref . OnlyUseMonoFontInEditor ) ;
344307 }
345308
309+ public override void OnFrameworkInitializationCompleted ( )
310+ {
311+ if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
312+ {
313+ BindingPlugins . DataValidators . RemoveAt ( 0 ) ;
314+
315+ if ( TryLaunchedAsCoreEditor ( desktop ) )
316+ return ;
317+
318+ if ( TryLaunchedAsAskpass ( desktop ) )
319+ return ;
320+
321+ TryLaunchedAsNormal ( desktop ) ;
322+ }
323+ }
324+ #endregion
325+
346326 private static void LogException ( Exception ex )
347327 {
348328 if ( ex == null )
@@ -369,55 +349,6 @@ private static void LogException(Exception ex)
369349 File . WriteAllText ( file , builder . ToString ( ) ) ;
370350 }
371351
372- private static void Check4Update ( bool manually = false )
373- {
374- Task . Run ( async ( ) =>
375- {
376- try
377- {
378- // Fetch lastest release information.
379- var client = new HttpClient ( ) { Timeout = TimeSpan . FromSeconds ( 5 ) } ;
380- var data = await client . GetStringAsync ( "https://sourcegit-scm.github.io/data/version.json" ) ;
381-
382- // Parse json into Models.Version.
383- var ver = JsonSerializer . Deserialize ( data , JsonCodeGen . Default . Version ) ;
384- if ( ver == null )
385- return ;
386-
387- // Check if already up-to-date.
388- if ( ! ver . IsNewVersion )
389- {
390- if ( manually )
391- ShowSelfUpdateResult ( new Models . AlreadyUpToDate ( ) ) ;
392- return ;
393- }
394-
395- // Should not check ignored tag if this is called manually.
396- if ( ! manually )
397- {
398- var pref = ViewModels . Preference . Instance ;
399- if ( ver . TagName == pref . IgnoreUpdateTag )
400- return ;
401- }
402-
403- ShowSelfUpdateResult ( ver ) ;
404- }
405- catch ( Exception e )
406- {
407- if ( manually )
408- ShowSelfUpdateResult ( e ) ;
409- }
410- } ) ;
411- }
412-
413- private static void ShowSelfUpdateResult ( object data )
414- {
415- Dispatcher . UIThread . Post ( ( ) =>
416- {
417- OpenDialog ( new Views . SelfUpdate ( ) { DataContext = new ViewModels . SelfUpdate ( ) { Data = data } } ) ;
418- } ) ;
419- }
420-
421352 private static bool TryLaunchedAsRebaseTodoEditor ( string [ ] args , out int exitCode )
422353 {
423354 exitCode = - 1 ;
@@ -555,6 +486,59 @@ private void TryLaunchedAsNormal(IClassicDesktopStyleApplicationLifetime desktop
555486#endif
556487 }
557488
489+ private void Check4Update ( bool manually = false )
490+ {
491+ Task . Run ( async ( ) =>
492+ {
493+ try
494+ {
495+ // Fetch lastest release information.
496+ var client = new HttpClient ( ) { Timeout = TimeSpan . FromSeconds ( 5 ) } ;
497+ var data = await client . GetStringAsync ( "https://sourcegit-scm.github.io/data/version.json" ) ;
498+
499+ // Parse json into Models.Version.
500+ var ver = JsonSerializer . Deserialize ( data , JsonCodeGen . Default . Version ) ;
501+ if ( ver == null )
502+ return ;
503+
504+ // Check if already up-to-date.
505+ if ( ! ver . IsNewVersion )
506+ {
507+ if ( manually )
508+ ShowSelfUpdateResult ( new Models . AlreadyUpToDate ( ) ) ;
509+ return ;
510+ }
511+
512+ // Should not check ignored tag if this is called manually.
513+ if ( ! manually )
514+ {
515+ var pref = ViewModels . Preference . Instance ;
516+ if ( ver . TagName == pref . IgnoreUpdateTag )
517+ return ;
518+ }
519+
520+ ShowSelfUpdateResult ( ver ) ;
521+ }
522+ catch ( Exception e )
523+ {
524+ if ( manually )
525+ ShowSelfUpdateResult ( e ) ;
526+ }
527+ } ) ;
528+ }
529+
530+ private void ShowSelfUpdateResult ( object data )
531+ {
532+ Dispatcher . UIThread . Post ( ( ) =>
533+ {
534+ if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow : { } owner } )
535+ {
536+ var dialog = new Views . SelfUpdate ( ) { DataContext = new ViewModels . SelfUpdate ( ) { Data = data } } ;
537+ dialog . ShowDialog ( owner ) ;
538+ }
539+ } ) ;
540+ }
541+
558542 private ViewModels . Launcher _launcher = null ;
559543 private ResourceDictionary _activeLocale = null ;
560544 private ResourceDictionary _themeOverrides = null ;
0 commit comments