44using System . Threading ;
55using System . Threading . Tasks ;
66using System . Windows ;
7+ using System . Windows . Media ;
78using CommunityToolkit . Mvvm . DependencyInjection ;
89using Flow . Launcher . Core ;
910using Flow . Launcher . Core . Configuration ;
1920using Flow . Launcher . Infrastructure . Storage ;
2021using Flow . Launcher . Infrastructure . UserSettings ;
2122using Flow . Launcher . Plugin ;
23+ using Flow . Launcher . SettingPages . ViewModels ;
2224using Flow . Launcher . ViewModel ;
2325using Microsoft . Extensions . DependencyInjection ;
2426using Microsoft . Extensions . Hosting ;
@@ -30,6 +32,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3032 #region Public Properties
3133
3234 public static IPublicAPI API { get ; private set ; }
35+ public static bool Exiting => _mainWindow . CanClose ;
3336
3437 #endregion
3538
@@ -38,7 +41,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3841 private static readonly string ClassName = nameof ( App ) ;
3942
4043 private static bool _disposed ;
41- private MainWindow _mainWindow ;
44+ private static MainWindow _mainWindow ;
4245 private readonly MainViewModel _mainVM ;
4346 private readonly Settings _settings ;
4447
@@ -74,14 +77,27 @@ public App()
7477 . AddSingleton ( _ => _settings )
7578 . AddSingleton ( sp => new Updater ( sp . GetRequiredService < IPublicAPI > ( ) , Launcher . Properties . Settings . Default . GithubRepo ) )
7679 . AddSingleton < Portable > ( )
77- . AddSingleton < SettingWindowViewModel > ( )
7880 . AddSingleton < IAlphabet , PinyinAlphabet > ( )
7981 . AddSingleton < StringMatcher > ( )
8082 . AddSingleton < Internationalization > ( )
8183 . AddSingleton < IPublicAPI , PublicAPIInstance > ( )
82- . AddSingleton < MainViewModel > ( )
8384 . AddSingleton < Theme > ( )
85+ // Use one instance for main window view model because we only have one main window
86+ . AddSingleton < MainViewModel > ( )
87+ // Use one instance for welcome window view model & setting window view model because
88+ // pages in welcome window & setting window need to share the same instance and
89+ // these two view models do not need to be reset when creating new windows
8490 . AddSingleton < WelcomeViewModel > ( )
91+ . AddSingleton < SettingWindowViewModel > ( )
92+ // Use transient instance for setting window page view models because
93+ // pages in setting window need to be recreated when setting window is closed
94+ . AddTransient < SettingsPaneAboutViewModel > ( )
95+ . AddTransient < SettingsPaneGeneralViewModel > ( )
96+ . AddTransient < SettingsPaneHotkeyViewModel > ( )
97+ . AddTransient < SettingsPanePluginsViewModel > ( )
98+ . AddTransient < SettingsPanePluginStoreViewModel > ( )
99+ . AddTransient < SettingsPaneProxyViewModel > ( )
100+ . AddTransient < SettingsPaneThemeViewModel > ( )
85101 ) . Build ( ) ;
86102 Ioc . Default . ConfigureServices ( host . Services ) ;
87103 }
@@ -147,10 +163,14 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
147163
148164 Log . SetLogLevel ( _settings . LogLevel ) ;
149165
166+ // Update dynamic resources base on settings
167+ Current . Resources [ "SettingWindowFont" ] = new FontFamily ( _settings . SettingWindowFont ) ;
168+ Current . Resources [ "ContentControlThemeFontFamily" ] = new FontFamily ( _settings . SettingWindowFont ) ;
169+
150170 Ioc . Default . GetRequiredService < Portable > ( ) . PreStartCleanUpAfterPortabilityUpdate ( ) ;
151171
152172 API . LogInfo ( ClassName , "Begin Flow Launcher startup ----------------------------------------------------" ) ;
153- API . LogInfo ( ClassName , "Runtime info:{ErrorReporting.RuntimeInfo()}" ) ;
173+ API . LogInfo ( ClassName , $ "Runtime info:{ ErrorReporting . RuntimeInfo ( ) } ") ;
154174
155175 RegisterAppDomainExceptions ( ) ;
156176 RegisterDispatcherUnhandledException ( ) ;
@@ -170,19 +190,16 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
170190 await PluginManager . InitializePluginsAsync ( ) ;
171191
172192 // Change language after all plugins are initialized because we need to update plugin title based on their api
173- // TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
174193 await Ioc . Default . GetRequiredService < Internationalization > ( ) . InitializeLanguageAsync ( ) ;
175194
176195 await imageLoadertask ;
177196
178197 _mainWindow = new MainWindow ( ) ;
179198
180- API . LogInfo ( ClassName , "Dependencies Info:{ErrorReporting.DependenciesInfo()}" ) ;
181-
182199 Current . MainWindow = _mainWindow ;
183200 Current . MainWindow . Title = Constant . FlowLauncher ;
184201
185- // main windows needs initialized before theme change because of blur settings
202+ // Main windows needs initialized before theme change because of blur settings
186203 Ioc . Default . GetRequiredService < Theme > ( ) . ChangeTheme ( ) ;
187204
188205 QuickSwitch . InitializeQuickSwitch ( ) ;
@@ -203,7 +220,7 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
203220#pragma warning restore VSTHRD100 // Avoid async void methods
204221
205222 /// <summary>
206- /// check startup only for Release
223+ /// Check startup only for Release
207224 /// </summary>
208225 [ Conditional ( "RELEASE" ) ]
209226 private void AutoStartup ( )
@@ -269,7 +286,7 @@ private void RegisterExitEvents()
269286 }
270287
271288 /// <summary>
272- /// let exception throw as normal is better for Debug
289+ /// Let exception throw as normal is better for Debug
273290 /// </summary>
274291 [ Conditional ( "RELEASE" ) ]
275292 private void RegisterDispatcherUnhandledException ( )
@@ -278,7 +295,7 @@ private void RegisterDispatcherUnhandledException()
278295 }
279296
280297 /// <summary>
281- /// let exception throw as normal is better for Debug
298+ /// Let exception throw as normal is better for Debug
282299 /// </summary>
283300 [ Conditional ( "RELEASE" ) ]
284301 private static void RegisterAppDomainExceptions ( )
@@ -287,7 +304,7 @@ private static void RegisterAppDomainExceptions()
287304 }
288305
289306 /// <summary>
290- /// let exception throw as normal is better for Debug
307+ /// Let exception throw as normal is better for Debug
291308 /// </summary>
292309 [ Conditional ( "RELEASE" ) ]
293310 private static void RegisterTaskSchedulerUnhandledException ( )
0 commit comments