1
1
using System ;
2
2
using System . Windows ;
3
- using System . Windows . Forms ;
3
+ using System . Windows . Controls ;
4
4
using System . Windows . Input ;
5
5
using System . Windows . Interop ;
6
6
using CommunityToolkit . Mvvm . DependencyInjection ;
9
9
using Flow . Launcher . SettingPages . Views ;
10
10
using Flow . Launcher . ViewModel ;
11
11
using ModernWpf . Controls ;
12
- using TextBox = System . Windows . Controls . TextBox ;
12
+ using Screen = System . Windows . Forms . Screen ;
13
13
14
14
namespace Flow . Launcher ;
15
15
16
16
public partial class SettingWindow
17
17
{
18
+ #region Private Fields
19
+
18
20
private readonly Settings _settings ;
19
- private readonly SettingWindowViewModel _viewModel ;
21
+
22
+ #endregion
23
+
24
+ #region Constructor
20
25
21
26
public SettingWindow ( )
22
27
{
23
- var viewModel = Ioc . Default . GetRequiredService < SettingWindowViewModel > ( ) ;
24
28
_settings = Ioc . Default . GetRequiredService < Settings > ( ) ;
29
+ var viewModel = Ioc . Default . GetRequiredService < SettingWindowViewModel > ( ) ;
25
30
DataContext = viewModel ;
26
- _viewModel = viewModel ;
27
- InitializePosition ( ) ;
28
31
InitializeComponent ( ) ;
32
+
33
+ UpdatePositionAndState ( ) ;
29
34
}
30
35
36
+ #endregion
37
+
38
+ #region Window Events
39
+
31
40
private void OnLoaded ( object sender , RoutedEventArgs e )
32
41
{
33
42
RefreshMaximizeRestoreButton ( ) ;
43
+
34
44
// Fix (workaround) for the window freezes after lock screen (Win+L) or sleep
35
45
// https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
36
46
HwndSource hwndSource = PresentationSource . FromVisual ( this ) as HwndSource ;
37
47
HwndTarget hwndTarget = hwndSource . CompositionTarget ;
38
48
hwndTarget . RenderMode = RenderMode . SoftwareOnly ; // Must use software only render mode here
39
49
40
- InitializePosition ( ) ;
50
+ UpdatePositionAndState ( ) ;
41
51
}
42
52
43
53
private void OnClosed ( object sender , EventArgs e )
44
54
{
45
55
_settings . SettingWindowState = WindowState ;
46
56
_settings . SettingWindowTop = Top ;
47
57
_settings . SettingWindowLeft = Left ;
48
- _viewModel . Save ( ) ;
58
+ _settings . Save ( ) ;
49
59
App . API . SavePluginSettings ( ) ;
50
60
}
51
61
@@ -104,7 +114,11 @@ private void Window_StateChanged(object sender, EventArgs e)
104
114
RefreshMaximizeRestoreButton ( ) ;
105
115
}
106
116
107
- public void InitializePosition ( )
117
+ #endregion
118
+
119
+ #region Window Position
120
+
121
+ public void UpdatePositionAndState ( )
108
122
{
109
123
var previousTop = _settings . SettingWindowTop ;
110
124
var previousLeft = _settings . SettingWindowLeft ;
@@ -119,6 +133,7 @@ public void InitializePosition()
119
133
Top = previousTop . Value ;
120
134
Left = previousLeft . Value ;
121
135
}
136
+
122
137
WindowState = _settings . SettingWindowState ;
123
138
}
124
139
@@ -155,6 +170,10 @@ private double WindowTop()
155
170
return top ;
156
171
}
157
172
173
+ #endregion
174
+
175
+ #region Navigation View Events
176
+
158
177
private void NavigationView_SelectionChanged ( NavigationView sender , NavigationViewSelectionChangedEventArgs args )
159
178
{
160
179
if ( args . IsSettingsSelected )
@@ -201,4 +220,6 @@ private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
201
220
{
202
221
NavView . SelectedItem ??= NavView . MenuItems [ 0 ] ; /* Set First Page */
203
222
}
223
+
224
+ #endregion
204
225
}
0 commit comments