From 47d109cbe1bc1d5fdae4079b02c970e267553d77 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 23 Dec 2022 14:14:53 +0800
Subject: [PATCH] Refactor toggle game mode logic
---
Flow.Launcher/Helper/HotKeyMapper.cs | 6 ++---
Flow.Launcher/MainWindow.xaml | 4 ++++
Flow.Launcher/MainWindow.xaml.cs | 28 +++++-------------------
Flow.Launcher/ViewModel/MainViewModel.cs | 11 +++++++---
4 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs
index b9ac6afb3..27c044c66 100644
--- a/Flow.Launcher/Helper/HotKeyMapper.cs
+++ b/Flow.Launcher/Helper/HotKeyMapper.cs
@@ -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();
diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml
index 36a45da74..5ed9ba802 100644
--- a/Flow.Launcher/MainWindow.xaml
+++ b/Flow.Launcher/MainWindow.xaml
@@ -177,6 +177,10 @@
Command="{Binding OpenResultCommand}"
CommandParameter="9"
Modifiers="{Binding OpenResultCommandModifiers}" />
+
diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs
index 05e01a3f7..544958284 100644
--- a/Flow.Launcher/MainWindow.xaml.cs
+++ b/Flow.Launcher/MainWindow.xaml.cs
@@ -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)
{
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index 26ad89fff..c474e2a15 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -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
///
public bool ShouldIgnoreHotkeys()
{
- return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
+ return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen() || GameModeStatus;
}
#endregion