-
-
Notifications
You must be signed in to change notification settings - Fork 448
Add New API for ProgressBoxEx to Show Progress & Add Progress Display for Plugin Downloading & Improve DownloadUrl Api Function #3170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
37058f7
Improve code quality.
Jack251970 562b233
Add progress box support for downloading plugin
Jack251970 54f02e0
Use public api for ProgressBoxEx & Add support for force close event
Jack251970 d0bab86
Improve code quality
Jack251970 f69dd0f
Improve documents
Jack251970 c06ba59
Add support for cancelling download
Jack251970 07bb16c
Improve code quality
Jack251970 c907c29
Fix plugin install issue
Jack251970 675ee9e
Add translation for progress box title
Jack251970 0fabe31
Improve code quality
Jack251970 cc0fb66
Extract duplicate cleanup code into a method
Jack251970 bc84910
Use static HttpClient instance for heavy load issue
Jack251970 aff6b1a
Perserve prgBox value when force close
Jack251970 8aebf95
Check ui thread when calling close function & Update documents
Jack251970 122887e
Await close event from non-ui thread
Jack251970 6220b34
Fix dulplicated close event
Jack251970 5016334
Avoid cancelling all pending requests on shared HttpClient instance
Jack251970 381e64e
Move ProgressBoxEx to main project for better development experience
Jack251970 d36aef5
Change ProgressBoxEx namespace
Jack251970 ed7265d
Remove override close event
Jack251970 297d191
Use function to delegate the progress task
Jack251970 cc921c7
Improve progress box when exception happens
Jack251970 df3cb58
Improve code quality
Jack251970 029cb38
Fix progress box action under ui thread
Jack251970 8eb5a4d
Improve HttpDownloadAsync function & Use it in PluginManager plugin
Jack251970 1bf045f
Make fileMode usage between progress and non-progress paths consistent
Jack251970 fc2ce73
Merge branch 'dev' into dev3
Jack251970 c32435f
Use api to call download function & Add message box for all download …
Jack251970 646bad6
Use parameter for function for readability
Jack251970 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<Window | ||
x:Class="Flow.Launcher.ProgressBoxEx" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Flow.Launcher" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
x:Name="MessageBoxWindow" | ||
Width="420" | ||
Height="Auto" | ||
Background="{DynamicResource PopuBGColor}" | ||
Foreground="{DynamicResource PopupTextColor}" | ||
ResizeMode="NoResize" | ||
SizeToContent="Height" | ||
WindowStartupLocation="CenterScreen" | ||
mc:Ignorable="d"> | ||
<WindowChrome.WindowChrome> | ||
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" /> | ||
</WindowChrome.WindowChrome> | ||
<Window.InputBindings> | ||
<KeyBinding Key="Escape" Command="Close" /> | ||
</Window.InputBindings> | ||
<Window.CommandBindings> | ||
<CommandBinding Command="Close" Executed="KeyEsc_OnPress" /> | ||
</Window.CommandBindings> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
<RowDefinition MinHeight="68" /> | ||
</Grid.RowDefinitions> | ||
<StackPanel Grid.Row="0"> | ||
<StackPanel> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<Button | ||
Grid.Column="1" | ||
Click="Button_Cancel" | ||
Style="{StaticResource TitleBarCloseButtonStyle}"> | ||
<Path | ||
Width="46" | ||
Height="32" | ||
Data="M 18,11 27,20 M 18,20 27,11" | ||
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> | ||
</Grid> | ||
</StackPanel> | ||
</StackPanel> | ||
<Grid Grid.Row="1" Margin="30 0 30 24"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<TextBlock | ||
x:Name="TitleTextBlock" | ||
Grid.Row="0" | ||
MaxWidth="400" | ||
Margin="0 0 26 12" | ||
VerticalAlignment="Center" | ||
FontFamily="Segoe UI" | ||
FontSize="20" | ||
FontWeight="SemiBold" | ||
TextAlignment="Left" | ||
TextWrapping="Wrap" /> | ||
<ProgressBar | ||
x:Name="ProgressBar" | ||
Grid.Row="1" | ||
Margin="0 0 26 0" | ||
Maximum="100" | ||
Minimum="0" | ||
Value="0" /> | ||
</Grid> | ||
<Border | ||
Grid.Row="2" | ||
Margin="0 0 0 0" | ||
Background="{DynamicResource PopupButtonAreaBGColor}" | ||
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}" | ||
BorderThickness="0 1 0 0"> | ||
<WrapPanel | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Orientation="Horizontal"> | ||
<Button | ||
x:Name="btnCancel" | ||
MinWidth="120" | ||
Margin="5 0 5 0" | ||
Click="Button_Click" | ||
Content="{DynamicResource commonCancel}" /> | ||
</WrapPanel> | ||
</Border> | ||
</Grid> | ||
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
using Flow.Launcher.Infrastructure.Logger; | ||
|
||
namespace Flow.Launcher | ||
{ | ||
public partial class ProgressBoxEx : Window | ||
{ | ||
private readonly Action _forceClosed; | ||
|
||
private ProgressBoxEx(Action forceClosed) | ||
{ | ||
_forceClosed = forceClosed; | ||
InitializeComponent(); | ||
} | ||
|
||
public static async Task ShowAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null) | ||
{ | ||
ProgressBoxEx prgBox = null; | ||
try | ||
{ | ||
if (!Application.Current.Dispatcher.CheckAccess()) | ||
{ | ||
await Application.Current.Dispatcher.InvokeAsync(() => | ||
{ | ||
prgBox = new ProgressBoxEx(forceClosed) | ||
{ | ||
Title = caption | ||
}; | ||
prgBox.TitleTextBlock.Text = caption; | ||
prgBox.Show(); | ||
}); | ||
} | ||
else | ||
{ | ||
prgBox = new ProgressBoxEx(forceClosed) | ||
{ | ||
Title = caption | ||
}; | ||
prgBox.TitleTextBlock.Text = caption; | ||
prgBox.Show(); | ||
} | ||
|
||
await reportProgressAsync(prgBox.ReportProgress).ConfigureAwait(false); | ||
} | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
catch (Exception e) | ||
{ | ||
Log.Error($"|ProgressBoxEx.Show|An error occurred: {e.Message}"); | ||
|
||
await reportProgressAsync(null).ConfigureAwait(false); | ||
} | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
finally | ||
{ | ||
if (!Application.Current.Dispatcher.CheckAccess()) | ||
{ | ||
await Application.Current.Dispatcher.InvokeAsync(() => | ||
{ | ||
prgBox?.Close(); | ||
}); | ||
} | ||
else | ||
{ | ||
prgBox?.Close(); | ||
} | ||
} | ||
} | ||
|
||
private void ReportProgress(double progress) | ||
{ | ||
if (!Application.Current.Dispatcher.CheckAccess()) | ||
{ | ||
Application.Current.Dispatcher.Invoke(() => ReportProgress(progress)); | ||
return; | ||
} | ||
|
||
if (progress < 0) | ||
{ | ||
ProgressBar.Value = 0; | ||
} | ||
else if (progress >= 100) | ||
{ | ||
ProgressBar.Value = 100; | ||
Close(); | ||
} | ||
else | ||
{ | ||
ProgressBar.Value = progress; | ||
} | ||
} | ||
|
||
private void KeyEsc_OnPress(object sender, ExecutedRoutedEventArgs e) | ||
{ | ||
ForceClose(); | ||
} | ||
|
||
private void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
ForceClose(); | ||
} | ||
|
||
private void Button_Cancel(object sender, RoutedEventArgs e) | ||
{ | ||
ForceClose(); | ||
} | ||
|
||
private void ForceClose() | ||
{ | ||
Close(); | ||
_forceClosed?.Invoke(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.