Skip to content

Commit e3573f3

Browse files
committed
Improve code quality
1 parent 197e9c4 commit e3573f3

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Windows;
3-
using System.Windows.Forms;
3+
using System.Windows.Controls;
44
using System.Windows.Input;
55
using System.Windows.Interop;
66
using CommunityToolkit.Mvvm.DependencyInjection;
@@ -9,43 +9,53 @@
99
using Flow.Launcher.SettingPages.Views;
1010
using Flow.Launcher.ViewModel;
1111
using ModernWpf.Controls;
12-
using TextBox = System.Windows.Controls.TextBox;
12+
using Screen = System.Windows.Forms.Screen;
1313

1414
namespace Flow.Launcher;
1515

1616
public 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
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ public SettingWindowViewModel(Settings settings)
1212
_settings = settings;
1313
}
1414

15-
/// <summary>
16-
/// Save Flow settings. Plugins settings are not included.
17-
/// </summary>
18-
public void Save()
19-
{
20-
_settings.Save();
21-
}
22-
2315
public double SettingWindowWidth
2416
{
2517
get => _settings.SettingWindowWidth;

Flow.Launcher/WelcomeWindow.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
using System.Windows;
33
using System.Windows.Input;
44
using System.Windows.Controls;
5-
using Flow.Launcher.Resources.Pages;
6-
using ModernWpf.Media.Animation;
75
using CommunityToolkit.Mvvm.DependencyInjection;
8-
using Flow.Launcher.ViewModel;
96
using Flow.Launcher.Infrastructure.UserSettings;
7+
using Flow.Launcher.Resources.Pages;
8+
using Flow.Launcher.ViewModel;
9+
using ModernWpf.Media.Animation;
1010

1111
namespace Flow.Launcher
1212
{
1313
public partial class WelcomeWindow : Window
1414
{
15+
private readonly Settings _settings;
1516
private readonly WelcomeViewModel _viewModel;
1617

1718
private readonly NavigationTransitionInfo _forwardTransitionInfo = new SlideNavigationTransitionInfo()
@@ -25,6 +26,7 @@ public partial class WelcomeWindow : Window
2526

2627
public WelcomeWindow()
2728
{
29+
_settings = Ioc.Default.GetRequiredService<Settings>();
2830
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
2931
DataContext = _viewModel;
3032
InitializeComponent();
@@ -97,7 +99,7 @@ private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
9799
private void Window_Closed(object sender, EventArgs e)
98100
{
99101
// Save settings when window is closed
100-
Ioc.Default.GetRequiredService<Settings>().Save();
102+
_settings.Save();
101103
}
102104
}
103105
}

0 commit comments

Comments
 (0)