Change setting window position & window state faster & Do not save settings for faster exiting experience

This commit is contained in:
Jack251970 2025-04-25 09:04:14 +08:00
parent 856346aceb
commit defb2830d6
4 changed files with 31 additions and 18 deletions

View file

@ -31,6 +31,7 @@ namespace Flow.Launcher
#region Public Properties
public static IPublicAPI API { get; private set; }
public static bool Exiting => _mainWindow.CanClose;
#endregion
@ -39,7 +40,7 @@ namespace Flow.Launcher
private static readonly string ClassName = nameof(App);
private static bool _disposed;
private MainWindow _mainWindow;
private static MainWindow _mainWindow;
private readonly MainViewModel _mainVM;
private readonly Settings _settings;

View file

@ -16,6 +16,7 @@
Icon="Images\app.ico"
Left="{Binding SettingWindowLeft, Mode=TwoWay}"
Loaded="OnLoaded"
LocationChanged="Window_LocationChanged"
MouseDown="window_MouseDown"
ResizeMode="CanResize"
SnapsToDevicePixels="True"

View file

@ -52,9 +52,9 @@ public partial class SettingWindow
private void OnClosed(object sender, EventArgs e)
{
_settings.SettingWindowState = WindowState;
_settings.SettingWindowTop = Top;
_settings.SettingWindowLeft = Left;
// If app is exiting, settings save is not needed because main window closing event will handle this
if (App.Exiting) return;
// Save settings when window is closed
_settings.Save();
App.API.SavePluginSettings();
}
@ -66,15 +66,32 @@ public partial class SettingWindow
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
{
if (Keyboard.FocusedElement is not TextBox textBox)
{
return;
}
if (Keyboard.FocusedElement is not TextBox textBox) return;
var tRequest = new TraversalRequest(FocusNavigationDirection.Next);
textBox.MoveFocus(tRequest);
}
/* Custom TitleBar */
private void Window_StateChanged(object sender, EventArgs e)
{
RefreshMaximizeRestoreButton();
if (IsLoaded)
{
_settings.SettingWindowState = WindowState;
}
}
private void Window_LocationChanged(object sender, EventArgs e)
{
if (IsLoaded)
{
_settings.SettingWindowTop = Top;
_settings.SettingWindowLeft = Left;
}
}
#endregion
#region Window Custom TitleBar
private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
{
@ -109,11 +126,6 @@ public partial class SettingWindow
}
}
private void Window_StateChanged(object sender, EventArgs e)
{
RefreshMaximizeRestoreButton();
}
#endregion
#region Window Position

View file

@ -78,10 +78,7 @@ namespace Flow.Launcher
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
{
if (Keyboard.FocusedElement is not TextBox textBox)
{
return;
}
if (Keyboard.FocusedElement is not TextBox textBox) return;
var tRequest = new TraversalRequest(FocusNavigationDirection.Next);
textBox.MoveFocus(tRequest);
}
@ -98,6 +95,8 @@ namespace Flow.Launcher
private void Window_Closed(object sender, EventArgs e)
{
// If app is exiting, settings save is not needed because main window closing event will handle this
if (App.Exiting) return;
// Save settings when window is closed
_settings.Save();
}