forked from project-sbc/Power-Control-Panel-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickAccessMenu.xaml.cs
280 lines (222 loc) · 11 KB
/
QuickAccessMenu.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using MahApps.Metro.Controls;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Navigation;
using Power_Control_Panel.PowerControlPanel.Classes.Navigation;
using MenuItem = Power_Control_Panel.PowerControlPanel.Classes.VMQAM.MI;
using System.Windows.Threading;
using System.Threading;
using Power_Control_Panel.PowerControlPanel.Classes.TaskScheduler;
using Power_Control_Panel.PowerControlPanel.Classes.StartUp;
using Power_Control_Panel.PowerControlPanel.Classes;
using Power_Control_Panel.PowerControlPanel.Classes.RoutineUpdate;
using SharpDX.XInput;
using System.Net.NetworkInformation;
using System.Management;
using ControlzEx.Theming;
using System.Drawing;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace Power_Control_Panel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class QuickAccessMenu : MetroWindow
{
private NavigationServiceEx navigationServiceEx;
//WindowSinker sinker;
DispatcherTimer timer = new DispatcherTimer();
public QuickAccessMenu()
{
this.InitializeComponent();
initializeTimer();
//Run code to set up hamburger menu
initializeNavigationFrame();
initializeWindow();
updateValues();
ThemeManager.Current.ChangeTheme(this, Properties.Settings.Default.systemTheme);
}
void initializeTimer()
{
timer.Interval = new TimeSpan(0, 0, 3);
timer.Tick += updateValuesTick;
timer.Start();
}
void initializeWindow()
{
//sinker = new WindowSinker(this);
//sinker.Sink();
InitializeComponent();
this.ShowInTaskbar = false;
this.Topmost = true;
this.WindowStyle = WindowStyle.None;
this.AllowsTransparency = true;
}
#region hamburger navigation
//Navigation routines
void initializeNavigationFrame()
{
navigationServiceEx = new NavigationServiceEx();
navigationServiceEx.Navigated += this.NavigationServiceEx_OnNavigated;
HamburgerMenuControl.Content = this.navigationServiceEx.Frame;
this.Loaded += (sender, args) => this.navigationServiceEx.Navigate(new Uri("PowerControlPanel/Pages/QAMHomePage.xaml", UriKind.RelativeOrAbsolute));
// Navigate to the home page.
//if (Properties.Settings.Default.homePageTypeQAM == "Slider")
//{
//this.Loaded += (sender, args) => this.navigationServiceEx.Navigate(new Uri("PowerControlPanel/Pages/sliderHomePage.xaml", UriKind.RelativeOrAbsolute));
//}
//if (Properties.Settings.Default.homePageTypeQAM == "Grouped Slider")
//{
// this.Loaded += (sender, args) => this.navigationServiceEx.Navigate(new Uri("PowerControlPanel/Pages/HomePage.xaml", UriKind.RelativeOrAbsolute));
//}
//if (Properties.Settings.Default.homePageTypeQAM == "Tile")
//{
// this.Loaded += (sender, args) => this.navigationServiceEx.Navigate(new Uri("PowerControlPanel/Pages/TileHomePage.xaml", UriKind.RelativeOrAbsolute));
//}
}
private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItemInvokedEventArgs e)
{
if (e.InvokedItem is MenuItem menuItem)
{
if (menuItem.Label == "Hide" ^ menuItem.Label == "隐藏")
{
this.Close();
}
if (menuItem.IsNavigation)
{
this.navigationServiceEx.Navigate(menuItem.NavigationDestination);
}
}
}
private void NavigationServiceEx_OnNavigated(object sender, NavigationEventArgs e)
{
// select the menu item
this.HamburgerMenuControl.SetCurrentValue(HamburgerMenu.SelectedItemProperty,
this.HamburgerMenuControl.Items
.OfType<MenuItem>()
.FirstOrDefault(x => x.NavigationDestination == e.Uri));
this.HamburgerMenuControl.SetCurrentValue(HamburgerMenu.SelectedOptionsItemProperty,
this.HamburgerMenuControl
.OptionsItems
.OfType<MenuItem>()
.FirstOrDefault(x => x.NavigationDestination == e.Uri));
// or when using the NavigationType on menu item
// this.HamburgerMenuControl.SelectedItem = this.HamburgerMenuControl
// .Items
// .OfType<MenuItem>()
// .FirstOrDefault(x => x.NavigationType == e.Content?.GetType());
// this.HamburgerMenuControl.SelectedOptionsItem = this.HamburgerMenuControl
// .OptionsItems
// .OfType<MenuItem>()
// .FirstOrDefault(x => x.NavigationType == e.Content?.GetType());
// update back button
this.GoBackButton.SetCurrentValue(VisibilityProperty, this.navigationServiceEx.CanGoBack ? Visibility.Visible : Visibility.Collapsed);
}
private void GoBack_OnClick(object sender, RoutedEventArgs e)
{
this.navigationServiceEx.GoBack();
}
#endregion hamburger navigation
//End navigation routines
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
timer.Stop();
MainWindow.overlay = null;
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
//double width =(Convert.ToDouble(Properties.Settings.Default.sizeQAM) / 100);
//this.Width = width * System.Windows.SystemParameters.PrimaryScreenWidth;
this.Left = System.Windows.SystemParameters.PrimaryScreenWidth - this.Width;
this.Top = 0;
//make height total height - 10%
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight - ((System.Windows.SystemParameters.PrimaryScreenHeight) / 15);
}
public void checkNetworkInterface()
{
//Gets internet status to display on overlay
NetworkInterface[] networkCards = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
bool connectedDevice = false;
foreach (NetworkInterface networkCard in networkCards)
{
if (networkCard.OperationalStatus == OperationalStatus.Up)
{
if (networkCard.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { txtblkInternet.Text = "\uE839"; ; connectedDevice = true; }
if (networkCard.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) { txtblkInternet.Text = "\uE701"; ; connectedDevice = true; }
}
}
if (!connectedDevice) { txtblkInternet.Text = "\uF384"; }
}
void checkPowerStatus()
{
int batterylevel = -1;
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Battery");
string powerStatus = "AC";
foreach (ManagementObject mo in mos.Get())
{
powerStatus = mo["EstimatedChargeRemaining"].ToString();
}
if (powerStatus != "AC")
{
batterylevel = Int16.Parse(powerStatus);
PowerLineStatus Power = SystemParameters.PowerLineStatus;
powerStatus = Power.ToString();
}
else { powerStatus = "AC"; }
switch (powerStatus)
{
case "AC":
txtblkPower.Text = "";
break;
case "Online":
if (batterylevel < 10 && batterylevel >= 0) { txtblkPower.Text = "\uE85A"; }
if (batterylevel < 20 && batterylevel >= 10) { txtblkPower.Text = "\uE85B"; }
if (batterylevel < 30 && batterylevel >= 20) { txtblkPower.Text = "\uE85C"; }
if (batterylevel < 40 && batterylevel >= 30) { txtblkPower.Text = "\uE85D"; }
if (batterylevel < 50 && batterylevel >= 40) { txtblkPower.Text = "\uE85E"; }
if (batterylevel < 60 && batterylevel >= 50) { txtblkPower.Text = "\uE85F"; }
if (batterylevel < 70 && batterylevel >= 60) { txtblkPower.Text = "\uE860"; }
if (batterylevel < 80 && batterylevel >= 70) { txtblkPower.Text = "\uE861"; }
if (batterylevel < 90 && batterylevel >= 80) { txtblkPower.Text = "\uE862"; }
if (batterylevel <= 100 && batterylevel >= 90) { txtblkPower.Text = "\uE83E"; }
txtblkBatteryPercentage.Text = batterylevel.ToString() + "%";
break;
case "Offline":
if (batterylevel < 10 && batterylevel >= 0) { txtblkPower.Text = "\uE850"; }
if (batterylevel < 20 && batterylevel >= 10) { txtblkPower.Text = "\uE851"; }
if (batterylevel < 30 && batterylevel >= 20) { txtblkPower.Text = "\uE852"; }
if (batterylevel < 40 && batterylevel >= 30) { txtblkPower.Text = "\uE853"; }
if (batterylevel < 50 && batterylevel >= 40) { txtblkPower.Text = "\uE854"; }
if (batterylevel < 60 && batterylevel >= 50) { txtblkPower.Text = "\uE855"; }
if (batterylevel < 70 && batterylevel >= 60) { txtblkPower.Text = "\uE856"; }
if (batterylevel < 80 && batterylevel >= 70) { txtblkPower.Text = "\uE857"; }
if (batterylevel < 90 && batterylevel >= 80) { txtblkPower.Text = "\uE858"; }
if (batterylevel < 100 && batterylevel >= 90) { txtblkPower.Text = "\uE859"; }
txtblkBatteryPercentage.Text = batterylevel.ToString() + "%";
break;
default:
break;
}
}
void updateValuesTick(object sender, EventArgs e)
{
updateValues();
}
void updateValues()
{
checkNetworkInterface();
checkPowerStatus();
txtblkDateTime.Text = DateTime.Now.ToString("MM/dd/yyyy h:mm tt");
//game pad stuff here
//if (GlobalVariables.controller is null) { txtblkGamepad.Text = ""; } else { if (GlobalVariables.controller.IsConnected) { txtblkGamepad.Text = "\uE7FC"; } else { txtblkGamepad.Text = ""; } }
}
private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}