mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Refactor Code (Move all operation for mainviewmodel to ToggleFlowLauncher)
This commit is contained in:
parent
364845a14c
commit
9a53015786
3 changed files with 28 additions and 51 deletions
|
|
@ -21,10 +21,15 @@ namespace Flow.Launcher.Helper
|
|||
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<HotkeyEventArgs> action)
|
||||
{
|
||||
var hotkey = new HotkeyModel(hotkeyStr);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ namespace Flow.Launcher
|
|||
if (HotkeyControl.CurrentHotkeyAvailable)
|
||||
{
|
||||
|
||||
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, mainViewModel.OnHotkey);
|
||||
HotKeyMapper.SetHotkey(HotkeyControl.CurrentHotkey, HotKeyMapper.OnToggleHotkey);
|
||||
HotKeyMapper.RemoveHotkey(settings.Hotkey);
|
||||
settings.Hotkey = HotkeyControl.CurrentHotkey.ToString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ namespace Flow.Launcher.ViewModel
|
|||
private ChannelWriter<ResultsForUpdate> _resultsUpdateChannelWriter;
|
||||
private Task _resultsViewUpdateTask;
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
|
@ -112,7 +110,9 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
|
||||
Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends");
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
void continueAction(Task t)
|
||||
{
|
||||
|
|
@ -693,7 +693,7 @@ namespace Flow.Launcher.ViewModel
|
|||
OpenResultCommandModifiers = _settings.OpenResultModifiers ?? DefaultOpenResultModifiers;
|
||||
}
|
||||
|
||||
public void ToggleFlowLauncher()
|
||||
public async void ToggleFlowLauncher()
|
||||
{
|
||||
if (MainWindowVisibility != Visibility.Visible)
|
||||
{
|
||||
|
|
@ -701,25 +701,24 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
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 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if Flow Launcher should ignore any hotkeys
|
||||
/// </summary>
|
||||
public bool ShouldIgnoreHotkeys()
|
||||
public bool ShouldIgnoreHotkeys()
|
||||
{
|
||||
return _settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue