@@ -41,9 +41,9 @@ public partial class App : IDisposable, ISingleInstanceApp
41
41
private static readonly string ClassName = nameof ( App ) ;
42
42
43
43
private static bool _disposed ;
44
+ private static Settings _settings ;
44
45
private static MainWindow _mainWindow ;
45
46
private readonly MainViewModel _mainVM ;
46
- private readonly Settings _settings ;
47
47
48
48
// To prevent two disposals running at the same time.
49
49
private static readonly object _disposingLock = new ( ) ;
@@ -55,19 +55,7 @@ public partial class App : IDisposable, ISingleInstanceApp
55
55
public App ( )
56
56
{
57
57
// Initialize settings
58
- try
59
- {
60
- var storage = new FlowLauncherJsonStorage < Settings > ( ) ;
61
- _settings = storage . Load ( ) ;
62
- _settings . SetStorage ( storage ) ;
63
- _settings . WMPInstalled = WindowsMediaPlayerHelper . IsWindowsMediaPlayerInstalled ( ) ;
64
- }
65
- catch ( Exception e )
66
- {
67
- ShowErrorMsgBoxAndFailFast ( "Cannot load setting storage, please check local data directory" , e ) ;
68
- return ;
69
- }
70
-
58
+ _settings . WMPInstalled = WindowsMediaPlayerHelper . IsWindowsMediaPlayerInstalled ( ) ;
71
59
// Configure the dependency injection container
72
60
try
73
61
{
@@ -119,16 +107,6 @@ public App()
119
107
ShowErrorMsgBoxAndFailFast ( "Cannot initialize api and settings, please open new issue in Flow.Launcher" , e ) ;
120
108
return ;
121
109
}
122
-
123
- // Local function
124
- static void ShowErrorMsgBoxAndFailFast ( string message , Exception e )
125
- {
126
- // Firstly show users the message
127
- MessageBox . Show ( e . ToString ( ) , message , MessageBoxButton . OK , MessageBoxImage . Error ) ;
128
-
129
- // Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
130
- Environment . FailFast ( message , e ) ;
131
- }
132
110
}
133
111
134
112
#endregion
@@ -138,6 +116,29 @@ static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
138
116
[ STAThread ]
139
117
public static void Main ( )
140
118
{
119
+ // Initialize settings so that we can get language code
120
+ try
121
+ {
122
+ var storage = new FlowLauncherJsonStorage < Settings > ( ) ;
123
+ _settings = storage . Load ( ) ;
124
+ _settings . SetStorage ( storage ) ;
125
+ }
126
+ catch ( Exception e )
127
+ {
128
+ ShowErrorMsgBoxAndFailFast ( "Cannot load setting storage, please check local data directory" , e ) ;
129
+ return ;
130
+ }
131
+
132
+ // Initialize system language before changing culture info
133
+ Internationalization . InitSystemLanguageCode ( ) ;
134
+
135
+ // Change culture info before application creation to localize WinForm windows
136
+ if ( _settings . Language != Constant . SystemLanguageCode )
137
+ {
138
+ Internationalization . ChangeCultureInfo ( _settings . Language ) ;
139
+ }
140
+
141
+ // Start the application as a single instance
141
142
if ( SingleInstance < App > . InitializeAsFirstInstance ( ) )
142
143
{
143
144
using var application = new App ( ) ;
@@ -148,6 +149,19 @@ public static void Main()
148
149
149
150
#endregion
150
151
152
+ #region Fail Fast
153
+
154
+ private static void ShowErrorMsgBoxAndFailFast ( string message , Exception e )
155
+ {
156
+ // Firstly show users the message
157
+ MessageBox . Show ( e . ToString ( ) , message , MessageBoxButton . OK , MessageBoxImage . Error ) ;
158
+
159
+ // Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
160
+ Environment . FailFast ( message , e ) ;
161
+ }
162
+
163
+ #endregion
164
+
151
165
#region App Events
152
166
153
167
#pragma warning disable VSTHRD100 // Avoid async void methods
0 commit comments