Skip to content

Commit 7d39c52

Browse files
committed
Code quality
1 parent 3f0c142 commit 7d39c52

File tree

2 files changed

+70
-83
lines changed

2 files changed

+70
-83
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,67 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
161161
{
162162
if (_viewModel.MainWindowVisibilityStatus)
163163
{
164+
// Set clock and search icon opacity
165+
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
166+
ClockPanel.Opacity = opacity;
167+
SearchIcon.Opacity = opacity;
168+
169+
// Set clock and search icon visibility
170+
ClockPanel.Visibility = string.IsNullOrEmpty(_viewModel.QueryText) ? Visibility.Visible : Visibility.Collapsed;
171+
if (_viewModel.PluginIconSource != null)
172+
{
173+
SearchIcon.Opacity = 0.0;
174+
}
175+
else
176+
{
177+
_viewModel.SearchIconVisibility = Visibility.Visible;
178+
}
179+
180+
// Play sound effect before activing the window
164181
if (_settings.UseSound)
165182
{
166183
SoundPlay();
167184
}
168185

186+
// Update position & Activate
169187
UpdatePosition();
170-
_viewModel.ResetPreview();
171188
Activate();
172-
QueryTextBox.Focus();
173-
_settings.ActivateTimes++;
189+
190+
// Reset preview
191+
_viewModel.ResetPreview();
192+
193+
// Select last query if need
174194
if (!_viewModel.LastQuerySelected)
175195
{
176196
QueryTextBox.SelectAll();
177197
_viewModel.LastQuerySelected = true;
178198
}
179199

200+
// Focus query box
201+
QueryTextBox.Focus();
202+
203+
// Play window animation
180204
if (_settings.UseAnimation)
205+
{
181206
WindowAnimation();
207+
}
208+
209+
_settings.ActivateTimes++;
210+
}
211+
else
212+
{
213+
// Set clock and search icon opacity
214+
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
215+
ClockPanel.Opacity = opacity;
216+
SearchIcon.Opacity = opacity;
217+
218+
// Set clock and search icon visibility
219+
ClockPanel.Visibility = Visibility.Hidden;
220+
_viewModel.SearchIconVisibility = Visibility.Hidden;
221+
222+
// Force UI update
223+
ClockPanel.UpdateLayout();
224+
SearchIcon.UpdateLayout();
182225
}
183226
});
184227
break;
@@ -191,7 +234,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
191234
Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length);
192235
_viewModel.QueryTextCursorMovedToEnd = false;
193236
}
194-
195237
break;
196238
case nameof(MainViewModel.GameModeStatus):
197239
_notifyIcon.Icon = _viewModel.GameModeStatus
@@ -280,8 +322,8 @@ private async void OnDeactivated(object sender, EventArgs e)
280322
_settings.WindowLeft = Left;
281323
_settings.WindowTop = Top;
282324

283-
ClockPanel.Opacity = 0;
284-
SearchIcon.Opacity = 0;
325+
ClockPanel.Opacity = 0.0;
326+
SearchIcon.Opacity = 0.0;
285327

286328
// This condition stops extra hide call when animator is on,
287329
// which causes the toggling to occasional hide instead of show.
@@ -291,7 +333,9 @@ private async void OnDeactivated(object sender, EventArgs e)
291333
// This also stops the mainwindow from flickering occasionally after Settings window is opened
292334
// and always after Settings window is closed.
293335
if (_settings.UseAnimation)
336+
{
294337
await Task.Delay(100);
338+
}
295339

296340
if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible)
297341
{
@@ -765,12 +809,6 @@ private void WindowAnimation()
765809
{
766810
_isArrowKeyPressed = true;
767811

768-
UpdatePosition();
769-
770-
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
771-
ClockPanel.Opacity = opacity;
772-
SearchIcon.Opacity = opacity;
773-
774812
var clocksb = new Storyboard();
775813
var iconsb = new Storyboard();
776814
var easing = new CircleEase { EasingMode = EasingMode.EaseInOut };

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Windows;
1111
using System.Windows.Input;
1212
using System.Windows.Media;
13-
using System.Windows.Threading;
1413
using CommunityToolkit.Mvvm.DependencyInjection;
1514
using CommunityToolkit.Mvvm.Input;
1615
using Flow.Launcher.Core.Plugin;
@@ -645,22 +644,22 @@ private async Task ChangeQueryTextAsync(string queryText, bool isReQuery = false
645644
return;
646645
}
647646

648-
BackToQueryResults();
647+
BackToQueryResults();
649648

650-
if (QueryText != queryText)
651-
{
652-
// re-query is done in QueryText's setter method
653-
QueryText = queryText;
654-
// set to false so the subsequent set true triggers
655-
// PropertyChanged and MoveQueryTextToEnd is called
656-
QueryTextCursorMovedToEnd = false;
657-
}
658-
else if (isReQuery)
659-
{
660-
await QueryAsync(isReQuery: true);
661-
}
649+
if (QueryText != queryText)
650+
{
651+
// re-query is done in QueryText's setter method
652+
QueryText = queryText;
653+
// set to false so the subsequent set true triggers
654+
// PropertyChanged and MoveQueryTextToEnd is called
655+
QueryTextCursorMovedToEnd = false;
656+
}
657+
else if (isReQuery)
658+
{
659+
await QueryAsync(isReQuery: true);
660+
}
662661

663-
QueryTextCursorMovedToEnd = true;
662+
QueryTextCursorMovedToEnd = true;
664663
}
665664

666665
public bool LastQuerySelected { get; set; }
@@ -1448,43 +1447,10 @@ public bool ShouldIgnoreHotkeys()
14481447

14491448
#pragma warning disable VSTHRD100 // Avoid async void methods
14501449

1451-
public async void Show()
1450+
public void Show()
14521451
{
1453-
await Application.Current.Dispatcher.InvokeAsync(() =>
1454-
{
1455-
if (Application.Current.MainWindow is MainWindow mainWindow)
1456-
{
1457-
// 📌 Remove DWM Cloak (Make the window visible normally)
1458-
Win32Helper.DWMSetCloakForWindow(mainWindow, false);
1459-
1460-
// Clock and SearchIcon hide when show situation
1461-
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
1462-
mainWindow.ClockPanel.Opacity = opacity;
1463-
mainWindow.SearchIcon.Opacity = opacity;
1464-
1465-
// QueryText sometimes is null when it is just initialized
1466-
if (QueryText != null && QueryText.Length != 0)
1467-
{
1468-
mainWindow.ClockPanel.Visibility = Visibility.Collapsed;
1469-
}
1470-
else
1471-
{
1472-
mainWindow.ClockPanel.Visibility = Visibility.Visible;
1473-
}
1474-
1475-
if (PluginIconSource != null)
1476-
{
1477-
mainWindow.SearchIcon.Opacity = 0;
1478-
}
1479-
else
1480-
{
1481-
SearchIconVisibility = Visibility.Visible;
1482-
}
1483-
1484-
// 📌 Restore UI elements
1485-
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
1486-
}
1487-
}, DispatcherPriority.Render);
1452+
// 📌 Remove DWM Cloak (Make the window visible normally)
1453+
Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, false);
14881454

14891455
// Update WPF properties
14901456
MainWindowVisibility = Visibility.Visible;
@@ -1500,6 +1466,9 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
15001466

15011467
public async void Hide()
15021468
{
1469+
// 📌 Apply DWM Cloak (Completely hide the window)
1470+
Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, true);
1471+
15031472
lastHistoryIndex = 1;
15041473

15051474
if (ExternalPreviewVisible)
@@ -1534,26 +1503,6 @@ public async void Hide()
15341503
break;
15351504
}
15361505

1537-
await Application.Current.Dispatcher.InvokeAsync(() =>
1538-
{
1539-
if (Application.Current.MainWindow is MainWindow mainWindow)
1540-
{
1541-
// 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
1542-
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
1543-
mainWindow.ClockPanel.Opacity = opacity;
1544-
mainWindow.SearchIcon.Opacity = opacity;
1545-
mainWindow.ClockPanel.Visibility = Visibility.Hidden;
1546-
SearchIconVisibility = Visibility.Hidden;
1547-
1548-
// Force UI update
1549-
mainWindow.ClockPanel.UpdateLayout();
1550-
mainWindow.SearchIcon.UpdateLayout();
1551-
1552-
// 📌 Apply DWM Cloak (Completely hide the window)
1553-
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
1554-
}
1555-
});
1556-
15571506
if (StartWithEnglishMode)
15581507
{
15591508
Win32Helper.RestorePreviousKeyboardLayout();

0 commit comments

Comments
 (0)