11using System ;
22using System . Windows ;
3- using System . Windows . Forms ;
3+ using System . Windows . Controls ;
44using System . Windows . Input ;
55using System . Windows . Interop ;
66using CommunityToolkit . Mvvm . DependencyInjection ;
99using Flow . Launcher . SettingPages . Views ;
1010using Flow . Launcher . ViewModel ;
1111using ModernWpf . Controls ;
12- using TextBox = System . Windows . Controls . TextBox ;
12+ using Screen = System . Windows . Forms . Screen ;
1313
1414namespace Flow . Launcher ;
1515
1616public partial class SettingWindow
1717{
18+ #region Private Fields
19+
1820 private readonly Settings _settings ;
19- private readonly SettingWindowViewModel _viewModel ;
21+
22+ #endregion
23+
24+ #region Constructor
2025
2126 public SettingWindow ( )
2227 {
23- var viewModel = Ioc . Default . GetRequiredService < SettingWindowViewModel > ( ) ;
2428 _settings = Ioc . Default . GetRequiredService < Settings > ( ) ;
29+ var viewModel = Ioc . Default . GetRequiredService < SettingWindowViewModel > ( ) ;
2530 DataContext = viewModel ;
26- _viewModel = viewModel ;
27- InitializePosition ( ) ;
2831 InitializeComponent ( ) ;
32+
33+ UpdatePositionAndState ( ) ;
2934 }
3035
36+ #endregion
37+
38+ #region Window Events
39+
3140 private void OnLoaded ( object sender , RoutedEventArgs e )
3241 {
3342 RefreshMaximizeRestoreButton ( ) ;
43+
3444 // Fix (workaround) for the window freezes after lock screen (Win+L) or sleep
3545 // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
3646 HwndSource hwndSource = PresentationSource . FromVisual ( this ) as HwndSource ;
3747 HwndTarget hwndTarget = hwndSource . CompositionTarget ;
3848 hwndTarget . RenderMode = RenderMode . SoftwareOnly ; // Must use software only render mode here
3949
40- InitializePosition ( ) ;
50+ UpdatePositionAndState ( ) ;
4151 }
4252
4353 private void OnClosed ( object sender , EventArgs e )
4454 {
4555 _settings . SettingWindowState = WindowState ;
4656 _settings . SettingWindowTop = Top ;
4757 _settings . SettingWindowLeft = Left ;
48- _viewModel . Save ( ) ;
58+ _settings . Save ( ) ;
4959 App . API . SavePluginSettings ( ) ;
5060 }
5161
@@ -104,7 +114,11 @@ private void Window_StateChanged(object sender, EventArgs e)
104114 RefreshMaximizeRestoreButton ( ) ;
105115 }
106116
107- public void InitializePosition ( )
117+ #endregion
118+
119+ #region Window Position
120+
121+ public void UpdatePositionAndState ( )
108122 {
109123 var previousTop = _settings . SettingWindowTop ;
110124 var previousLeft = _settings . SettingWindowLeft ;
@@ -119,6 +133,7 @@ public void InitializePosition()
119133 Top = previousTop . Value ;
120134 Left = previousLeft . Value ;
121135 }
136+
122137 WindowState = _settings . SettingWindowState ;
123138 }
124139
@@ -155,6 +170,10 @@ private double WindowTop()
155170 return top ;
156171 }
157172
173+ #endregion
174+
175+ #region Navigation View Events
176+
158177 private void NavigationView_SelectionChanged ( NavigationView sender , NavigationViewSelectionChangedEventArgs args )
159178 {
160179 if ( args . IsSettingsSelected )
@@ -201,4 +220,6 @@ private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
201220 {
202221 NavView . SelectedItem ??= NavView . MenuItems [ 0 ] ; /* Set First Page */
203222 }
223+
224+ #endregion
204225}
0 commit comments