Skip to content

Commit 47d109c

Browse files
Refactor toggle game mode logic
1 parent 33615d1 commit 47d109c

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Infrastructure.Hotkey;
1+
using Flow.Launcher.Infrastructure.Hotkey;
22
using Flow.Launcher.Infrastructure.UserSettings;
33
using System;
44
using NHotkey;
@@ -25,7 +25,7 @@ internal static void Initialize(MainViewModel mainVM)
2525

2626
internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
2727
{
28-
if (!mainViewModel.ShouldIgnoreHotkeys() && !mainViewModel.GameModeStatus)
28+
if (!mainViewModel.ShouldIgnoreHotkeys())
2929
mainViewModel.ToggleFlowLauncher();
3030
}
3131

@@ -74,7 +74,7 @@ internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey)
7474
{
7575
SetHotkey(hotkey.Hotkey, (s, e) =>
7676
{
77-
if (mainViewModel.ShouldIgnoreHotkeys() || mainViewModel.GameModeStatus)
77+
if (mainViewModel.ShouldIgnoreHotkeys())
7878
return;
7979

8080
mainViewModel.Show();

Flow.Launcher/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@
177177
Command="{Binding OpenResultCommand}"
178178
CommandParameter="9"
179179
Modifiers="{Binding OpenResultCommandModifiers}" />
180+
<KeyBinding
181+
Key="F12"
182+
Command="{Binding ToggleGameModeCommand}"
183+
Modifiers="Ctrl"/>
180184
</Window.InputBindings>
181185
<Grid>
182186
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
101101
// since the default main window visibility is visible
102102
// so we need set focus during startup
103103
QueryTextBox.Focus();
104+
104105
_viewModel.PropertyChanged += (o, e) =>
105106
{
106107
switch (e.PropertyName)
@@ -169,9 +170,12 @@ private void OnLoaded(object sender, RoutedEventArgs _)
169170
_viewModel.QueryTextCursorMovedToEnd = false;
170171
}
171172
break;
172-
173+
case nameof(MainViewModel.GameModeStatus):
174+
_notifyIcon.Icon = _viewModel.GameModeStatus ? Properties.Resources.gamemode : Properties.Resources.app;
175+
break;
173176
}
174177
};
178+
175179
_settings.PropertyChanged += (o, e) =>
176180
{
177181
switch (e.PropertyName)
@@ -286,7 +290,7 @@ private void InitializeNotifyIcon()
286290
};
287291

288292
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
289-
gamemode.Click += (o, e) => ToggleGameMode();
293+
gamemode.Click += (o, e) => _viewModel.ToggleGameMode();
290294
positionreset.Click += (o, e) => PositionReset();
291295
settings.Click += (o, e) => App.API.OpenSettingDialog();
292296
exit.Click += (o, e) => Close();
@@ -332,20 +336,6 @@ private void OpenWelcomeWindow()
332336
WelcomeWindow.Show();
333337
}
334338

335-
private void ToggleGameMode()
336-
{
337-
if (_viewModel.GameModeStatus)
338-
{
339-
_notifyIcon.Icon = Properties.Resources.app;
340-
_viewModel.GameModeStatus = false;
341-
}
342-
else
343-
{
344-
_notifyIcon.Icon = Properties.Resources.gamemode;
345-
_viewModel.GameModeStatus = true;
346-
}
347-
}
348-
349339
private async void PositionReset()
350340
{
351341
_viewModel.Show();
@@ -601,12 +591,6 @@ private void OnKeyDown(object sender, KeyEventArgs e)
601591
e.Handled = true;
602592
}
603593
break;
604-
case Key.F12:
605-
if (specialKeyState.CtrlPressed)
606-
{
607-
ToggleGameMode();
608-
}
609-
break;
610594
case Key.Back:
611595
if (specialKeyState.CtrlPressed)
612596
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ private void Esc()
337337
}
338338
}
339339

340+
[RelayCommand]
341+
public void ToggleGameMode()
342+
{
343+
GameModeStatus = !GameModeStatus;
344+
}
345+
340346
#endregion
341347

342348
#region ViewModel Properties
@@ -365,7 +371,7 @@ private async Task RegisterClockAndDateUpdateAsync()
365371

366372
public ResultsViewModel History { get; private set; }
367373

368-
public bool GameModeStatus { get; set; }
374+
public bool GameModeStatus { get; set; } = false;
369375

370376
private string _queryText;
371377
public string QueryText
@@ -379,7 +385,6 @@ public string QueryText
379385
}
380386
}
381387

382-
383388
[RelayCommand]
384389
private void IncreaseWidth()
385390
{
@@ -942,7 +947,7 @@ public async void Hide()
942947
/// </summary>
943948
public bool ShouldIgnoreHotkeys()
944949
{
945-
return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen();
950+
return Settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen() || GameModeStatus;
946951
}
947952

948953
#endregion

0 commit comments

Comments
 (0)