Skip to content

Commit defb283

Browse files
committed
Change setting window position & window state faster & Do not save settings for faster exiting experience
1 parent 856346a commit defb283

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3131
#region Public Properties
3232

3333
public static IPublicAPI API { get; private set; }
34+
public static bool Exiting => _mainWindow.CanClose;
3435

3536
#endregion
3637

@@ -39,7 +40,7 @@ public partial class App : IDisposable, ISingleInstanceApp
3940
private static readonly string ClassName = nameof(App);
4041

4142
private static bool _disposed;
42-
private MainWindow _mainWindow;
43+
private static MainWindow _mainWindow;
4344
private readonly MainViewModel _mainVM;
4445
private readonly Settings _settings;
4546

Flow.Launcher/SettingWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Icon="Images\app.ico"
1717
Left="{Binding SettingWindowLeft, Mode=TwoWay}"
1818
Loaded="OnLoaded"
19+
LocationChanged="Window_LocationChanged"
1920
MouseDown="window_MouseDown"
2021
ResizeMode="CanResize"
2122
SnapsToDevicePixels="True"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ private void OnLoaded(object sender, RoutedEventArgs e)
5252

5353
private void OnClosed(object sender, EventArgs e)
5454
{
55-
_settings.SettingWindowState = WindowState;
56-
_settings.SettingWindowTop = Top;
57-
_settings.SettingWindowLeft = Left;
55+
// If app is exiting, settings save is not needed because main window closing event will handle this
56+
if (App.Exiting) return;
57+
// Save settings when window is closed
5858
_settings.Save();
5959
App.API.SavePluginSettings();
6060
}
@@ -66,15 +66,32 @@ private void OnCloseExecuted(object sender, ExecutedRoutedEventArgs e)
6666

6767
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
6868
{
69-
if (Keyboard.FocusedElement is not TextBox textBox)
70-
{
71-
return;
72-
}
69+
if (Keyboard.FocusedElement is not TextBox textBox) return;
7370
var tRequest = new TraversalRequest(FocusNavigationDirection.Next);
7471
textBox.MoveFocus(tRequest);
7572
}
7673

77-
/* Custom TitleBar */
74+
private void Window_StateChanged(object sender, EventArgs e)
75+
{
76+
RefreshMaximizeRestoreButton();
77+
if (IsLoaded)
78+
{
79+
_settings.SettingWindowState = WindowState;
80+
}
81+
}
82+
83+
private void Window_LocationChanged(object sender, EventArgs e)
84+
{
85+
if (IsLoaded)
86+
{
87+
_settings.SettingWindowTop = Top;
88+
_settings.SettingWindowLeft = Left;
89+
}
90+
}
91+
92+
#endregion
93+
94+
#region Window Custom TitleBar
7895

7996
private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
8097
{
@@ -109,11 +126,6 @@ private void RefreshMaximizeRestoreButton()
109126
}
110127
}
111128

112-
private void Window_StateChanged(object sender, EventArgs e)
113-
{
114-
RefreshMaximizeRestoreButton();
115-
}
116-
117129
#endregion
118130

119131
#region Window Position

Flow.Launcher/WelcomeWindow.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ private static Type PageTypeSelector(int pageNumber)
7878

7979
private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
8080
{
81-
if (Keyboard.FocusedElement is not TextBox textBox)
82-
{
83-
return;
84-
}
81+
if (Keyboard.FocusedElement is not TextBox textBox) return;
8582
var tRequest = new TraversalRequest(FocusNavigationDirection.Next);
8683
textBox.MoveFocus(tRequest);
8784
}
@@ -98,6 +95,8 @@ private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
9895

9996
private void Window_Closed(object sender, EventArgs e)
10097
{
98+
// If app is exiting, settings save is not needed because main window closing event will handle this
99+
if (App.Exiting) return;
101100
// Save settings when window is closed
102101
_settings.Save();
103102
}

0 commit comments

Comments
 (0)