diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index b1ff136b3..1b57d5cbe 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -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; diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index ab27b235a..a75a51c8f 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -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" diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index cd3e5414f..79bd171ed 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -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 diff --git a/Flow.Launcher/WelcomeWindow.xaml.cs b/Flow.Launcher/WelcomeWindow.xaml.cs index d23bd4937..ef0706765 100644 --- a/Flow.Launcher/WelcomeWindow.xaml.cs +++ b/Flow.Launcher/WelcomeWindow.xaml.cs @@ -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(); }