Refactor toggle game mode logic

This commit is contained in:
Vic 2022-12-23 14:14:53 +08:00
parent 33615d1d46
commit 47d109cbe1
4 changed files with 21 additions and 28 deletions

View file

@ -1,4 +1,4 @@
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.UserSettings;
using System;
using NHotkey;
@ -25,7 +25,7 @@ namespace Flow.Launcher.Helper
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
{
if (!mainViewModel.ShouldIgnoreHotkeys() && !mainViewModel.GameModeStatus)
if (!mainViewModel.ShouldIgnoreHotkeys())
mainViewModel.ToggleFlowLauncher();
}
@ -74,7 +74,7 @@ namespace Flow.Launcher.Helper
{
SetHotkey(hotkey.Hotkey, (s, e) =>
{
if (mainViewModel.ShouldIgnoreHotkeys() || mainViewModel.GameModeStatus)
if (mainViewModel.ShouldIgnoreHotkeys())
return;
mainViewModel.Show();

View file

@ -177,6 +177,10 @@
Command="{Binding OpenResultCommand}"
CommandParameter="9"
Modifiers="{Binding OpenResultCommandModifiers}" />
<KeyBinding
Key="F12"
Command="{Binding ToggleGameModeCommand}"
Modifiers="Ctrl"/>
</Window.InputBindings>
<Grid>
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">

View file

@ -101,6 +101,7 @@ namespace Flow.Launcher
// since the default main window visibility is visible
// so we need set focus during startup
QueryTextBox.Focus();
_viewModel.PropertyChanged += (o, e) =>
{
switch (e.PropertyName)
@ -169,9 +170,12 @@ namespace Flow.Launcher
_viewModel.QueryTextCursorMovedToEnd = false;
}
break;
case nameof(MainViewModel.GameModeStatus):
_notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app;
break;
}
};
_settings.PropertyChanged += (o, e) =>
{
switch (e.PropertyName)
@ -286,7 +290,7 @@ namespace Flow.Launcher
};
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
gamemode.Click += (o, e) => ToggleGameMode();
gamemode.Click += (o, e) => _viewModel.ToggleGameMode();
positionreset.Click += (o, e) => PositionReset();
settings.Click += (o, e) => App.API.OpenSettingDialog();
exit.Click += (o, e) => Close();
@ -332,20 +336,6 @@ namespace Flow.Launcher
WelcomeWindow.Show();
}
private void ToggleGameMode()
{
if (_viewModel.GameModeStatus)
{
_notifyIcon.Icon = Properties.Resources.app;
_viewModel.GameModeStatus = false;
}
else
{
_notifyIcon.Icon = Properties.Resources.gamemode;
_viewModel.GameModeStatus = true;
}
}
private async void PositionReset()
{
_viewModel.Show();
@ -601,12 +591,6 @@ namespace Flow.Launcher
e.Handled = true;
}
break;
case Key.F12:
if (specialKeyState.CtrlPressed)
{
ToggleGameMode();
}
break;
case Key.Back:
if (specialKeyState.CtrlPressed)
{

View file

@ -337,6 +337,12 @@ namespace Flow.Launcher.ViewModel
}
}
[RelayCommand]
public void ToggleGameMode()
{
GameModeStatus = !GameModeStatus;
}
#endregion
#region ViewModel Properties
@ -365,7 +371,7 @@ namespace Flow.Launcher.ViewModel
public ResultsViewModel History { get; private set; }
public bool GameModeStatus { get; set; }
public bool GameModeStatus { get; set; } = false;
private string _queryText;
public string QueryText
@ -379,7 +385,6 @@ namespace Flow.Launcher.ViewModel
}
}
[RelayCommand]
private void IncreaseWidth()
{
@ -942,7 +947,7 @@ namespace Flow.Launcher.ViewModel
/// </summary>
public bool ShouldIgnoreHotkeys()
{
return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen() || GameModeStatus;
}
#endregion