This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
174 lines (140 loc) · 5.49 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
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
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Management.Automation;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using WMR_USB_Controller.YUART.Autostart;
using WMR_USB_Controller.YUART.Holographic.Sleep_Mode;
using WMR_USB_Controller.YUART.Holographic.VirtualScreens;
using WMR_USB_Controller.YUART.Tray_Icon;
using WMR_USB_Controller.YUART.USB;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
namespace WMR_USB_Controller
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private const string DisableWMRToggleText = "Disable WMR device";
private const string EnableWMRToggleText = "Enable WMR device";
private const double WindowToScreenSizeRatio = 4;
private readonly UsbDevicesManager _usbDevicesManager = new UsbDevicesManager();
private readonly PowerShell ps = PowerShell.Create();
private AutostartManager _autostartManager;
private TrayIconManager _trayIconManager;
private SleepModeManager _sleepModeManager;
private VirtualScreensManager _virtualScreensManager;
public MainWindow()
{
InitializeComponent();
SetProgramWindowSizeWithRatio();
SetupTrayIconManager();
SetupAutostartManager();
SetupSleepModeManager();
SetupVirtualScreensManager();
_usbDevicesManager.Initialize();
DisableWmrDeviceOnStartup();
}
private void SetProgramWindowSizeWithRatio()
{
var primaryScreenBounds = Screen.PrimaryScreen.Bounds;
var heightScreenSizeWithRatio = primaryScreenBounds.Height / WindowToScreenSizeRatio;
Width = heightScreenSizeWithRatio;
Height = heightScreenSizeWithRatio;
}
private void SetupTrayIconManager()
{
_trayIconManager = new TrayIconManager(this);
_trayIconManager.Initialize();
}
private void SetupAutostartManager()
{
_autostartManager = new AutostartManager(AutostartCheckbox);
_autostartManager.Initialize();
}
private void SetupSleepModeManager()
{
_sleepModeManager = new SleepModeManager(SleepDelayValue, ScreensaverModeStatus, ScreensaverModeStatusCheckbox);
_sleepModeManager.Initialize();
}
private void SetupVirtualScreensManager()
{
_virtualScreensManager = new VirtualScreensManager(VirtualScreensCheckbox);
_virtualScreensManager.Initialize();
}
private void DisableWmrDeviceOnStartup()
{
ChangeWmrDeviceState(false);
}
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Hide();
_trayIconManager.ShowIcon();
}
base.OnStateChanged(e);
}
private void DisableWmrDeviceAction(object sender, RoutedEventArgs e)
{
ChangeWmrDeviceState(false);
}
private void EnableWmrDeviceAction(object sender, RoutedEventArgs e)
{
ChangeWmrDeviceState(true);
}
/// <summary>
/// Switch WMR device status (active/disabled).
/// </summary>
/// <param name="newState">New active status of WMR device.</param>
public void ChangeWmrDeviceState(bool newState)
{
_usbDevicesManager.ActivateWmrDevice(newState);
WmrStatusToggle.Content = newState ? DisableWMRToggleText : EnableWMRToggleText;
WmrStatusToggle.IsChecked = !newState;
}
private void StartWMR(object sender, RoutedEventArgs e) {
ps.Commands.Clear();
EnableWmrDeviceAction(null, null);
ps.AddScript(File.ReadAllText(@"resolution_script.ps1")).Invoke();
}
private void SwitchAutostartStatus(object sender, RoutedEventArgs e)
{
_autostartManager.SetToAutostart();
}
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
private void TrySetNewSleepDelayValue(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter) return;
_sleepModeManager.SetNewSleepDelay(Int32.Parse(SleepDelayInputField.Text));
SleepDelayInputField.Text = String.Empty;
}
private void EnableScreensaverMode(object sender, RoutedEventArgs e)
{
_sleepModeManager.SetScreensaverModeStatus(true);
}
private void DisableScreensaverMode(object sender, RoutedEventArgs e)
{
_sleepModeManager.SetScreensaverModeStatus(false);
}
private void ResetSleepModeValues(object sender, RoutedEventArgs e)
{
_sleepModeManager.ResetSleepModeValues();
}
private void EnableVirtualScreens(object sender, RoutedEventArgs e)
{
_virtualScreensManager.SetVirtualScreensStatus(true);
}
private void DisableVirtualScreens(object sender, RoutedEventArgs e)
{
_virtualScreensManager.SetVirtualScreensStatus(false);
}
}
}