Merge pull request #1445 from Sparrkle/ProgressBarDispatcher

Fixed Progressbar Dispatcher Exception
This commit is contained in:
Jack Ye 2025-03-16 16:45:49 +08:00 committed by GitHub
commit eb2a24db62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 49 deletions

View file

@ -331,7 +331,6 @@
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
StrokeThickness="2"
Style="{DynamicResource PendingLineStyle}"
Visibility="{Binding ProgressBarVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
X1="-100"
X2="0"
@ -377,8 +376,8 @@
HorizontalAlignment="Stretch"
Style="{DynamicResource SeparatorStyle}" />
</ContentControl>
</Grid>
<Border Style="{DynamicResource WindowRadius}">
<Border.Clip>
<MultiBinding Converter="{StaticResource BorderClipConverter}">

View file

@ -27,6 +27,7 @@ using DataObject = System.Windows.DataObject;
using System.Windows.Media;
using System.Windows.Interop;
using Windows.Win32;
using System.Windows.Shapes;
namespace Flow.Launcher
{
@ -34,8 +35,6 @@ namespace Flow.Launcher
{
#region Private Fields
private readonly Storyboard _progressBarStoryboard = new Storyboard();
private bool isProgressBarStoryboardPaused;
private Settings _settings;
private NotifyIcon _notifyIcon;
private ContextMenu contextMenu = new ContextMenu();
@ -63,7 +62,7 @@ namespace Flow.Launcher
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
this.Loaded += (_, _) =>
Loaded += (_, _) =>
{
var handle = new WindowInteropHelper(this).Handle;
var win = HwndSource.FromHwnd(handle);
@ -71,13 +70,6 @@ namespace Flow.Launcher
};
}
DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false };
public MainWindow()
{
InitializeComponent();
}
private int _initialWidth;
private int _initialHeight;
@ -225,39 +217,9 @@ namespace Flow.Launcher
_viewModel.LastQuerySelected = true;
}
if (_viewModel.ProgressBarVisibility == Visibility.Visible &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
if (_settings.UseAnimation)
WindowAnimator();
}
else if (!isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
});
break;
}
case nameof(MainViewModel.ProgressBarVisibility):
{
Dispatcher.Invoke(() =>
{
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Stop(ProgressBar);
isProgressBarStoryboardPaused = true;
}
else if (_viewModel.MainWindowVisibilityStatus &&
isProgressBarStoryboardPaused)
{
_progressBarStoryboard.Begin(ProgressBar, true);
isProgressBarStoryboardPaused = false;
}
});
break;
}
@ -365,7 +327,6 @@ namespace Flow.Launcher
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
Visible = !_settings.HideNotifyIcon
};
var openIcon = new FontIcon { Glyph = "\ue71e" };
var open = new MenuItem
{
@ -376,7 +337,8 @@ namespace Flow.Launcher
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
var gamemode = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
Icon = gamemodeIcon
};
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
var positionreset = new MenuItem
@ -393,7 +355,8 @@ namespace Flow.Launcher
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
var exit = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
Icon = exitIcon
};
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@ -460,17 +423,49 @@ namespace Flow.Launcher
private void InitProgressbarAnimation()
{
var progressBarStoryBoard = new Storyboard();
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 0,
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
_progressBarStoryboard.Children.Add(da);
_progressBarStoryboard.Children.Add(da1);
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
progressBarStoryBoard.Children.Add(da);
progressBarStoryBoard.Children.Add(da1);
progressBarStoryBoard.RepeatBehavior = RepeatBehavior.Forever;
da.Freeze();
da1.Freeze();
const string progressBarAnimationName = "ProgressBarAnimation";
var beginStoryboard = new BeginStoryboard
{
Name = progressBarAnimationName, Storyboard = progressBarStoryBoard
};
var stopStoryboard = new StopStoryboard()
{
BeginStoryboardName = progressBarAnimationName
};
var trigger = new Trigger
{
Property = VisibilityProperty, Value = Visibility.Visible
};
trigger.EnterActions.Add(beginStoryboard);
trigger.ExitActions.Add(stopStoryboard);
var progressStyle = new Style(typeof(Line))
{
BasedOn = FindResource("PendingLineStyle") as Style
};
progressStyle.RegisterName(progressBarAnimationName, beginStoryboard);
progressStyle.Triggers.Add(trigger);
ProgressBar.Style = progressStyle;
_viewModel.ProgressBarVisibility = Visibility.Hidden;
isProgressBarStoryboardPaused = true;
}
public void WindowAnimator()