Merge pull request #3390 from Flow-Launcher/fix_hide_window_startup

Fix hide window startup
This commit is contained in:
Jack Ye 2025-03-28 15:03:58 +08:00 committed by GitHub
commit 0a497d832e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 90 additions and 91 deletions

View file

@ -101,11 +101,16 @@ namespace Flow.Launcher
// Check first launch
if (_settings.FirstLaunch)
{
// Set First Launch to false
_settings.FirstLaunch = false;
// Set Backdrop Type to Acrylic for Windows 11 when First Launch. Default is None
if (Win32Helper.IsBackdropSupported()) _settings.BackdropType = BackdropTypes.Acrylic;
// Save settings
App.API.SaveAppAllSettings();
/* Set Backdrop Type to Acrylic for Windows 11 when First Launch. Default is None. */
if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000))
_settings.BackdropType = BackdropTypes.Acrylic;
// Show Welcome Window
var WelcomeWindow = new WelcomeWindow();
WelcomeWindow.Show();
}
@ -161,24 +166,68 @@ namespace Flow.Launcher
{
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)
{
SoundPlay();
}
// Update position & Activate
UpdatePosition();
_viewModel.ResetPreview();
Activate();
QueryTextBox.Focus();
_settings.ActivateTimes++;
// Reset preview
_viewModel.ResetPreview();
// Select last query if need
if (!_viewModel.LastQuerySelected)
{
QueryTextBox.SelectAll();
_viewModel.LastQuerySelected = true;
}
// Focus query box
QueryTextBox.Focus();
// Play window animation
if (_settings.UseAnimation)
{
WindowAnimation();
}
// Update activate times
_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;
@ -191,7 +240,6 @@ namespace Flow.Launcher
Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length);
_viewModel.QueryTextCursorMovedToEnd = false;
}
break;
case nameof(MainViewModel.GameModeStatus):
_notifyIcon.Icon = _viewModel.GameModeStatus
@ -248,7 +296,8 @@ namespace Flow.Launcher
Notification.Uninstall();
// After plugins are all disposed, we can close the main window
_canClose = true;
Close();
// Use this instead of Close() to avoid InvalidOperationException when calling Close() in OnClosing event
Application.Current.Shutdown();
}
}
@ -280,8 +329,8 @@ namespace Flow.Launcher
_settings.WindowLeft = Left;
_settings.WindowTop = Top;
ClockPanel.Opacity = 0;
SearchIcon.Opacity = 0;
ClockPanel.Opacity = 0.0;
SearchIcon.Opacity = 0.0;
// This condition stops extra hide call when animator is on,
// which causes the toggling to occasional hide instead of show.
@ -291,7 +340,9 @@ namespace Flow.Launcher
// This also stops the mainwindow from flickering occasionally after Settings window is opened
// and always after Settings window is closed.
if (_settings.UseAnimation)
{
await Task.Delay(100);
}
if (_settings.HideWhenDeactivated && !_viewModel.ExternalPreviewVisible)
{
@ -765,12 +816,6 @@ namespace Flow.Launcher
{
_isArrowKeyPressed = true;
UpdatePosition();
var opacity = _settings.UseAnimation ? 0.0 : 1.0;
ClockPanel.Opacity = opacity;
SearchIcon.Opacity = opacity;
var clocksb = new Storyboard();
var iconsb = new Storyboard();
var easing = new CircleEase { EasingMode = EasingMode.EaseInOut };
@ -904,6 +949,7 @@ namespace Flow.Launcher
ClockPanel.BeginAnimation(OpacityProperty, fadeOut);
}
// ✅ 4. When showing ClockPanel (apply fade-in animation)
else if (shouldShowClock && ClockPanel.Visibility != Visibility.Visible && !_isClockPanelAnimating)
{
@ -927,7 +973,6 @@ namespace Flow.Launcher
}
}
private static double GetOpacityFromStyle(Style style, double defaultOpacity = 1.0)
{
if (style == null)

View file

@ -10,7 +10,6 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core.Plugin;
@ -213,7 +212,8 @@ namespace Flow.Launcher.ViewModel
queue.Clear();
}
Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends");
if (!_disposed)
Log.Error("MainViewModel", "Unexpected ResultViewUpdate ends");
}
void continueAction(Task t)
@ -638,25 +638,29 @@ namespace Flow.Launcher.ViewModel
/// </summary>
private async Task ChangeQueryTextAsync(string queryText, bool isReQuery = false)
{
await Application.Current.Dispatcher.InvokeAsync(async () =>
// Must check access so that we will not block the UI thread which cause window visibility issue
if (!Application.Current.Dispatcher.CheckAccess())
{
BackToQueryResults();
await Application.Current.Dispatcher.InvokeAsync(() => ChangeQueryText(queryText, isReQuery));
return;
}
if (QueryText != queryText)
{
// re-query is done in QueryText's setter method
QueryText = queryText;
// set to false so the subsequent set true triggers
// PropertyChanged and MoveQueryTextToEnd is called
QueryTextCursorMovedToEnd = false;
}
else if (isReQuery)
{
await QueryAsync(isReQuery: true);
}
BackToQueryResults();
QueryTextCursorMovedToEnd = true;
});
if (QueryText != queryText)
{
// re-query is done in QueryText's setter method
QueryText = queryText;
// set to false so the subsequent set true triggers
// PropertyChanged and MoveQueryTextToEnd is called
QueryTextCursorMovedToEnd = false;
}
else if (isReQuery)
{
await QueryAsync(isReQuery: true);
}
QueryTextCursorMovedToEnd = true;
}
public bool LastQuerySelected { get; set; }
@ -1444,43 +1448,10 @@ namespace Flow.Launcher.ViewModel
#pragma warning disable VSTHRD100 // Avoid async void methods
public async void Show()
public void Show()
{
await Application.Current.Dispatcher.InvokeAsync(() =>
{
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);
// 📌 Remove DWM Cloak (Make the window visible normally)
Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, false);
// Update WPF properties
MainWindowVisibility = Visibility.Visible;
@ -1496,6 +1467,9 @@ namespace Flow.Launcher.ViewModel
public async void Hide()
{
// 📌 Apply DWM Cloak (Completely hide the window)
Win32Helper.DWMSetCloakForWindow(Application.Current.MainWindow, true);
lastHistoryIndex = 1;
if (ExternalPreviewVisible)
@ -1530,26 +1504,6 @@ namespace Flow.Launcher.ViewModel
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)
{
Win32Helper.RestorePreviousKeyboardLayout();