Code quality

This commit is contained in:
Jack251970 2025-03-28 12:00:23 +08:00
parent 3f0c142d3d
commit 7d39c52596
2 changed files with 70 additions and 83 deletions

View file

@ -161,24 +161,67 @@ namespace Flow.Launcher
{ {
if (_viewModel.MainWindowVisibilityStatus) if (_viewModel.MainWindowVisibilityStatus)
{ {
// Set clock and search icon opacity
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
ClockPanel.Opacity = opacity;
SearchIcon.Opacity = opacity;
// Set clock and search icon visibility
ClockPanel.Visibility = string.IsNullOrEmpty(_viewModel.QueryText) ? Visibility.Visible : Visibility.Collapsed;
if (_viewModel.PluginIconSource != null)
{
SearchIcon.Opacity = 0.0;
}
else
{
_viewModel.SearchIconVisibility = Visibility.Visible;
}
// Play sound effect before activing the window
if (_settings.UseSound) if (_settings.UseSound)
{ {
SoundPlay(); SoundPlay();
} }
// Update position & Activate
UpdatePosition(); UpdatePosition();
_viewModel.ResetPreview();
Activate(); Activate();
QueryTextBox.Focus();
_settings.ActivateTimes++; // Reset preview
_viewModel.ResetPreview();
// Select last query if need
if (!_viewModel.LastQuerySelected) if (!_viewModel.LastQuerySelected)
{ {
QueryTextBox.SelectAll(); QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true; _viewModel.LastQuerySelected = true;
} }
// Focus query box
QueryTextBox.Focus();
// Play window animation
if (_settings.UseAnimation) if (_settings.UseAnimation)
{
WindowAnimation(); WindowAnimation();
}
_settings.ActivateTimes++;
}
else
{
// Set clock and search icon opacity
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
ClockPanel.Opacity = opacity;
SearchIcon.Opacity = opacity;
// Set clock and search icon visibility
ClockPanel.Visibility = Visibility.Hidden;
_viewModel.SearchIconVisibility = Visibility.Hidden;
// Force UI update
ClockPanel.UpdateLayout();
SearchIcon.UpdateLayout();
} }
}); });
break; break;
@ -191,7 +234,6 @@ namespace Flow.Launcher
Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length); Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length);
_viewModel.QueryTextCursorMovedToEnd = false; _viewModel.QueryTextCursorMovedToEnd = false;
} }
break; break;
case nameof(MainViewModel.GameModeStatus): case nameof(MainViewModel.GameModeStatus):
_notifyIcon.Icon = _viewModel.GameModeStatus _notifyIcon.Icon = _viewModel.GameModeStatus
@ -280,8 +322,8 @@ namespace Flow.Launcher
_settings.WindowLeft = Left; _settings.WindowLeft = Left;
_settings.WindowTop = Top; _settings.WindowTop = Top;
ClockPanel.Opacity = 0; ClockPanel.Opacity = 0.0;
SearchIcon.Opacity = 0; SearchIcon.Opacity = 0.0;
// This condition stops extra hide call when animator is on, // This condition stops extra hide call when animator is on,
// which causes the toggling to occasional hide instead of show. // which causes the toggling to occasional hide instead of show.
@ -291,7 +333,9 @@ namespace Flow.Launcher
// This also stops the mainwindow from flickering occasionally after Settings window is opened // This also stops the mainwindow from flickering occasionally after Settings window is opened
// and always after Settings window is closed. // and always after Settings window is closed.
if (_settings.UseAnimation) if (_settings.UseAnimation)
{
await Task.Delay(100); await Task.Delay(100);
}
if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible) if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible)
{ {
@ -765,12 +809,6 @@ namespace Flow.Launcher
{ {
_isArrowKeyPressed = true; _isArrowKeyPressed = true;
UpdatePosition();
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
ClockPanel.Opacity = opacity;
SearchIcon.Opacity = opacity;
var clocksb = new Storyboard(); var clocksb = new Storyboard();
var iconsb = new Storyboard(); var iconsb = new Storyboard();
var easing = new CircleEase { EasingMode = EasingMode.EaseInOut }; var easing = new CircleEase { EasingMode = EasingMode.EaseInOut };

View file

@ -10,7 +10,6 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Plugin;
@ -645,22 +644,22 @@ namespace Flow.Launcher.ViewModel
return; return;
} }
BackToQueryResults(); BackToQueryResults();
if (QueryText != queryText) if (QueryText != queryText)
{ {
// re-query is done in QueryText's setter method // re-query is done in QueryText's setter method
QueryText = queryText; QueryText = queryText;
// set to false so the subsequent set true triggers // set to false so the subsequent set true triggers
// PropertyChanged and MoveQueryTextToEnd is called // PropertyChanged and MoveQueryTextToEnd is called
QueryTextCursorMovedToEnd = false; QueryTextCursorMovedToEnd = false;
} }
else if (isReQuery) else if (isReQuery)
{ {
await QueryAsync(isReQuery: true); await QueryAsync(isReQuery: true);
} }
QueryTextCursorMovedToEnd = true; QueryTextCursorMovedToEnd = true;
} }
public bool LastQuerySelected { get; set; } public bool LastQuerySelected { get; set; }
@ -1448,43 +1447,10 @@ namespace Flow.Launcher.ViewModel
#pragma warning disable VSTHRD100 // Avoid async void methods #pragma warning disable VSTHRD100 // Avoid async void methods
public async void Show() public void Show()
{ {
await Application.Current.Dispatcher.InvokeAsync(() => // 📌 Remove DWM Cloak (Make the window visible normally)
{ Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, false);
if (Application.Current.MainWindow is MainWindow mainWindow)
{
// 📌 Remove DWM Cloak (Make the window visible normally)
Win32Helper.DWMSetCloakForWindow(mainWindow, false);
// Clock and SearchIcon hide when show situation
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
mainWindow.ClockPanel.Opacity = opacity;
mainWindow.SearchIcon.Opacity = opacity;
// QueryText sometimes is null when it is just initialized
if (QueryText != null && QueryText.Length != 0)
{
mainWindow.ClockPanel.Visibility = Visibility.Collapsed;
}
else
{
mainWindow.ClockPanel.Visibility = Visibility.Visible;
}
if (PluginIconSource != null)
{
mainWindow.SearchIcon.Opacity = 0;
}
else
{
SearchIconVisibility = Visibility.Visible;
}
// 📌 Restore UI elements
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
}
}, DispatcherPriority.Render);
// Update WPF properties // Update WPF properties
MainWindowVisibility = Visibility.Visible; MainWindowVisibility = Visibility.Visible;
@ -1500,6 +1466,9 @@ namespace Flow.Launcher.ViewModel
public async void Hide() public async void Hide()
{ {
// 📌 Apply DWM Cloak (Completely hide the window)
Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, true);
lastHistoryIndex = 1; lastHistoryIndex = 1;
if (ExternalPreviewVisible) if (ExternalPreviewVisible)
@ -1534,26 +1503,6 @@ namespace Flow.Launcher.ViewModel
break; break;
} }
await Application.Current.Dispatcher.InvokeAsync(() =>
{
if (Application.Current.MainWindow is MainWindow mainWindow)
{
// 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
var opacity = Settings.UseAnimation ? 0.0 : 1.0;
mainWindow.ClockPanel.Opacity = opacity;
mainWindow.SearchIcon.Opacity = opacity;
mainWindow.ClockPanel.Visibility = Visibility.Hidden;
SearchIconVisibility = Visibility.Hidden;
// Force UI update
mainWindow.ClockPanel.UpdateLayout();
mainWindow.SearchIcon.UpdateLayout();
// 📌 Apply DWM Cloak (Completely hide the window)
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
}
});
if (StartWithEnglishMode) if (StartWithEnglishMode)
{ {
Win32Helper.RestorePreviousKeyboardLayout(); Win32Helper.RestorePreviousKeyboardLayout();