Skip to content

Commit c3a8a02

Browse files
authored
Merge branch 'dev' into loading_bar
2 parents 5c48aca + 65f85cf commit c3a8a02

File tree

7 files changed

+109
-41
lines changed

7 files changed

+109
-41
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,17 @@ public interface IPublicAPI
323323
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK);
324324

325325
/// <summary>
326-
/// Displays a standardised Flow message box.
327-
/// If there is issue when showing the message box, it will return null.
326+
/// Displays a standardised Flow progress box.
328327
/// </summary>
329-
/// <param name="caption">The caption of the message box.</param>
328+
/// <param name="caption">The caption of the progress box.</param>
330329
/// <param name="reportProgressAsync">
331330
/// Time-consuming task function, whose input is the action to report progress.
332331
/// The input of the action is the progress value which is a double value between 0 and 100.
333332
/// If there are any exceptions, this action will be null.
334333
/// </param>
335-
/// <param name="forceClosed">When user closes the progress box manually by button or esc key, this action will be called.</param>
336-
/// <returns>A progress box interface.</returns>
337-
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null);
334+
/// <param name="cancelProgress">When user cancel the progress, this action will be called.</param>
335+
/// <returns></returns>
336+
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null);
338337

339338
/// <summary>
340339
/// Start the loading bar in main window

Flow.Launcher/App.xaml.cs

Lines changed: 54 additions & 21 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]

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<PackageReference Include="InputSimulator" Version="1.0.4" />
9393
<!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting since we are .Net7.0 -->
9494
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
95-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
95+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
9696
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
9797
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
9898
<PrivateAssets>all</PrivateAssets>
@@ -104,7 +104,7 @@
104104
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
105105
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
106106
<PackageReference Include="SemanticVersioning" Version="3.0.0" />
107-
<PackageReference Include="TaskScheduler" Version="2.11.0" />
107+
<PackageReference Include="Jack251970.TaskScheduler" Version="2.12.1" />
108108
<PackageReference Include="VirtualizingWrapPanel" Version="2.1.1" />
109109
</ItemGroup>
110110

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
<system:String x:Key="commonOK">OK</system:String>
369369
<system:String x:Key="commonYes">Yes</system:String>
370370
<system:String x:Key="commonNo">No</system:String>
371+
<system:String x:Key="commonBackground">Background</system:String>
371372

372373
<!-- Crash Reporter -->
373374
<system:String x:Key="reportWindow_version">Version</system:String>

Flow.Launcher/ProgressBoxEx.xaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Foreground="{DynamicResource PopupTextColor}"
1313
ResizeMode="NoResize"
1414
SizeToContent="Height"
15+
Topmost="True"
1516
WindowStartupLocation="CenterScreen"
1617
mc:Ignorable="d">
1718
<WindowChrome.WindowChrome>
@@ -35,9 +36,32 @@
3536
<Grid.ColumnDefinitions>
3637
<ColumnDefinition Width="*" />
3738
<ColumnDefinition Width="Auto" />
39+
<ColumnDefinition Width="Auto" />
3840
</Grid.ColumnDefinitions>
3941
<Button
4042
Grid.Column="1"
43+
Click="Button_Minimize"
44+
RenderOptions.EdgeMode="Aliased"
45+
Style="{DynamicResource TitleBarButtonStyle}">
46+
<Path
47+
Width="46"
48+
Height="32"
49+
Data="M 18,15 H 28"
50+
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
51+
StrokeThickness="1">
52+
<Path.Style>
53+
<Style TargetType="Path">
54+
<Style.Triggers>
55+
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
56+
<Setter Property="Opacity" Value="0.5" />
57+
</DataTrigger>
58+
</Style.Triggers>
59+
</Style>
60+
</Path.Style>
61+
</Path>
62+
</Button>
63+
<Button
64+
Grid.Column="2"
4165
Click="Button_Cancel"
4266
Style="{StaticResource TitleBarCloseButtonStyle}">
4367
<Path
@@ -94,11 +118,17 @@
94118
HorizontalAlignment="Center"
95119
VerticalAlignment="Center"
96120
Orientation="Horizontal">
121+
<Button
122+
x:Name="btnBackground"
123+
MinWidth="120"
124+
Margin="5 0 5 0"
125+
Click="Button_Background"
126+
Content="{DynamicResource commonBackground}" />
97127
<Button
98128
x:Name="btnCancel"
99129
MinWidth="120"
100130
Margin="5 0 5 0"
101-
Click="Button_Click"
131+
Click="Button_Cancel"
102132
Content="{DynamicResource commonCancel}" />
103133
</WrapPanel>
104134
</Border>

Flow.Launcher/ProgressBoxEx.xaml.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Flow.Launcher
88
{
99
public partial class ProgressBoxEx : Window
1010
{
11-
private readonly Action _forceClosed;
11+
private readonly Action _cancelProgress;
1212

13-
private ProgressBoxEx(Action forceClosed)
13+
private ProgressBoxEx(Action cancelProgress)
1414
{
15-
_forceClosed = forceClosed;
15+
_cancelProgress = cancelProgress;
1616
InitializeComponent();
1717
}
1818

19-
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null)
19+
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null)
2020
{
2121
ProgressBoxEx prgBox = null;
2222
try
@@ -25,7 +25,7 @@ public static async Task ShowAsync(string caption, Func<Action<double>, Task> re
2525
{
2626
await Application.Current.Dispatcher.InvokeAsync(() =>
2727
{
28-
prgBox = new ProgressBoxEx(forceClosed)
28+
prgBox = new ProgressBoxEx(cancelProgress)
2929
{
3030
Title = caption
3131
};
@@ -35,7 +35,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
3535
}
3636
else
3737
{
38-
prgBox = new ProgressBoxEx(forceClosed)
38+
prgBox = new ProgressBoxEx(cancelProgress)
3939
{
4040
Title = caption
4141
};
@@ -95,20 +95,25 @@ private void KeyEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
9595
ForceClose();
9696
}
9797

98-
private void Button_Click(object sender, RoutedEventArgs e)
98+
private void Button_Cancel(object sender, RoutedEventArgs e)
9999
{
100100
ForceClose();
101101
}
102102

103-
private void Button_Cancel(object sender, RoutedEventArgs e)
103+
private void Button_Minimize(object sender, RoutedEventArgs e)
104104
{
105-
ForceClose();
105+
WindowState = WindowState.Minimized;
106+
}
107+
108+
private void Button_Background(object sender, RoutedEventArgs e)
109+
{
110+
Hide();
106111
}
107112

108113
private void ForceClose()
109114
{
110115
Close();
111-
_forceClosed?.Invoke();
116+
_cancelProgress?.Invoke();
112117
}
113118
}
114119
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public bool IsGameModeOn()
342342
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
343343
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);
344344

345-
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, forceClosed);
345+
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);
346346

347347
#endregion
348348

0 commit comments

Comments
 (0)