1+ using System ;
2+ using System . IO ;
3+ using System . Reflection ;
4+ using System . Text ;
5+ using System . Globalization ;
6+ using System . Linq ;
7+ using System . Reflection ;
8+ using System . Threading ;
9+
110using Avalonia ;
211using Avalonia . Controls ;
312using Avalonia . Controls . ApplicationLifetimes ;
615using Avalonia . Media ;
716using Avalonia . Media . Fonts ;
817using Avalonia . Styling ;
9- using System ;
10- using System . Globalization ;
11- using System . IO ;
12- using System . Linq ;
13- using System . Reflection ;
14- using System . Text ;
15- using System . Threading ;
1618
17- namespace SourceGit {
18- public partial class App : Application {
19+ namespace SourceGit
20+ {
21+ public partial class App : Application
22+ {
1923
2024 [ STAThread ]
21- public static void Main ( string [ ] args ) {
22- try {
25+ public static void Main ( string [ ] args )
26+ {
27+ try
28+ {
2329 BuildAvaloniaApp ( ) . StartWithClassicDesktopLifetime ( args ) ;
24- } catch ( Exception ex ) {
30+ }
31+ catch ( Exception ex )
32+ {
2533 var builder = new StringBuilder ( ) ;
2634 builder . Append ( "Crash: " ) ;
2735 builder . Append ( ex . Message ) ;
@@ -39,40 +47,48 @@ public static void Main(string[] args) {
3947 "SourceGit" ,
4048 $ "crash_{ time } .log") ;
4149 File . WriteAllText ( file , builder . ToString ( ) ) ;
42- }
50+ }
4351 }
4452
45- public static AppBuilder BuildAvaloniaApp ( ) {
53+ public static AppBuilder BuildAvaloniaApp ( )
54+ {
4655 var builder = AppBuilder . Configure < App > ( ) ;
4756 builder . UsePlatformDetect ( ) ;
4857 builder . LogToTrace ( ) ;
49- builder . ConfigureFonts ( manager => {
58+ builder . ConfigureFonts ( manager =>
59+ {
5060 var monospace = new EmbeddedFontCollection (
5161 new Uri ( "fonts:SourceGit" , UriKind . Absolute ) ,
5262 new Uri ( "avares://SourceGit/Resources/Fonts" , UriKind . Absolute ) ) ;
5363 manager . AddFontCollection ( monospace ) ;
5464 } ) ;
5565
56- Native . OS . SetupFonts ( builder ) ;
66+ Native . OS . SetupApp ( builder ) ;
5767 return builder ;
5868 }
5969
60- public static void RaiseException ( string context , string message ) {
61- if ( Current is App app && app . _notificationReceiver != null ) {
70+ public static void RaiseException ( string context , string message )
71+ {
72+ if ( Current is App app && app . _notificationReceiver != null )
73+ {
6274 var notice = new Models . Notification ( ) { IsError = true , Message = message } ;
6375 app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
6476 }
6577 }
6678
67- public static void SendNotification ( string context , string message ) {
68- if ( Current is App app && app . _notificationReceiver != null ) {
79+ public static void SendNotification ( string context , string message )
80+ {
81+ if ( Current is App app && app . _notificationReceiver != null )
82+ {
6983 var notice = new Models . Notification ( ) { IsError = false , Message = message } ;
7084 app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
7185 }
7286 }
7387
74- public static void SetLocale ( string localeKey ) {
88+ public static void SetLocale ( string localeKey )
89+ {
7590 var app = Current as App ;
91+
7692 localeKey = localeKey . Replace ( "_" , "-" ) ;
7793
7894 Thread . CurrentThread . CurrentUICulture = CultureInfo . GetCultureInfo ( localeKey ) ;
@@ -92,39 +108,51 @@ public static void SetLocale(string localeKey) {
92108 return ;
93109 }
94110
95- if ( app . _activeLocale != null ) {
111+ if ( app . _activeLocale != null )
112+ {
96113 app . Resources . MergedDictionaries . Remove ( app . _activeLocale ) ;
97114 }
98115
99116 app . Resources . MergedDictionaries . Add ( targetLocale ) ;
100117 app . _activeLocale = targetLocale ;
101118 }
102119
103- public static void SetTheme ( string theme ) {
104- if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) ) {
120+ public static void SetTheme ( string theme )
121+ {
122+ if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
123+ {
105124 Current . RequestedThemeVariant = ThemeVariant . Light ;
106- } else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) ) {
125+ }
126+ else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
127+ {
107128 Current . RequestedThemeVariant = ThemeVariant . Dark ;
108- } else {
129+ }
130+ else
131+ {
109132 Current . RequestedThemeVariant = ThemeVariant . Default ;
110133 }
111134 }
112135
113- public static async void CopyText ( string data ) {
114- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
115- if ( desktop . MainWindow . Clipboard is { } clipbord ) {
136+ public static async void CopyText ( string data )
137+ {
138+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
139+ {
140+ if ( desktop . MainWindow . Clipboard is { } clipbord )
141+ {
116142 await clipbord . SetTextAsync ( data ) ;
117143 }
118144 }
119145 }
120146
121- public static string Text ( string key , params object [ ] args ) {
147+ public static string Text ( string key , params object [ ] args )
148+ {
122149 var fmt = Current . FindResource ( $ "Text.{ key } ") as string ;
123150 if ( string . IsNullOrWhiteSpace ( fmt ) ) return $ "Text.{ key } ";
124151 return string . Format ( fmt , args ) ;
125152 }
126153
127- public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key ) {
154+ public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key )
155+ {
128156 var icon = new Avalonia . Controls . Shapes . Path ( ) ;
129157 icon . Width = 12 ;
130158 icon . Height = 12 ;
@@ -133,29 +161,36 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
133161 return icon ;
134162 }
135163
136- public static TopLevel GetTopLevel ( ) {
137- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
164+ public static TopLevel GetTopLevel ( )
165+ {
166+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
167+ {
138168 return desktop . MainWindow ;
139169 }
140170 return null ;
141171 }
142172
143- public static void Quit ( ) {
144- if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
173+ public static void Quit ( )
174+ {
175+ if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
176+ {
145177 desktop . MainWindow . Close ( ) ;
146178 desktop . Shutdown ( ) ;
147179 }
148180 }
149181
150- public override void Initialize ( ) {
182+ public override void Initialize ( )
183+ {
151184 AvaloniaXamlLoader . Load ( this ) ;
152185
153186 SetLocale ( ViewModels . Preference . Instance . Locale ) ;
154187 SetTheme ( ViewModels . Preference . Instance . Theme ) ;
155188 }
156189
157- public override void OnFrameworkInitializationCompleted ( ) {
158- if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
190+ public override void OnFrameworkInitializationCompleted ( )
191+ {
192+ if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
193+ {
159194 BindingPlugins . DataValidators . RemoveAt ( 0 ) ;
160195
161196 var launcher = new Views . Launcher ( ) ;
0 commit comments