-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
133 lines (118 loc) · 3.72 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using AsusFanControl.Infrastructure;
using AsusFanControl.Model;
using AsusFanControl.ViewModel;
using AsusFanControl.ViewModels;
using H.NotifyIcon;
using H.NotifyIcon.Core;
using H.NotifyIcon.EfficiencyMode;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace AsusFanControl
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private RelayCommand showHideCommand;
private GraphWindow? graphWindow;
public MainWindow()
{
InitializeComponent();
DataContext = new MainViewModel();
SystemTrayIcon.DoubleClickCommand = ShowHideCommand;
}
private void Slider_Complete(object sender, MouseButtonEventArgs e)
{
var slider = sender as Slider;
if (slider != null)
{
var viewModel = slider.DataContext as MainViewModel;
if (viewModel != null)
{
viewModel.SetFanPowerCommand.Execute(null);
}
}
}
private void Slider_PreviewKeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
private void Button_Click_Closed(object sender, RoutedEventArgs e)
{
Close();
}
private void Button_Click_Graph_Form(object sender, RoutedEventArgs e)
{
graphWindow = new GraphWindow();
graphWindow.Closed += GrahpViewWindowClosed;
graphWindow.Show();
}
private void GrahpViewWindowClosed(object? sender, EventArgs e)
{
if (DataContext is MainViewModel viewModel)
viewModel.RefreshGraphs();
graphWindow = null;
}
private void StatusModeListBox_Selected(object sender, RoutedEventArgs e)
{
if (DataContext is MainViewModel viewModel)
{
var listBox = sender as ListBox;
viewModel.ModeSelectedCommand.Execute(listBox.SelectedIndex);
}
}
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
if (StatusModeListBox.Visibility == Visibility.Collapsed)
{
StatusModeListBox.Visibility = Visibility.Visible;
}
else
{
StatusModeListBox.Visibility = Visibility.Collapsed;
}
}
protected override void OnClosed(EventArgs e)
{
var viewModel = DataContext as MainViewModel;
if (viewModel is not null)
viewModel.Dispose();
if (graphWindow != null)
graphWindow.Close();
base.OnClosed(e);
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
showHideCommand.Execute(null);
}
private RelayCommand ShowHideCommand
{
get
{
return showHideCommand ?? (showHideCommand = new RelayCommand(obj =>
{
if (Visibility == Visibility.Visible)
Hide();
else
{
WindowState = WindowState.Normal;
Topmost = true;
Show();
Topmost = false;
}
}));
}
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Hide();
}
}
}
}