Skip to content

Commit 397c6ee

Browse files
committed
Add message box to show exception
1 parent 2e511b0 commit 397c6ee

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
@@ -132,17 +165,17 @@ private void AutoStartup()
132165
{
133166
// we try to enable auto-startup on first launch, or reenable if it was removed
134167
// but the user still has the setting set
135-
if (_settings.StartFlowLauncherOnSystemStartup && !Helper.AutoStartup.IsEnabled)
168+
if (_settings.StartFlowLauncherOnSystemStartup && !Infrastructure.AutoStartup.IsEnabled)
136169
{
137170
try
138171
{
139172
if (_settings.UseLogonTaskForStartup)
140173
{
141-
Helper.AutoStartup.EnableViaLogonTask();
174+
Infrastructure.AutoStartup.EnableViaLogonTask();
142175
}
143176
else
144177
{
145-
Helper.AutoStartup.EnableViaRegistry();
178+
Infrastructure.AutoStartup.EnableViaRegistry();
146179
}
147180
}
148181
catch (Exception e)

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
</PackageReference>
9292
<PackageReference Include="InputSimulator" Version="1.0.4" />
9393
<!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting since we are .Net7.0 -->
94+
<!-- TaskScheduler seems to be incompatible with 7.0.x version, so we use 6.0.x -->
9495
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.2" />
9596
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
9697
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />

0 commit comments

Comments
 (0)