diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index ebd3761ff..1789b8548 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -21,7 +21,7 @@ namespace Flow.Launcher.Helper mainViewModel = mainVM; settings = mainViewModel._settings; - SetHotkey(settings.Hotkey, OnHotkey); + SetHotkey(settings.Hotkey, mainViewModel.OnHotkey); LoadCustomPluginHotkey(); } @@ -55,46 +55,6 @@ namespace Flow.Launcher.Helper } } - 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 @@ namespace Flow.Launcher.Helper { 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 aa341f431..26a0a840b 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -23,6 +23,7 @@ namespace Flow.Launcher public readonly IPublicAPI API; private Settings settings; private SettingWindowViewModel viewModel; + private static MainViewModel mainViewModel; public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) { @@ -126,7 +127,7 @@ namespace Flow.Launcher 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 6134da644..f136ac279 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -21,6 +21,8 @@ using Microsoft.VisualStudio.Threading; using System.Threading.Channels; using ISavable = Flow.Launcher.Plugin.ISavable; using System.Windows.Threading; +using NHotkey; + namespace Flow.Launcher.ViewModel { @@ -225,7 +227,6 @@ namespace Flow.Launcher.ViewModel if (hideWindow) { - //MainWindowVisibility = Visibility.Collapsed; Hide(); } @@ -276,7 +277,6 @@ namespace Flow.Launcher.ViewModel Owner = Application.Current.MainWindow }; - //MainWindowVisibility = Visibility.Collapsed; Hide(); PluginManager @@ -368,7 +368,6 @@ namespace Flow.Launcher.ViewModel } public Visibility ProgressBarVisibility { get; set; } - public Visibility MainWindowVisibility { get; set; } public ICommand EscCommand { get; set; } @@ -735,7 +734,7 @@ namespace Flow.Launcher.ViewModel #endregion - public void OnHotkey() + public void OnHotkey(object sender, HotkeyEventArgs e) { if (!ShouldIgnoreHotkeys()) { @@ -765,7 +764,7 @@ namespace Flow.Launcher.ViewModel /// /// Checks if Flow Launcher should ignore any hotkeys /// - private bool ShouldIgnoreHotkeys() + public bool ShouldIgnoreHotkeys() { return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); }