From 04aea73d0cc90bffa1ddc4accf771d4feee0430b Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 7 Oct 2021 21:34:42 +0900 Subject: [PATCH 01/11] - Fix ProgressBar (Finally!) --- Flow.Launcher/MainWindow.xaml | 4 ++-- Flow.Launcher/MainWindow.xaml.cs | 4 ++-- Flow.Launcher/SettingWindow.xaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index db015392a19..73b13be8c95 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -101,11 +101,11 @@ - + + Y1="0" Y2="0" X1="-150" X2="-50" Height="2" Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}},Path=ActualWidth}" StrokeThickness="1"> diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 95e7ed6a82d..e84a3148e2d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -207,9 +207,9 @@ private void InitializeNotifyIcon() private void InitProgressbarAnimation() { - var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, + var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); - var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth, 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); diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 7dc8829bec7..2a552e7d821 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -447,7 +447,7 @@ - + a From 5d670194fe7ae98a5aebd6ff439c633ba2abe230 Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Wed, 13 Oct 2021 01:45:18 +0900 Subject: [PATCH 02/11] Add delay --- Flow.Launcher/Helper/HotKeyMapper.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index d5fcabace05..87ef0628b7d 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -6,6 +6,8 @@ using Flow.Launcher.Core.Resource; using System.Windows; using Flow.Launcher.ViewModel; +using System.Threading.Tasks; +using System.Threading; namespace Flow.Launcher.Helper { @@ -58,8 +60,10 @@ internal static void OnHotkey(object sender, HotkeyEventArgs e) if (!ShouldIgnoreHotkeys()) { UpdateLastQUeryMode(); - - mainViewModel.ToggleFlowLauncher(); + + var overlayTask = Task.Delay(20).ContinueWith(_ => { + mainViewModel.ToggleFlowLauncher(); + }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); e.Handled = true; } } @@ -77,7 +81,7 @@ private static void UpdateLastQUeryMode() switch(settings.LastQueryMode) { case LastQueryMode.Empty: - mainViewModel.ChangeQueryText(string.Empty); + mainViewModel.ChangeQueryText(""); break; case LastQueryMode.Preserved: mainViewModel.LastQuerySelected = true; From abf91dc8cb080ff6634d3556fabdf323bf7f7be2 Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Wed, 13 Oct 2021 02:30:04 +0900 Subject: [PATCH 03/11] add Opacity value --- Flow.Launcher/Helper/HotKeyMapper.cs | 4 ++-- Flow.Launcher/ViewModel/MainViewModel.cs | 27 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 87ef0628b7d..b9eee1a1797 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -60,8 +60,8 @@ internal static void OnHotkey(object sender, HotkeyEventArgs e) if (!ShouldIgnoreHotkeys()) { UpdateLastQUeryMode(); - - var overlayTask = Task.Delay(20).ContinueWith(_ => { + mainViewModel.ToggleFlowLauncherOpacity(); + var overlayTask = Task.Delay(30).ContinueWith(_ => { mainViewModel.ToggleFlowLauncher(); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); e.Handled = true; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 4212280bb3b..80378f01898 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -14,6 +14,7 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; +using Flow.Launcher.Helper; using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; @@ -156,7 +157,15 @@ private void InitializeKeyCommands() } else { - MainWindowVisibility = Visibility.Collapsed; + + + Application.Current.MainWindow.Opacity = 0; + + var overlayTask = Task.Delay(30).ContinueWith(_ => { + MainWindowVisibility = Visibility.Collapsed; + }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + + } }); @@ -664,14 +673,30 @@ internal void ToggleFlowLauncher() { if (MainWindowVisibility != Visibility.Visible) { + MainWindowVisibility = Visibility.Visible; } else { + MainWindowVisibility = Visibility.Collapsed; } } + internal void ToggleFlowLauncherOpacity() + { + if (MainWindowVisibility != Visibility.Visible) + { + + Application.Current.MainWindow.Opacity = 1; + } + else + { + + Application.Current.MainWindow.Opacity = 0; + } + } + #endregion #region Public Methods From 73696250e1592d4612d9c586db5c0e6cd8a40c2f Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Wed, 13 Oct 2021 02:30:04 +0900 Subject: [PATCH 04/11] add Opacity value --- Flow.Launcher/Helper/HotKeyMapper.cs | 4 ++-- Flow.Launcher/ViewModel/MainViewModel.cs | 26 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 87ef0628b7d..b9eee1a1797 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -60,8 +60,8 @@ internal static void OnHotkey(object sender, HotkeyEventArgs e) if (!ShouldIgnoreHotkeys()) { UpdateLastQUeryMode(); - - var overlayTask = Task.Delay(20).ContinueWith(_ => { + mainViewModel.ToggleFlowLauncherOpacity(); + var overlayTask = Task.Delay(30).ContinueWith(_ => { mainViewModel.ToggleFlowLauncher(); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); e.Handled = true; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 4212280bb3b..13acc470aac 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -156,7 +156,15 @@ private void InitializeKeyCommands() } else { - MainWindowVisibility = Visibility.Collapsed; + + + Application.Current.MainWindow.Opacity = 0; + + var overlayTask = Task.Delay(30).ContinueWith(_ => { + MainWindowVisibility = Visibility.Collapsed; + }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + + } }); @@ -664,14 +672,30 @@ internal void ToggleFlowLauncher() { if (MainWindowVisibility != Visibility.Visible) { + MainWindowVisibility = Visibility.Visible; } else { + MainWindowVisibility = Visibility.Collapsed; } } + internal void ToggleFlowLauncherOpacity() + { + if (MainWindowVisibility != Visibility.Visible) + { + + Application.Current.MainWindow.Opacity = 1; + } + else + { + + Application.Current.MainWindow.Opacity = 0; + } + } + #endregion #region Public Methods From 4a37900d49b4fcdfa6dbd68c89604b96951d7b3a Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 01:00:16 +0900 Subject: [PATCH 05/11] On Load Animation (WIP) --- Flow.Launcher/Helper/HotKeyMapper.cs | 4 ++-- Flow.Launcher/MainWindow.xaml | 16 ++++++++++++++++ Flow.Launcher/ViewModel/MainViewModel.cs | 3 +-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index b9eee1a1797..21f277b99c1 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -63,7 +63,7 @@ internal static void OnHotkey(object sender, HotkeyEventArgs e) mainViewModel.ToggleFlowLauncherOpacity(); var overlayTask = Task.Delay(30).ContinueWith(_ => { mainViewModel.ToggleFlowLauncher(); - }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + }); e.Handled = true; } } @@ -81,7 +81,7 @@ private static void UpdateLastQUeryMode() switch(settings.LastQueryMode) { case LastQueryMode.Empty: - mainViewModel.ChangeQueryText(""); + mainViewModel.ChangeQueryText(string.Empty); break; case LastQueryMode.Preserved: mainViewModel.LastQuerySelected = true; diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 73b13be8c95..d41e7419afd 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -28,6 +28,22 @@ PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 80378f01898..d47c540225d 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -14,7 +14,6 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.Helper; using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; @@ -163,7 +162,7 @@ private void InitializeKeyCommands() var overlayTask = Task.Delay(30).ContinueWith(_ => { MainWindowVisibility = Visibility.Collapsed; - }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + }); } From ad186a320a06b7ea5b93aa64476458bd4acc3621 Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 01:00:16 +0900 Subject: [PATCH 06/11] On Load Animation (WIP) --- Flow.Launcher/Helper/HotKeyMapper.cs | 4 ++-- Flow.Launcher/MainWindow.xaml | 16 ++++++++++++++++ Flow.Launcher/SettingWindow.xaml | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 3 +-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index b9eee1a1797..21f277b99c1 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -63,7 +63,7 @@ internal static void OnHotkey(object sender, HotkeyEventArgs e) mainViewModel.ToggleFlowLauncherOpacity(); var overlayTask = Task.Delay(30).ContinueWith(_ => { mainViewModel.ToggleFlowLauncher(); - }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + }); e.Handled = true; } } @@ -81,7 +81,7 @@ private static void UpdateLastQUeryMode() switch(settings.LastQueryMode) { case LastQueryMode.Empty: - mainViewModel.ChangeQueryText(""); + mainViewModel.ChangeQueryText(string.Empty); break; case LastQueryMode.Preserved: mainViewModel.LastQuerySelected = true; diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 73b13be8c95..d41e7419afd 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -28,6 +28,22 @@ PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> + + + + + + + + + + + + + + + + diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 2a552e7d821..7dc8829bec7 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -447,7 +447,7 @@ - a + diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 80378f01898..d47c540225d 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -14,7 +14,6 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.Helper; using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Storage; using Flow.Launcher.Infrastructure.Logger; @@ -163,7 +162,7 @@ private void InitializeKeyCommands() var overlayTask = Task.Delay(30).ContinueWith(_ => { MainWindowVisibility = Visibility.Collapsed; - }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); + }); } From 8326ba9cfbe199ee7d49a38e1ca08277ec30c71b Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 09:00:58 +0900 Subject: [PATCH 07/11] - change visibility call structure (like powertoy) - add some opacity trick for empty query - remove start animation --- Flow.Launcher/MainWindow.xaml | 16 ----- Flow.Launcher/MainWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 91 +++++++++++++++++++++--- 3 files changed, 84 insertions(+), 25 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index d41e7419afd..73b13be8c95 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -28,22 +28,6 @@ PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> - - - - - - - - - - - - - - - - diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index e84a3148e2d..057c3f07d09 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -262,7 +262,7 @@ private void OnDeactivated(object sender, EventArgs e) { if (_settings.HideWhenDeactive) { - Hide(); + _viewModel.Hide(); } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 1a08bd15594..eee96ecf405 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -176,10 +176,18 @@ private void InitializeKeyCommands() } else { - UpdateLastQUeryMode(); - var overlayTask = Task.Delay(50).ContinueWith(_ => { - MainWindowVisibility = Visibility.Collapsed; - }); + Hide(); + } + }); + + ClearQueryCommand = new RelayCommand(_ => + { + if (!string.IsNullOrEmpty(QueryText)) + { + ChangeQueryText(string.Empty); + + // Push Event to UI SystemQuery has changed + //OnPropertyChanged(nameof(SystemQueryText)); } }); @@ -217,7 +225,8 @@ private void InitializeKeyCommands() if (hideWindow) { - MainWindowVisibility = Visibility.Collapsed; + //MainWindowVisibility = Visibility.Collapsed; + Hide(); } if (SelectedIsFromQueryResults()) @@ -267,7 +276,8 @@ private void InitializeKeyCommands() Owner = Application.Current.MainWindow }; - MainWindowVisibility = Visibility.Collapsed; + //MainWindowVisibility = Visibility.Collapsed; + Hide(); PluginManager .ReloadData() @@ -372,6 +382,7 @@ private ResultsViewModel SelectedResults public ICommand LoadHistoryCommand { get; set; } public ICommand OpenResultCommand { get; set; } public ICommand ReloadPluginDataCommand { get; set; } + public ICommand ClearQueryCommand { get; private set; } public string OpenResultCommandModifiers { get; private set; } @@ -683,7 +694,7 @@ private void SetOpenResultModifiers() OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers; } - internal void ToggleFlowLauncher() + public void ToggleFlowLauncher() { if (MainWindowVisibility != Visibility.Visible) { @@ -691,12 +702,76 @@ internal void ToggleFlowLauncher() } else { - MainWindowVisibility = Visibility.Collapsed; + if (_settings.LastQueryMode == LastQueryMode.Empty) + { + Application.Current.MainWindow.Opacity = 0; // Trick for no delay + ClearQueryCommand.Execute(null); + Task.Run(() => + { + Thread.Sleep(100); + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MainWindowVisibility = Visibility.Collapsed; + Application.Current.MainWindow.Opacity = 1; + })); + }); + } + else + { + + MainWindowVisibility = Visibility.Collapsed; + } + } + } + + public void Hide() + { + if (MainWindowVisibility != Visibility.Collapsed) + { + ToggleFlowLauncher(); } } #endregion + private void OnHotkey() + { + if (!ShouldIgnoreHotkeys()) + { + // If launcher window was hidden and the hotkey was pressed, start telemetry event + + if (_settings.LastQueryMode == LastQueryMode.Empty) + { + ChangeQueryText(string.Empty); + } + else if (_settings.LastQueryMode == LastQueryMode.Preserved) + { + LastQuerySelected = true; + } + else if (_settings.LastQueryMode == LastQueryMode.Selected) + { + LastQuerySelected = false; + } + else + { + throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>"); + } + + ToggleFlowLauncher(); + } + } + + + /// + /// Checks if Flow Launcher should ignore any hotkeys + /// + private bool ShouldIgnoreHotkeys() + { + return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); + } + + + #region Public Methods public void Save() From f77d45068de108f877eb2a4fa76890b217608596 Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 09:00:58 +0900 Subject: [PATCH 08/11] - change visibility call structure (like powertoy) - add some opacity trick for empty query - remove start animation --- Flow.Launcher/MainWindow.xaml | 16 ----- Flow.Launcher/MainWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 90 +++++++++++++++++++++--- 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index d41e7419afd..73b13be8c95 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -28,22 +28,6 @@ PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> - - - - - - - - - - - - - - - - diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index e84a3148e2d..057c3f07d09 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -262,7 +262,7 @@ private void OnDeactivated(object sender, EventArgs e) { if (_settings.HideWhenDeactive) { - Hide(); + _viewModel.Hide(); } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 1a08bd15594..19f0ae81191 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -176,10 +176,18 @@ private void InitializeKeyCommands() } else { - UpdateLastQUeryMode(); - var overlayTask = Task.Delay(50).ContinueWith(_ => { - MainWindowVisibility = Visibility.Collapsed; - }); + Hide(); + } + }); + + ClearQueryCommand = new RelayCommand(_ => + { + if (!string.IsNullOrEmpty(QueryText)) + { + ChangeQueryText(string.Empty); + + // Push Event to UI SystemQuery has changed + //OnPropertyChanged(nameof(SystemQueryText)); } }); @@ -217,7 +225,8 @@ private void InitializeKeyCommands() if (hideWindow) { - MainWindowVisibility = Visibility.Collapsed; + //MainWindowVisibility = Visibility.Collapsed; + Hide(); } if (SelectedIsFromQueryResults()) @@ -267,7 +276,8 @@ private void InitializeKeyCommands() Owner = Application.Current.MainWindow }; - MainWindowVisibility = Visibility.Collapsed; + //MainWindowVisibility = Visibility.Collapsed; + Hide(); PluginManager .ReloadData() @@ -372,6 +382,7 @@ private ResultsViewModel SelectedResults public ICommand LoadHistoryCommand { get; set; } public ICommand OpenResultCommand { get; set; } public ICommand ReloadPluginDataCommand { get; set; } + public ICommand ClearQueryCommand { get; private set; } public string OpenResultCommandModifiers { get; private set; } @@ -683,7 +694,7 @@ private void SetOpenResultModifiers() OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers; } - internal void ToggleFlowLauncher() + public void ToggleFlowLauncher() { if (MainWindowVisibility != Visibility.Visible) { @@ -691,12 +702,75 @@ internal void ToggleFlowLauncher() } else { - MainWindowVisibility = Visibility.Collapsed; + if (_settings.LastQueryMode == LastQueryMode.Empty) + { + Application.Current.MainWindow.Opacity = 0; // Trick for no delay + ClearQueryCommand.Execute(null); + Task.Run(() => + { + Thread.Sleep(100); + Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + MainWindowVisibility = Visibility.Collapsed; + Application.Current.MainWindow.Opacity = 1; + })); + }); + } + else + { + + MainWindowVisibility = Visibility.Collapsed; + } + } + } + + public void Hide() + { + if (MainWindowVisibility != Visibility.Collapsed) + { + ToggleFlowLauncher(); } } #endregion + public void OnHotkey() + { + if (!ShouldIgnoreHotkeys()) + { + + if (_settings.LastQueryMode == LastQueryMode.Empty) + { + ChangeQueryText(string.Empty); + } + else if (_settings.LastQueryMode == LastQueryMode.Preserved) + { + LastQuerySelected = true; + } + else if (_settings.LastQueryMode == LastQueryMode.Selected) + { + LastQuerySelected = false; + } + else + { + throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>"); + } + + ToggleFlowLauncher(); + } + } + + + /// + /// Checks if Flow Launcher should ignore any hotkeys + /// + private bool ShouldIgnoreHotkeys() + { + return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); + } + + + #region Public Methods public void Save() From a7ed67892acb0c4c12b3a7d0099879a197bee139 Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 13:34:46 +0900 Subject: [PATCH 09/11] - Remove duplicate method. --- Flow.Launcher/Helper/HotKeyMapper.cs | 44 ++---------------------- Flow.Launcher/SettingWindow.xaml.cs | 3 +- Flow.Launcher/ViewModel/MainViewModel.cs | 7 ++-- 3 files changed, 8 insertions(+), 46 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index ebd3761ffeb..1789b85483c 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -21,7 +21,7 @@ internal static void Initialize(MainViewModel mainVM) mainViewModel = mainVM; settings = mainViewModel._settings; - SetHotkey(settings.Hotkey, OnHotkey); + SetHotkey(settings.Hotkey, mainViewModel.OnHotkey); LoadCustomPluginHotkey(); } @@ -55,46 +55,6 @@ internal static void RemoveHotkey(string hotkeyStr) } } - internal static void OnHotkey(object sender, HotkeyEventArgs e) - { - if (!ShouldIgnoreHotkeys()) - { - UpdateLastQUeryMode(); - var overlayTask = Task.Delay(50).ContinueWith(_ => { - mainViewModel.ToggleFlowLauncher(); - }); - e.Handled = true; - } - } - - - /// - /// Checks if Flow Launcher should ignore any hotkeys - /// - private static bool ShouldIgnoreHotkeys() - { - return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); - } - - private static void UpdateLastQUeryMode() - { - switch(settings.LastQueryMode) - { - case LastQueryMode.Empty: - mainViewModel.ChangeQueryText(string.Empty); - break; - case LastQueryMode.Preserved: - mainViewModel.LastQuerySelected = true; - break; - case LastQueryMode.Selected: - mainViewModel.LastQuerySelected = false; - break; - default: - throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>"); - - } - } - internal static void LoadCustomPluginHotkey() { if (settings.CustomPluginHotkeys == null) @@ -110,7 +70,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey) { SetHotkey(hotkey.Hotkey, (s, e) => { - if (ShouldIgnoreHotkeys()) + if (mainViewModel.ShouldIgnoreHotkeys()) return; mainViewModel.MainWindowVisibility = Visibility.Visible; diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index aa341f4316a..26a0a840b9a 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -23,6 +23,7 @@ public partial class SettingWindow public readonly IPublicAPI API; private Settings settings; private SettingWindowViewModel viewModel; + private static MainViewModel mainViewModel; public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) { @@ -126,7 +127,7 @@ void OnHotkeyChanged(object sender, EventArgs e) if (HotkeyControl.CurrentHotkeyAvailable) { - HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnHotkey); + HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, mainViewModel.OnHotkey); HotKeyMapper.RemoveHotkey(settings.Hotkey); settings.Hotkey = HotkeyControl.CurrentHotkey.ToString(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6134da644bc..11e9580c912 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -21,6 +21,8 @@ using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; using System.Windows.Threading; +using NHotkey; + namespace Flow.Launcher.ViewModel { @@ -368,7 +370,6 @@ private ResultsViewModel SelectedResults } public Visibility ProgressBarVisibility { get; set; } - public Visibility MainWindowVisibility { get; set; } public ICommand EscCommand { get; set; } @@ -735,7 +736,7 @@ public void Hide() #endregion - public void OnHotkey() + public void OnHotkey(object sender, HotkeyEventArgs e) { if (!ShouldIgnoreHotkeys()) { @@ -765,7 +766,7 @@ public void OnHotkey() /// /// Checks if Flow Launcher should ignore any hotkeys /// - private bool ShouldIgnoreHotkeys() + public bool ShouldIgnoreHotkeys() { return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); } From e225c2bb7fbfde775d39c75b962867d3618c84dc Mon Sep 17 00:00:00 2001 From: Dobin Park Date: Thu, 14 Oct 2021 13:34:46 +0900 Subject: [PATCH 10/11] - Remove duplicate method. --- Flow.Launcher/Helper/HotKeyMapper.cs | 44 ++---------------------- Flow.Launcher/SettingWindow.xaml.cs | 3 +- Flow.Launcher/ViewModel/MainViewModel.cs | 9 +++-- 3 files changed, 8 insertions(+), 48 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index ebd3761ffeb..1789b85483c 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -21,7 +21,7 @@ internal static void Initialize(MainViewModel mainVM) mainViewModel = mainVM; settings = mainViewModel._settings; - SetHotkey(settings.Hotkey, OnHotkey); + SetHotkey(settings.Hotkey, mainViewModel.OnHotkey); LoadCustomPluginHotkey(); } @@ -55,46 +55,6 @@ internal static void RemoveHotkey(string hotkeyStr) } } - internal static void OnHotkey(object sender, HotkeyEventArgs e) - { - if (!ShouldIgnoreHotkeys()) - { - UpdateLastQUeryMode(); - var overlayTask = Task.Delay(50).ContinueWith(_ => { - mainViewModel.ToggleFlowLauncher(); - }); - e.Handled = true; - } - } - - - /// - /// Checks if Flow Launcher should ignore any hotkeys - /// - private static bool ShouldIgnoreHotkeys() - { - return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); - } - - private static void UpdateLastQUeryMode() - { - switch(settings.LastQueryMode) - { - case LastQueryMode.Empty: - mainViewModel.ChangeQueryText(string.Empty); - break; - case LastQueryMode.Preserved: - mainViewModel.LastQuerySelected = true; - break; - case LastQueryMode.Selected: - mainViewModel.LastQuerySelected = false; - break; - default: - throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>"); - - } - } - internal static void LoadCustomPluginHotkey() { if (settings.CustomPluginHotkeys == null) @@ -110,7 +70,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey) { SetHotkey(hotkey.Hotkey, (s, e) => { - if (ShouldIgnoreHotkeys()) + if (mainViewModel.ShouldIgnoreHotkeys()) return; mainViewModel.MainWindowVisibility = Visibility.Visible; diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index aa341f4316a..26a0a840b9a 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -23,6 +23,7 @@ public partial class SettingWindow public readonly IPublicAPI API; private Settings settings; private SettingWindowViewModel viewModel; + private static MainViewModel mainViewModel; public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) { @@ -126,7 +127,7 @@ void OnHotkeyChanged(object sender, EventArgs e) if (HotkeyControl.CurrentHotkeyAvailable) { - HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnHotkey); + HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, mainViewModel.OnHotkey); HotKeyMapper.RemoveHotkey(settings.Hotkey); settings.Hotkey = HotkeyControl.CurrentHotkey.ToString(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6134da644bc..f136ac27993 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -21,6 +21,8 @@ using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; using System.Windows.Threading; +using NHotkey; + namespace Flow.Launcher.ViewModel { @@ -225,7 +227,6 @@ private void InitializeKeyCommands() if (hideWindow) { - //MainWindowVisibility = Visibility.Collapsed; Hide(); } @@ -276,7 +277,6 @@ private void InitializeKeyCommands() Owner = Application.Current.MainWindow }; - //MainWindowVisibility = Visibility.Collapsed; Hide(); PluginManager @@ -368,7 +368,6 @@ private ResultsViewModel SelectedResults } public Visibility ProgressBarVisibility { get; set; } - public Visibility MainWindowVisibility { get; set; } public ICommand EscCommand { get; set; } @@ -735,7 +734,7 @@ public void Hide() #endregion - public void OnHotkey() + public void OnHotkey(object sender, HotkeyEventArgs e) { if (!ShouldIgnoreHotkeys()) { @@ -765,7 +764,7 @@ public void OnHotkey() /// /// Checks if Flow Launcher should ignore any hotkeys /// - private bool ShouldIgnoreHotkeys() + public bool ShouldIgnoreHotkeys() { return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); } From 9a53015786139e5f26999eee111f7e371f497c51 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Tue, 19 Oct 2021 22:10:37 -0500 Subject: [PATCH 11/11] Refactor Code (Move all operation for mainviewmodel to ToggleFlowLauncher) --- Flow.Launcher/Helper/HotKeyMapper.cs | 7 ++- Flow.Launcher/SettingWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 70 +++++++----------------- 3 files changed, 28 insertions(+), 51 deletions(-) diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 1789b85483c..e10f4d86ba3 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -21,10 +21,15 @@ internal static void Initialize(MainViewModel mainVM) mainViewModel = mainVM; settings = mainViewModel._settings; - SetHotkey(settings.Hotkey, mainViewModel.OnHotkey); + SetHotkey(settings.Hotkey, OnToggleHotkey); LoadCustomPluginHotkey(); } + internal static void OnToggleHotkey(object sender, HotkeyEventArgs args) + { + mainViewModel.ToggleFlowLauncher(); + } + private static void SetHotkey(string hotkeyStr, EventHandler action) { var hotkey = new HotkeyModel(hotkeyStr); diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 26a0a840b9a..5e8e194d4da 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -127,7 +127,7 @@ void OnHotkeyChanged(object sender, EventArgs e) if (HotkeyControl.CurrentHotkeyAvailable) { - HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, mainViewModel.OnHotkey); + HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey); HotKeyMapper.RemoveHotkey(settings.Hotkey); settings.Hotkey = HotkeyControl.CurrentHotkey.ToString(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index f136ac27993..5e56f06cf7a 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -52,8 +52,6 @@ public class MainViewModel : BaseModel, ISavable private ChannelWriter _resultsUpdateChannelWriter; private Task _resultsViewUpdateTask; - - #endregion #region Constructor @@ -112,7 +110,9 @@ async Task updateAction() } Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends"); - }; + } + + ; void continueAction(Task t) { @@ -693,7 +693,7 @@ private void SetOpenResultModifiers() OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers; } - public void ToggleFlowLauncher() + public async void ToggleFlowLauncher() { if (MainWindowVisibility != Visibility.Visible) { @@ -701,25 +701,24 @@ public void ToggleFlowLauncher() } else { - if (_settings.LastQueryMode == LastQueryMode.Empty) + switch (_settings.LastQueryMode) { - Application.Current.MainWindow.Opacity = 0; // Trick for no delay - ClearQueryCommand.Execute(null); - Task.Run(() => - { - Thread.Sleep(100); - Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => - { - MainWindowVisibility = Visibility.Collapsed; - Application.Current.MainWindow.Opacity = 1; - })); - }); - } - else - { - - MainWindowVisibility = Visibility.Collapsed; + case LastQueryMode.Empty: + ChangeQueryText(string.Empty); + Application.Current.MainWindow.Opacity = 0; // Trick for no delay + await Task.Delay(100); + Application.Current.MainWindow.Opacity = 1; + break; + case LastQueryMode.Preserved: + LastQuerySelected = true; + break; + case LastQueryMode.Selected: + LastQuerySelected = false; + break; + default: + throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>"); } + MainWindowVisibility = Visibility.Collapsed; } } @@ -731,40 +730,13 @@ public void Hide() } } - #endregion - public void OnHotkey(object sender, HotkeyEventArgs e) - { - if (!ShouldIgnoreHotkeys()) - { - - if (_settings.LastQueryMode == LastQueryMode.Empty) - { - ChangeQueryText(string.Empty); - } - else if (_settings.LastQueryMode == LastQueryMode.Preserved) - { - LastQuerySelected = true; - } - else if (_settings.LastQueryMode == LastQueryMode.Selected) - { - LastQuerySelected = false; - } - else - { - throw new ArgumentException($"wrong LastQueryMode: <{_settings.LastQueryMode}>"); - } - - ToggleFlowLauncher(); - } - } - /// /// Checks if Flow Launcher should ignore any hotkeys /// - public bool ShouldIgnoreHotkeys() + public bool ShouldIgnoreHotkeys() { return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); }