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
+
1
10
using Avalonia ;
2
11
using Avalonia . Controls ;
3
12
using Avalonia . Controls . ApplicationLifetimes ;
6
15
using Avalonia . Media ;
7
16
using Avalonia . Media . Fonts ;
8
17
using 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 ;
16
18
17
- namespace SourceGit {
18
- public partial class App : Application {
19
+ namespace SourceGit
20
+ {
21
+ public partial class App : Application
22
+ {
19
23
20
24
[ STAThread ]
21
- public static void Main ( string [ ] args ) {
22
- try {
25
+ public static void Main ( string [ ] args )
26
+ {
27
+ try
28
+ {
23
29
BuildAvaloniaApp ( ) . StartWithClassicDesktopLifetime ( args ) ;
24
- } catch ( Exception ex ) {
30
+ }
31
+ catch ( Exception ex )
32
+ {
25
33
var builder = new StringBuilder ( ) ;
26
34
builder . Append ( "Crash: " ) ;
27
35
builder . Append ( ex . Message ) ;
@@ -39,40 +47,48 @@ public static void Main(string[] args) {
39
47
"SourceGit" ,
40
48
$ "crash_{ time } .log") ;
41
49
File . WriteAllText ( file , builder . ToString ( ) ) ;
42
- }
50
+ }
43
51
}
44
52
45
- public static AppBuilder BuildAvaloniaApp ( ) {
53
+ public static AppBuilder BuildAvaloniaApp ( )
54
+ {
46
55
var builder = AppBuilder . Configure < App > ( ) ;
47
56
builder . UsePlatformDetect ( ) ;
48
57
builder . LogToTrace ( ) ;
49
- builder . ConfigureFonts ( manager => {
58
+ builder . ConfigureFonts ( manager =>
59
+ {
50
60
var monospace = new EmbeddedFontCollection (
51
61
new Uri ( "fonts:SourceGit" , UriKind . Absolute ) ,
52
62
new Uri ( "avares://SourceGit/Resources/Fonts" , UriKind . Absolute ) ) ;
53
63
manager . AddFontCollection ( monospace ) ;
54
64
} ) ;
55
65
56
- Native . OS . SetupFonts ( builder ) ;
66
+ Native . OS . SetupApp ( builder ) ;
57
67
return builder ;
58
68
}
59
69
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
+ {
62
74
var notice = new Models . Notification ( ) { IsError = true , Message = message } ;
63
75
app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
64
76
}
65
77
}
66
78
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
+ {
69
83
var notice = new Models . Notification ( ) { IsError = false , Message = message } ;
70
84
app . _notificationReceiver . OnReceiveNotification ( context , notice ) ;
71
85
}
72
86
}
73
87
74
- public static void SetLocale ( string localeKey ) {
88
+ public static void SetLocale ( string localeKey )
89
+ {
75
90
var app = Current as App ;
91
+
76
92
localeKey = localeKey . Replace ( "_" , "-" ) ;
77
93
78
94
Thread . CurrentThread . CurrentUICulture = CultureInfo . GetCultureInfo ( localeKey ) ;
@@ -92,39 +108,51 @@ public static void SetLocale(string localeKey) {
92
108
return ;
93
109
}
94
110
95
- if ( app . _activeLocale != null ) {
111
+ if ( app . _activeLocale != null )
112
+ {
96
113
app . Resources . MergedDictionaries . Remove ( app . _activeLocale ) ;
97
114
}
98
115
99
116
app . Resources . MergedDictionaries . Add ( targetLocale ) ;
100
117
app . _activeLocale = targetLocale ;
101
118
}
102
119
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
+ {
105
124
Current . RequestedThemeVariant = ThemeVariant . Light ;
106
- } else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) ) {
125
+ }
126
+ else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
127
+ {
107
128
Current . RequestedThemeVariant = ThemeVariant . Dark ;
108
- } else {
129
+ }
130
+ else
131
+ {
109
132
Current . RequestedThemeVariant = ThemeVariant . Default ;
110
133
}
111
134
}
112
135
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
+ {
116
142
await clipbord . SetTextAsync ( data ) ;
117
143
}
118
144
}
119
145
}
120
146
121
- public static string Text ( string key , params object [ ] args ) {
147
+ public static string Text ( string key , params object [ ] args )
148
+ {
122
149
var fmt = Current . FindResource ( $ "Text.{ key } ") as string ;
123
150
if ( string . IsNullOrWhiteSpace ( fmt ) ) return $ "Text.{ key } ";
124
151
return string . Format ( fmt , args ) ;
125
152
}
126
153
127
- public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key ) {
154
+ public static Avalonia . Controls . Shapes . Path CreateMenuIcon ( string key )
155
+ {
128
156
var icon = new Avalonia . Controls . Shapes . Path ( ) ;
129
157
icon . Width = 12 ;
130
158
icon . Height = 12 ;
@@ -133,29 +161,36 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
133
161
return icon ;
134
162
}
135
163
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
+ {
138
168
return desktop . MainWindow ;
139
169
}
140
170
return null ;
141
171
}
142
172
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
+ {
145
177
desktop . MainWindow . Close ( ) ;
146
178
desktop . Shutdown ( ) ;
147
179
}
148
180
}
149
181
150
- public override void Initialize ( ) {
182
+ public override void Initialize ( )
183
+ {
151
184
AvaloniaXamlLoader . Load ( this ) ;
152
185
153
186
SetLocale ( ViewModels . Preference . Instance . Locale ) ;
154
187
SetTheme ( ViewModels . Preference . Instance . Theme ) ;
155
188
}
156
189
157
- public override void OnFrameworkInitializationCompleted ( ) {
158
- if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
190
+ public override void OnFrameworkInitializationCompleted ( )
191
+ {
192
+ if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
193
+ {
159
194
BindingPlugins . DataValidators . RemoveAt ( 0 ) ;
160
195
161
196
var launcher = new Views . Launcher ( ) ;
0 commit comments