From bfee170d0fbeba908d9f228771af7a08351e7a10 Mon Sep 17 00:00:00 2001 From: Sparrkle Date: Wed, 5 Oct 2022 16:20:41 +0900 Subject: [PATCH 1/6] Changed ProgressBar Storyboard (No Dispatcher) --- Flow.Launcher/MainWindow.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 60 +++++++++++--------------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index dc3b3f1454b..7d8c195f33d 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -250,7 +250,6 @@ Height="2" HorizontalAlignment="Right" StrokeThickness="1" - Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" X1="-150" X2="-50" diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 332e0f5024a..1dd9fe34d6e 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -28,9 +28,6 @@ namespace Flow.Launcher public partial class MainWindow { #region Private Fields - - private readonly Storyboard _progressBarStoryboard = new Storyboard(); - private bool isProgressBarStoryboardPaused; private Settings _settings; private NotifyIcon _notifyIcon; private ContextMenu contextMenu; @@ -119,39 +116,9 @@ private void OnLoaded(object sender, RoutedEventArgs _) _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; } case nameof(MainViewModel.QueryTextCursorMovedToEnd): @@ -291,17 +258,32 @@ private void ToggleGameMode() } private void InitProgressbarAnimation() { - var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150, - new Duration(new TimeSpan(0, 0, 0, 0, 1600))); + var progressBarStoryBoard = new Storyboard(); + + var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 50, 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(); + + var beginStoryboard = new BeginStoryboard(); + beginStoryboard.Storyboard = progressBarStoryBoard; + + var trigger = new Trigger { Property = System.Windows.Shapes.Line.VisibilityProperty, Value = Visibility.Visible }; + trigger.EnterActions.Add(beginStoryboard); + + var progressStyle = new Style(typeof(System.Windows.Shapes.Line)); + progressStyle.BasedOn = FindResource("PendingLineStyle") as Style; + progressStyle.Triggers.Add(trigger); + + ProgressBar.Style = progressStyle; _viewModel.ProgressBarVisibility = Visibility.Hidden; - isProgressBarStoryboardPaused = true; } public void WindowAnimator() { From 6f0c2549cea809b0a1e406951f734daf4fb8cc0d Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 24 Nov 2022 14:01:32 -0600 Subject: [PATCH 2/6] also pause animation when exit visible --- Flow.Launcher/MainWindow.xaml.cs | 151 ++++++++++++++++++------------- 1 file changed, 89 insertions(+), 62 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 245ab4d051f..efa43000bf2 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -36,6 +36,7 @@ namespace Flow.Launcher public partial class MainWindow { #region Private Fields + private Settings _settings; private NotifyIcon _notifyIcon; private ContextMenu contextMenu; @@ -50,7 +51,7 @@ public MainWindow(Settings settings, MainViewModel mainVM) DataContext = mainVM; _viewModel = mainVM; _settings = settings; - + InitializeComponent(); InitializePosition(); animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); @@ -60,7 +61,7 @@ public MainWindow() { InitializeComponent(); } - + private void OnCopy(object sender, ExecutedRoutedEventArgs e) { if (QueryTextBox.SelectionLength == 0) @@ -108,29 +109,29 @@ private void OnLoaded(object sender, RoutedEventArgs _) switch (e.PropertyName) { case nameof(MainViewModel.MainWindowVisibilityStatus): + { + if (_viewModel.MainWindowVisibilityStatus) { - if (_viewModel.MainWindowVisibilityStatus) + if (_settings.UseSound) { - if (_settings.UseSound) - { - animationSound.Position = TimeSpan.Zero; - animationSound.Play(); - } - UpdatePosition(); - Activate(); - QueryTextBox.Focus(); - _settings.ActivateTimes++; - if (!_viewModel.LastQuerySelected) - { - QueryTextBox.SelectAll(); - _viewModel.LastQuerySelected = true; - } - - if(_settings.UseAnimation) - WindowAnimator(); + animationSound.Position = TimeSpan.Zero; + animationSound.Play(); } - break; + UpdatePosition(); + Activate(); + QueryTextBox.Focus(); + _settings.ActivateTimes++; + if (!_viewModel.LastQuerySelected) + { + QueryTextBox.SelectAll(); + _viewModel.LastQuerySelected = true; + } + + if (_settings.UseAnimation) + WindowAnimator(); } + break; + } case nameof(MainViewModel.QueryTextCursorMovedToEnd): if (_viewModel.QueryTextCursorMovedToEnd) { @@ -211,35 +212,45 @@ private void InitializeNotifyIcon() Visible = !_settings.HideNotifyIcon }; contextMenu = new ContextMenu(); - var openIcon = new FontIcon { Glyph = "\ue71e" }; + var openIcon = new FontIcon + { + Glyph = "\ue71e" + }; var open = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", - Icon = openIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon + }; + var gamemodeIcon = new FontIcon + { + Glyph = "\ue7fc" }; - 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 positionresetIcon = new FontIcon { Glyph = "\ue73f" }; var positionreset = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), - Icon = positionresetIcon + Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon + }; + var settingsIcon = new FontIcon + { + Glyph = "\ue713" }; - var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), - Icon = settingsIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon + }; + var exitIcon = new FontIcon + { + Glyph = "\ue7e8" }; - 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(); @@ -300,10 +311,10 @@ private void ToggleGameMode() } private async void PositionReset() { - _viewModel.Show(); - await Task.Delay(300); // If don't give a time, Positioning will be weird. - Left = HorizonCenter(); - Top = VerticalCenter(); + _viewModel.Show(); + await Task.Delay(300); // If don't give a time, Positioning will be weird. + Left = HorizonCenter(); + Top = VerticalCenter(); } private void InitProgressbarAnimation() { @@ -320,14 +331,30 @@ private void InitProgressbarAnimation() da.Freeze(); da1.Freeze(); - var beginStoryboard = new BeginStoryboard(); - beginStoryboard.Storyboard = progressBarStoryBoard; + const string progressBarAnimationName = "ProgressBarAnimation"; + var beginStoryboard = new BeginStoryboard + { + Name = progressBarAnimationName, Storyboard = progressBarStoryBoard + }; + + var stopStoryboard = new StopStoryboard() + { + BeginStoryboardName = progressBarAnimationName + }; - var trigger = new Trigger { Property = System.Windows.Shapes.Line.VisibilityProperty, Value = Visibility.Visible }; + var trigger = new Trigger + { + Property = VisibilityProperty, Value = Visibility.Visible + }; trigger.EnterActions.Add(beginStoryboard); + trigger.ExitActions.Add(stopStoryboard); + - var progressStyle = new Style(typeof(System.Windows.Shapes.Line)); - progressStyle.BasedOn = FindResource("PendingLineStyle") as Style; + var progressStyle = new Style(typeof(System.Windows.Shapes.Line)) + { + BasedOn = FindResource("PendingLineStyle") as Style + }; + progressStyle.RegisterName(progressBarAnimationName, beginStoryboard); progressStyle.Triggers.Add(trigger); ProgressBar.Style = progressStyle; @@ -343,7 +370,7 @@ public void WindowAnimator() UpdatePosition(); Storyboard sb = new Storyboard(); Storyboard iconsb = new Storyboard(); - CircleEase easing = new CircleEase(); // or whatever easing class you want + CircleEase easing = new CircleEase(); // or whatever easing class you want easing.EasingMode = EasingMode.EaseInOut; var da = new DoubleAnimation { @@ -360,14 +387,14 @@ public void WindowAnimator() Duration = TimeSpan.FromSeconds(0.25), FillBehavior = FillBehavior.Stop }; - var da3 = new DoubleAnimation - { - From = 12, - To = 0, - EasingFunction = easing, - Duration = TimeSpan.FromSeconds(0.36), - FillBehavior = FillBehavior.Stop - }; + var da3 = new DoubleAnimation + { + From = 12, + To = 0, + EasingFunction = easing, + Duration = TimeSpan.FromSeconds(0.36), + FillBehavior = FillBehavior.Stop + }; Storyboard.SetTarget(da, this); Storyboard.SetTargetProperty(da, new PropertyPath(Window.OpacityProperty)); Storyboard.SetTargetProperty(da2, new PropertyPath(Window.TopProperty)); @@ -395,10 +422,10 @@ private void OnPreviewDragOver(object sender, DragEventArgs e) private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) { _viewModel.Hide(); - - if(_settings.UseAnimation) + + if (_settings.UseAnimation) await Task.Delay(100); - + App.API.OpenSettingDialog(); } @@ -416,7 +443,7 @@ private async void OnDeactivated(object sender, EventArgs e) // and always after Settings window is closed. if (_settings.UseAnimation) await Task.Delay(100); - + if (_settings.HideWhenDeactive) { _viewModel.Hide(); @@ -454,7 +481,7 @@ public void HideStartup() _viewModel.Show(); } } - + public double HorizonCenter() { var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); @@ -536,9 +563,9 @@ private void OnKeyDown(object sender, KeyEventArgs e) && QueryTextBox.Text.Length > 0 && QueryTextBox.CaretIndex == QueryTextBox.Text.Length) { - var queryWithoutActionKeyword = + var queryWithoutActionKeyword = QueryBuilder.Build(QueryTextBox.Text.Trim(), PluginManager.NonGlobalPlugins).Search; - + if (FilesFolders.IsLocationPathString(queryWithoutActionKeyword)) { _viewModel.BackspaceCommand.Execute(null); @@ -574,7 +601,7 @@ public void InitializeColorScheme() private void QueryTextBox_KeyUp(object sender, KeyEventArgs e) { - if(_viewModel.QueryText != QueryTextBox.Text) + if (_viewModel.QueryText != QueryTextBox.Text) { BindingExpression be = QueryTextBox.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty); be.UpdateSource(); From c28a37a9c4558fea7a774c30f438ab207eecdfb3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 19:30:54 +0800 Subject: [PATCH 3/6] Fix build issue --- Flow.Launcher/MainWindow.xaml.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index d121108858a..eba2ff171fa 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -333,7 +333,6 @@ private void InitializeNotifyIcon() 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 { @@ -341,26 +340,22 @@ private void InitializeNotifyIcon() _settings.Hotkey + ")", Icon = openIcon }; + var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" }; var gamemode = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon }; + var positionresetIcon = new FontIcon { Glyph = "\ue73f" }; var positionreset = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon }; - var settingsIcon = new FontIcon - { - Glyph = "\ue713" - }; + var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon }; - var exitIcon = new FontIcon - { - Glyph = "\ue7e8" - }; + var exitIcon = new FontIcon { Glyph = "\ue7e8" }; var exit = new MenuItem { Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon From 5d2778a7ab502eb2c3f889aa1ada9d725b89a81a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 19:32:48 +0800 Subject: [PATCH 4/6] Code cleanup --- Flow.Launcher/MainWindow.xaml.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index eba2ff171fa..4a3b58281f9 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -69,13 +69,11 @@ public MainWindow(Settings settings, MainViewModel mainVM) }; } - DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false }; - public MainWindow() { InitializeComponent(); } - + private int _initialWidth; private int _initialHeight; @@ -343,22 +341,26 @@ private void InitializeNotifyIcon() 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 { - Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon + Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), + Icon = positionresetIcon }; var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), + Icon = settingsIcon }; 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(); @@ -636,7 +638,7 @@ private async void OnDeactivated(object sender, EventArgs e) // and always after Settings window is closed. if (_settings.UseAnimation) await Task.Delay(100); - + if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible) { _viewModel.Hide(); @@ -677,7 +679,7 @@ public void HideStartup() _viewModel.Show(); } } - + public Screen SelectedScreen() { Screen screen = null; From e862b3861d2669ff2d6822fe3874056ce71172cc Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 19:40:03 +0800 Subject: [PATCH 5/6] Cleanup PendingLineStyle --- Flow.Launcher/MainWindow.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index d2f0ce79f62..0720501cab5 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -331,7 +331,6 @@ HorizontalAlignment="Center" VerticalAlignment="Bottom" StrokeThickness="2" - Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" X1="-100" X2="0" diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 4a3b58281f9..6836d9b3a53 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -27,6 +27,7 @@ using System.Windows.Media; using System.Windows.Interop; using Windows.Win32; +using System.Windows.Shapes; namespace Flow.Launcher { @@ -460,8 +461,7 @@ private void InitProgressbarAnimation() trigger.EnterActions.Add(beginStoryboard); trigger.ExitActions.Add(stopStoryboard); - - var progressStyle = new Style(typeof(System.Windows.Shapes.Line)) + var progressStyle = new Style(typeof(Line)) { BasedOn = FindResource("PendingLineStyle") as Style }; From 9b60eac42b0dcc4865475bd672d0812fd3666da2 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 15 Mar 2025 21:50:10 +0800 Subject: [PATCH 6/6] Code cleanup --- Flow.Launcher/MainWindow.xaml.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 6836d9b3a53..1d4a2610104 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -62,7 +62,7 @@ public MainWindow(Settings settings, MainViewModel mainVM) DataObject.AddPastingHandler(QueryTextBox, OnPaste); - this.Loaded += (_, _) => + Loaded += (_, _) => { var handle = new WindowInteropHelper(this).Handle; var win = HwndSource.FromHwnd(handle); @@ -70,11 +70,6 @@ public MainWindow(Settings settings, MainViewModel mainVM) }; } - public MainWindow() - { - InitializeComponent(); - } - private int _initialWidth; private int _initialHeight;