mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'dev' into loading_bar
This commit is contained in:
commit
c3a8a025fa
7 changed files with 111 additions and 43 deletions
|
|
@ -323,18 +323,17 @@ namespace Flow.Launcher.Plugin
|
||||||
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK);
|
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays a standardised Flow message box.
|
/// Displays a standardised Flow progress box.
|
||||||
/// If there is issue when showing the message box, it will return null.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="caption">The caption of the message box.</param>
|
/// <param name="caption">The caption of the progress box.</param>
|
||||||
/// <param name="reportProgressAsync">
|
/// <param name="reportProgressAsync">
|
||||||
/// Time-consuming task function, whose input is the action to report progress.
|
/// Time-consuming task function, whose input is the action to report progress.
|
||||||
/// The input of the action is the progress value which is a double value between 0 and 100.
|
/// The input of the action is the progress value which is a double value between 0 and 100.
|
||||||
/// If there are any exceptions, this action will be null.
|
/// If there are any exceptions, this action will be null.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="forceClosed">When user closes the progress box manually by button or esc key, this action will be called.</param>
|
/// <param name="cancelProgress">When user cancel the progress, this action will be called.</param>
|
||||||
/// <returns>A progress box interface.</returns>
|
/// <returns></returns>
|
||||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null);
|
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start the loading bar in main window
|
/// Start the loading bar in main window
|
||||||
|
|
|
||||||
|
|
@ -35,31 +35,64 @@ namespace Flow.Launcher
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
// Initialize settings
|
// Initialize settings
|
||||||
var storage = new FlowLauncherJsonStorage<Settings>();
|
try
|
||||||
_settings = storage.Load();
|
{
|
||||||
_settings.SetStorage(storage);
|
var storage = new FlowLauncherJsonStorage<Settings>();
|
||||||
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
|
_settings = storage.Load();
|
||||||
|
_settings.SetStorage(storage);
|
||||||
|
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ShowErrorMsgBoxAndFailFast("Cannot load setting storage, please check local data directory", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the dependency injection container
|
// Configure the dependency injection container
|
||||||
var host = Host.CreateDefaultBuilder()
|
try
|
||||||
.UseContentRoot(AppContext.BaseDirectory)
|
{
|
||||||
.ConfigureServices(services => services
|
var host = Host.CreateDefaultBuilder()
|
||||||
.AddSingleton(_ => _settings)
|
.UseContentRoot(AppContext.BaseDirectory)
|
||||||
.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))
|
.ConfigureServices(services => services
|
||||||
.AddSingleton<Portable>()
|
.AddSingleton(_ => _settings)
|
||||||
.AddSingleton<SettingWindowViewModel>()
|
.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))
|
||||||
.AddSingleton<IAlphabet, PinyinAlphabet>()
|
.AddSingleton<Portable>()
|
||||||
.AddSingleton<StringMatcher>()
|
.AddSingleton<SettingWindowViewModel>()
|
||||||
.AddSingleton<Internationalization>()
|
.AddSingleton<IAlphabet, PinyinAlphabet>()
|
||||||
.AddSingleton<IPublicAPI, PublicAPIInstance>()
|
.AddSingleton<StringMatcher>()
|
||||||
.AddSingleton<MainViewModel>()
|
.AddSingleton<Internationalization>()
|
||||||
.AddSingleton<Theme>()
|
.AddSingleton<IPublicAPI, PublicAPIInstance>()
|
||||||
).Build();
|
.AddSingleton<MainViewModel>()
|
||||||
Ioc.Default.ConfigureServices(host.Services);
|
.AddSingleton<Theme>()
|
||||||
|
).Build();
|
||||||
|
Ioc.Default.ConfigureServices(host.Services);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ShowErrorMsgBoxAndFailFast("Cannot configure dependency injection container, please open new issue in Flow.Launcher", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the public API and Settings first
|
// Initialize the public API and Settings first
|
||||||
API = Ioc.Default.GetRequiredService<IPublicAPI>();
|
try
|
||||||
_settings.Initialize();
|
{
|
||||||
|
API = Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||||
|
_settings.Initialize();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ShowErrorMsgBoxAndFailFast("Cannot initialize api and settings, please open new issue in Flow.Launcher", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
|
||||||
|
{
|
||||||
|
// Firstly show users the message
|
||||||
|
MessageBox.Show(e.ToString(), message, MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
|
||||||
|
// Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
|
||||||
|
Environment.FailFast(message, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
<PackageReference Include="InputSimulator" Version="1.0.4" />
|
<PackageReference Include="InputSimulator" Version="1.0.4" />
|
||||||
<!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting since we are .Net7.0 -->
|
<!-- Do not upgrade Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.Hosting since we are .Net7.0 -->
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
|
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
|
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
|
||||||
<PackageReference Include="SemanticVersioning" Version="3.0.0" />
|
<PackageReference Include="SemanticVersioning" Version="3.0.0" />
|
||||||
<PackageReference Include="TaskScheduler" Version="2.11.0" />
|
<PackageReference Include="Jack251970.TaskScheduler" Version="2.12.1" />
|
||||||
<PackageReference Include="VirtualizingWrapPanel" Version="2.1.1" />
|
<PackageReference Include="VirtualizingWrapPanel" Version="2.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -368,6 +368,7 @@
|
||||||
<system:String x:Key="commonOK">OK</system:String>
|
<system:String x:Key="commonOK">OK</system:String>
|
||||||
<system:String x:Key="commonYes">Yes</system:String>
|
<system:String x:Key="commonYes">Yes</system:String>
|
||||||
<system:String x:Key="commonNo">No</system:String>
|
<system:String x:Key="commonNo">No</system:String>
|
||||||
|
<system:String x:Key="commonBackground">Background</system:String>
|
||||||
|
|
||||||
<!-- Crash Reporter -->
|
<!-- Crash Reporter -->
|
||||||
<system:String x:Key="reportWindow_version">Version</system:String>
|
<system:String x:Key="reportWindow_version">Version</system:String>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
Foreground="{DynamicResource PopupTextColor}"
|
Foreground="{DynamicResource PopupTextColor}"
|
||||||
ResizeMode="NoResize"
|
ResizeMode="NoResize"
|
||||||
SizeToContent="Height"
|
SizeToContent="Height"
|
||||||
|
Topmost="True"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<WindowChrome.WindowChrome>
|
<WindowChrome.WindowChrome>
|
||||||
|
|
@ -35,9 +36,32 @@
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button
|
<Button
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
|
Click="Button_Minimize"
|
||||||
|
RenderOptions.EdgeMode="Aliased"
|
||||||
|
Style="{DynamicResource TitleBarButtonStyle}">
|
||||||
|
<Path
|
||||||
|
Width="46"
|
||||||
|
Height="32"
|
||||||
|
Data="M 18,15 H 28"
|
||||||
|
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
|
||||||
|
StrokeThickness="1">
|
||||||
|
<Path.Style>
|
||||||
|
<Style TargetType="Path">
|
||||||
|
<Style.Triggers>
|
||||||
|
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
|
||||||
|
<Setter Property="Opacity" Value="0.5" />
|
||||||
|
</DataTrigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
|
</Path.Style>
|
||||||
|
</Path>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
Grid.Column="2"
|
||||||
Click="Button_Cancel"
|
Click="Button_Cancel"
|
||||||
Style="{StaticResource TitleBarCloseButtonStyle}">
|
Style="{StaticResource TitleBarCloseButtonStyle}">
|
||||||
<Path
|
<Path
|
||||||
|
|
@ -94,11 +118,17 @@
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
|
<Button
|
||||||
|
x:Name="btnBackground"
|
||||||
|
MinWidth="120"
|
||||||
|
Margin="5 0 5 0"
|
||||||
|
Click="Button_Background"
|
||||||
|
Content="{DynamicResource commonBackground}" />
|
||||||
<Button
|
<Button
|
||||||
x:Name="btnCancel"
|
x:Name="btnCancel"
|
||||||
MinWidth="120"
|
MinWidth="120"
|
||||||
Margin="5 0 5 0"
|
Margin="5 0 5 0"
|
||||||
Click="Button_Click"
|
Click="Button_Cancel"
|
||||||
Content="{DynamicResource commonCancel}" />
|
Content="{DynamicResource commonCancel}" />
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,15 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
public partial class ProgressBoxEx : Window
|
public partial class ProgressBoxEx : Window
|
||||||
{
|
{
|
||||||
private readonly Action _forceClosed;
|
private readonly Action _cancelProgress;
|
||||||
|
|
||||||
private ProgressBoxEx(Action forceClosed)
|
private ProgressBoxEx(Action cancelProgress)
|
||||||
{
|
{
|
||||||
_forceClosed = forceClosed;
|
_cancelProgress = cancelProgress;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null)
|
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null)
|
||||||
{
|
{
|
||||||
ProgressBoxEx prgBox = null;
|
ProgressBoxEx prgBox = null;
|
||||||
try
|
try
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Flow.Launcher
|
||||||
{
|
{
|
||||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
prgBox = new ProgressBoxEx(forceClosed)
|
prgBox = new ProgressBoxEx(cancelProgress)
|
||||||
{
|
{
|
||||||
Title = caption
|
Title = caption
|
||||||
};
|
};
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Flow.Launcher
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prgBox = new ProgressBoxEx(forceClosed)
|
prgBox = new ProgressBoxEx(cancelProgress)
|
||||||
{
|
{
|
||||||
Title = caption
|
Title = caption
|
||||||
};
|
};
|
||||||
|
|
@ -95,20 +95,25 @@ namespace Flow.Launcher
|
||||||
ForceClose();
|
ForceClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
ForceClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Button_Cancel(object sender, RoutedEventArgs e)
|
private void Button_Cancel(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ForceClose();
|
ForceClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Button_Minimize(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
WindowState = WindowState.Minimized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Background(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
|
|
||||||
private void ForceClose()
|
private void ForceClose()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
_forceClosed?.Invoke();
|
_cancelProgress?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ namespace Flow.Launcher
|
||||||
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
|
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
|
||||||
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);
|
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);
|
||||||
|
|
||||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, forceClosed);
|
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue