1+ using System ;
2+ using System . IO ;
3+ using System . Reflection ;
4+ using System . Text ;
5+
16using Avalonia ;
27using Avalonia . Controls ;
38using Avalonia . Controls . ApplicationLifetimes ;
611using Avalonia . Media ;
712using Avalonia . Media . Fonts ;
813using Avalonia . Styling ;
9- using System ;
10- using System . IO ;
11- using System . Reflection ;
12- using System . Text ;
1314
14- namespace SourceGit {
15- public partial class App : Application {
15+ namespace SourceGit
16+ {
17+ public partial class App : Application
18+ {
1619
1720 [ STAThread ]
18- public static void Main ( string [ ] args ) {
19- try {
21+ public static void Main ( string [ ] args )
22+ {
23+ try
24+ {
2025 BuildAvaloniaApp ( ) . StartWithClassicDesktopLifetime ( args ) ;
21- } catch ( Exception ex ) {
26+ }
27+ catch ( Exception ex )
28+ {
2229 var builder = new StringBuilder ( ) ;
2330 builder . Append ( "Crash: " ) ;
2431 builder . Append ( ex . Message ) ;
@@ -36,14 +43,16 @@ public static void Main(string[] args) {
3643 "SourceGit" ,
3744 $ "crash_{ time } .log") ;
3845 File . WriteAllText ( file , builder . ToString ( ) ) ;
39- }
46+ }
4047 }
4148
42- public static AppBuilder BuildAvaloniaApp ( ) {
49+ public static AppBuilder BuildAvaloniaApp ( )
50+ {
4351 var builder = AppBuilder . Configure < App > ( ) ;
4452 builder . UsePlatformDetect ( ) ;
4553 builder . LogToTrace ( ) ;
46- builder . ConfigureFonts ( manager => {
54+ builder . ConfigureFonts ( manager =>
55+ {
4756 var monospace = new EmbeddedFontCollection (
4857 new Uri ( "fonts:SourceGit" , UriKind . Absolute ) ,
4958 new Uri ( "avares://SourceGit/Resources/Fonts" , UriKind . Absolute ) ) ;
@@ -54,60 +63,78 @@ public static AppBuilder BuildAvaloniaApp() {
5463 return builder ;
5564 }
5665
57- public static void RaiseException ( string context , string message ) {
58- if ( Current is App app && app . _notificationReceiver != null ) {
66+ public static void RaiseException ( string context , string message )
67+ {
68+ if ( Current is App app && app . _notificationReceiver != null )
69+ {
5970 var notice = new Models . Notification ( ) { IsError = true , Message = message } ;
6071 app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
6172 }
6273 }
6374
64- public static void SendNotification ( string context , string message ) {
65- if ( Current is App app && app . _notificationReceiver != null ) {
75+ public static void SendNotification ( string context , string message )
76+ {
77+ if ( Current is App app && app . _notificationReceiver != null )
78+ {
6679 var notice = new Models . Notification ( ) { IsError = false , Message = message } ;
6780 app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
6881 }
6982 }
7083
71- public static void SetLocale ( string localeKey ) {
84+ public static void SetLocale ( string localeKey )
85+ {
7286 var app = Current as App ;
7387 var targetLocale = app . Resources [ localeKey ] as ResourceDictionary ;
74- if ( targetLocale == null || targetLocale == app . _activeLocale ) {
88+ if ( targetLocale == null || targetLocale == app . _activeLocale )
89+ {
7590 return ;
7691 }
7792
78- if ( app . _activeLocale != null ) {
93+ if ( app . _activeLocale != null )
94+ {
7995 app . Resources . MergedDictionaries . Remove ( app . _activeLocale ) ;
8096 }
8197
8298 app . Resources . MergedDictionaries . Add ( targetLocale ) ;
8399 app . _activeLocale = targetLocale ;
84100 }
85101
86- public static void SetTheme ( string theme ) {
87- if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) ) {
102+ public static void SetTheme ( string theme )
103+ {
104+ if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
105+ {
88106 Current . RequestedThemeVariant = ThemeVariant . Light ;
89- } else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) ) {
107+ }
108+ else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
109+ {
90110 Current . RequestedThemeVariant = ThemeVariant . Dark ;
91- } else {
111+ }
112+ else
113+ {
92114 Current . RequestedThemeVariant = ThemeVariant . Default ;
93115 }
94116 }
95117
96- public static async void CopyText ( string data ) {
97- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
98- if ( desktop . MainWindow . Clipboard is { } clipbord ) {
118+ public static async void CopyText ( string data )
119+ {
120+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
121+ {
122+ if ( desktop . MainWindow . Clipboard is { } clipbord )
123+ {
99124 await clipbord . SetTextAsync ( data ) ;
100125 }
101126 }
102127 }
103128
104- public static string Text ( string key , params object [ ] args ) {
129+ public static string Text ( string key , params object [ ] args )
130+ {
105131 var fmt = Current . FindResource ( $ "Text.{ key } ") as string ;
106132 if ( string . IsNullOrWhiteSpace ( fmt ) ) return $ "Text.{ key } ";
107133 return string . Format ( fmt , args ) ;
108134 }
109135
110- public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key ) {
136+ public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key )
137+ {
111138 var icon = new Avalonia . Controls . Shapes . Path ( ) ;
112139 icon . Width = 12 ;
113140 icon . Height = 12 ;
@@ -116,29 +143,36 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
116143 return icon ;
117144 }
118145
119- public static TopLevel GetTopLevel ( ) {
120- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
146+ public static TopLevel GetTopLevel ( )
147+ {
148+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
149+ {
121150 return desktop . MainWindow ;
122151 }
123152 return null ;
124153 }
125154
126- public static void Quit ( ) {
127- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
155+ public static void Quit ( )
156+ {
157+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
158+ {
128159 desktop . MainWindow . Close ( ) ;
129160 desktop . Shutdown ( ) ;
130161 }
131162 }
132163
133- public override void Initialize ( ) {
164+ public override void Initialize ( )
165+ {
134166 AvaloniaXamlLoader . Load ( this ) ;
135167
136168 SetLocale ( ViewModels . Preference . Instance . Locale ) ;
137169 SetTheme ( ViewModels . Preference . Instance . Theme ) ;
138170 }
139171
140- public override void OnFrameworkInitializationCompleted ( ) {
141- if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
172+ public override void OnFrameworkInitializationCompleted ( )
173+ {
174+ if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
175+ {
142176 BindingPlugins . DataValidators . RemoveAt ( 0 ) ;
143177
144178 var launcher = new Views . Launcher ( ) ;
0 commit comments