4
4
using System . Threading ;
5
5
using System . Threading . Tasks ;
6
6
using System . Windows ;
7
+ using System . Windows . Media ;
7
8
using CommunityToolkit . Mvvm . DependencyInjection ;
8
9
using Flow . Launcher . Core ;
9
10
using Flow . Launcher . Core . Configuration ;
18
19
using Flow . Launcher . Infrastructure . Storage ;
19
20
using Flow . Launcher . Infrastructure . UserSettings ;
20
21
using Flow . Launcher . Plugin ;
22
+ using Flow . Launcher . SettingPages . ViewModels ;
21
23
using Flow . Launcher . ViewModel ;
22
24
using Microsoft . Extensions . DependencyInjection ;
23
25
using Microsoft . Extensions . Hosting ;
@@ -29,6 +31,7 @@ public partial class App : IDisposable, ISingleInstanceApp
29
31
#region Public Properties
30
32
31
33
public static IPublicAPI API { get ; private set ; }
34
+ public static bool Exiting => _mainWindow . CanClose ;
32
35
33
36
#endregion
34
37
@@ -37,7 +40,7 @@ public partial class App : IDisposable, ISingleInstanceApp
37
40
private static readonly string ClassName = nameof ( App ) ;
38
41
39
42
private static bool _disposed ;
40
- private MainWindow _mainWindow ;
43
+ private static MainWindow _mainWindow ;
41
44
private readonly MainViewModel _mainVM ;
42
45
private readonly Settings _settings ;
43
46
@@ -73,14 +76,27 @@ public App()
73
76
. AddSingleton ( _ => _settings )
74
77
. AddSingleton ( sp => new Updater ( sp . GetRequiredService < IPublicAPI > ( ) , Launcher . Properties . Settings . Default . GithubRepo ) )
75
78
. AddSingleton < Portable > ( )
76
- . AddSingleton < SettingWindowViewModel > ( )
77
79
. AddSingleton < IAlphabet , PinyinAlphabet > ( )
78
80
. AddSingleton < StringMatcher > ( )
79
81
. AddSingleton < Internationalization > ( )
80
82
. AddSingleton < IPublicAPI , PublicAPIInstance > ( )
81
- . AddSingleton < MainViewModel > ( )
82
83
. AddSingleton < Theme > ( )
84
+ // Use one instance for main window view model because we only have one main window
85
+ . AddSingleton < MainViewModel > ( )
86
+ // Use one instance for welcome window view model & setting window view model because
87
+ // pages in welcome window & setting window need to share the same instance and
88
+ // these two view models do not need to be reset when creating new windows
83
89
. AddSingleton < WelcomeViewModel > ( )
90
+ . AddSingleton < SettingWindowViewModel > ( )
91
+ // Use transient instance for setting window page view models because
92
+ // pages in setting window need to be recreated when setting window is closed
93
+ . AddTransient < SettingsPaneAboutViewModel > ( )
94
+ . AddTransient < SettingsPaneGeneralViewModel > ( )
95
+ . AddTransient < SettingsPaneHotkeyViewModel > ( )
96
+ . AddTransient < SettingsPanePluginsViewModel > ( )
97
+ . AddTransient < SettingsPanePluginStoreViewModel > ( )
98
+ . AddTransient < SettingsPaneProxyViewModel > ( )
99
+ . AddTransient < SettingsPaneThemeViewModel > ( )
84
100
) . Build ( ) ;
85
101
Ioc . Default . ConfigureServices ( host . Services ) ;
86
102
}
@@ -146,10 +162,14 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
146
162
147
163
Log . SetLogLevel ( _settings . LogLevel ) ;
148
164
165
+ // Update dynamic resources base on settings
166
+ Current . Resources [ "SettingWindowFont" ] = new FontFamily ( _settings . SettingWindowFont ) ;
167
+ Current . Resources [ "ContentControlThemeFontFamily" ] = new FontFamily ( _settings . SettingWindowFont ) ;
168
+
149
169
Ioc . Default . GetRequiredService < Portable > ( ) . PreStartCleanUpAfterPortabilityUpdate ( ) ;
150
170
151
171
API . LogInfo ( ClassName , "Begin Flow Launcher startup ----------------------------------------------------" ) ;
152
- API . LogInfo ( ClassName , "Runtime info:{ErrorReporting.RuntimeInfo()}" ) ;
172
+ API . LogInfo ( ClassName , $ "Runtime info:{ ErrorReporting . RuntimeInfo ( ) } ") ;
153
173
154
174
RegisterAppDomainExceptions ( ) ;
155
175
RegisterDispatcherUnhandledException ( ) ;
@@ -169,19 +189,16 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
169
189
await PluginManager . InitializePluginsAsync ( ) ;
170
190
171
191
// Change language after all plugins are initialized because we need to update plugin title based on their api
172
- // TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
173
192
await Ioc . Default . GetRequiredService < Internationalization > ( ) . InitializeLanguageAsync ( ) ;
174
193
175
194
await imageLoadertask ;
176
195
177
196
_mainWindow = new MainWindow ( ) ;
178
197
179
- API . LogInfo ( ClassName , "Dependencies Info:{ErrorReporting.DependenciesInfo()}" ) ;
180
-
181
198
Current . MainWindow = _mainWindow ;
182
199
Current . MainWindow . Title = Constant . FlowLauncher ;
183
200
184
- // main windows needs initialized before theme change because of blur settings
201
+ // Main windows needs initialized before theme change because of blur settings
185
202
Ioc . Default . GetRequiredService < Theme > ( ) . ChangeTheme ( ) ;
186
203
187
204
Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance ) ;
@@ -198,6 +215,10 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
198
215
199
216
#pragma warning restore VSTHRD100 // Avoid async void methods
200
217
218
+ /// <summary>
219
+ /// Check startup only for Release
220
+ /// </summary>
221
+ [ Conditional ( "RELEASE" ) ]
201
222
private void AutoStartup ( )
202
223
{
203
224
// we try to enable auto-startup on first launch, or reenable if it was removed
@@ -261,7 +282,7 @@ private void RegisterExitEvents()
261
282
}
262
283
263
284
/// <summary>
264
- /// let exception throw as normal is better for Debug
285
+ /// Let exception throw as normal is better for Debug
265
286
/// </summary>
266
287
[ Conditional ( "RELEASE" ) ]
267
288
private void RegisterDispatcherUnhandledException ( )
@@ -270,7 +291,7 @@ private void RegisterDispatcherUnhandledException()
270
291
}
271
292
272
293
/// <summary>
273
- /// let exception throw as normal is better for Debug
294
+ /// Let exception throw as normal is better for Debug
274
295
/// </summary>
275
296
[ Conditional ( "RELEASE" ) ]
276
297
private static void RegisterAppDomainExceptions ( )
@@ -279,7 +300,7 @@ private static void RegisterAppDomainExceptions()
279
300
}
280
301
281
302
/// <summary>
282
- /// let exception throw as normal is better for Debug
303
+ /// Let exception throw as normal is better for Debug
283
304
/// </summary>
284
305
[ Conditional ( "RELEASE" ) ]
285
306
private static void RegisterTaskSchedulerUnhandledException ( )
0 commit comments