@@ -35,31 +35,64 @@ public partial class App : IDisposable, ISingleInstanceApp
3535 public App ( )
3636 {
3737 // Initialize settings
38- var storage = new FlowLauncherJsonStorage < Settings > ( ) ;
39- _settings = storage . Load ( ) ;
40- _settings . SetStorage ( storage ) ;
41- _settings . WMPInstalled = WindowsMediaPlayerHelper . IsWindowsMediaPlayerInstalled ( ) ;
38+ try
39+ {
40+ var storage = new FlowLauncherJsonStorage < Settings > ( ) ;
41+ _settings = storage . Load ( ) ;
42+ _settings . SetStorage ( storage ) ;
43+ _settings . WMPInstalled = WindowsMediaPlayerHelper . IsWindowsMediaPlayerInstalled ( ) ;
44+ }
45+ catch ( Exception e )
46+ {
47+ ShowErrorMsgBoxAndFailFast ( "Cannot load setting storage, please check local data directory" , e ) ;
48+ return ;
49+ }
4250
4351 // Configure the dependency injection container
44- var host = Host . CreateDefaultBuilder ( )
45- . UseContentRoot ( AppContext . BaseDirectory )
46- . ConfigureServices ( services => services
47- . AddSingleton ( _ => _settings )
48- . AddSingleton ( sp => new Updater ( sp . GetRequiredService < IPublicAPI > ( ) , Launcher . Properties . Settings . Default . GithubRepo ) )
49- . AddSingleton < Portable > ( )
50- . AddSingleton < SettingWindowViewModel > ( )
51- . AddSingleton < IAlphabet , PinyinAlphabet > ( )
52- . AddSingleton < StringMatcher > ( )
53- . AddSingleton < Internationalization > ( )
54- . AddSingleton < IPublicAPI , PublicAPIInstance > ( )
55- . AddSingleton < MainViewModel > ( )
56- . AddSingleton < Theme > ( )
57- ) . Build ( ) ;
58- Ioc . Default . ConfigureServices ( host . Services ) ;
52+ try
53+ {
54+ var host = Host . CreateDefaultBuilder ( )
55+ . UseContentRoot ( AppContext . BaseDirectory )
56+ . ConfigureServices ( services => services
57+ . AddSingleton ( _ => _settings )
58+ . AddSingleton ( sp => new Updater ( sp . GetRequiredService < IPublicAPI > ( ) , Launcher . Properties . Settings . Default . GithubRepo ) )
59+ . AddSingleton < Portable > ( )
60+ . AddSingleton < SettingWindowViewModel > ( )
61+ . AddSingleton < IAlphabet , PinyinAlphabet > ( )
62+ . AddSingleton < StringMatcher > ( )
63+ . AddSingleton < Internationalization > ( )
64+ . AddSingleton < IPublicAPI , PublicAPIInstance > ( )
65+ . AddSingleton < MainViewModel > ( )
66+ . AddSingleton < Theme > ( )
67+ ) . Build ( ) ;
68+ Ioc . Default . ConfigureServices ( host . Services ) ;
69+ }
70+ catch ( Exception e )
71+ {
72+ ShowErrorMsgBoxAndFailFast ( "Cannot configure dependency injection container, please open new issue in Flow.Launcher" , e ) ;
73+ return ;
74+ }
5975
6076 // Initialize the public API and Settings first
61- API = Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
62- _settings . Initialize ( ) ;
77+ try
78+ {
79+ API = Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
80+ _settings . Initialize ( ) ;
81+ }
82+ catch ( Exception e )
83+ {
84+ ShowErrorMsgBoxAndFailFast ( "Cannot initialize api and settings, please open new issue in Flow.Launcher" , e ) ;
85+ return ;
86+ }
87+ }
88+
89+ private static void ShowErrorMsgBoxAndFailFast ( string message , Exception e )
90+ {
91+ // Firstly show users the message
92+ MessageBox . Show ( e . ToString ( ) , message , MessageBoxButton . OK , MessageBoxImage . Error ) ;
93+
94+ // Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
95+ Environment . FailFast ( message , e ) ;
6396 }
6497
6598 [ STAThread ]
0 commit comments