Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev-4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtYurchenko committed Dec 9, 2020
2 parents 0b40fc2 + bb8e55d commit 3c0d054
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 28 deletions.
8 changes: 6 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
<StackPanel Background="#FF5B5B5B">
<ToggleButton Name="WmrStatusToggle" Content="Disable WMR device" FontSize="24" Width="256" Height="124" Margin="50" Checked="DisableWmrDeviceAction"
Unchecked="EnableWmrDeviceAction" HorizontalAlignment="Center" />

<CheckBox Name="AutostartCheckbox" Click="SwitchAutostartStatus" Content="Add to autostart" FontSize="14" Margin="50" HorizontalAlignment="Center">
<CheckBox Name="VirtualScreensCheckbox" Content="Disable virtual screens" FontSize="14" Margin="10" HorizontalAlignment="Center" Checked="DisableVirtualScreens" Unchecked="EnableVirtualScreens">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
</CheckBox>
<CheckBox Name="AutostartCheckbox" Click="SwitchAutostartStatus" Content="Add to autostart" FontSize="14" Margin="10" HorizontalAlignment="Center">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
Expand Down
21 changes: 20 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System.Windows;
using System.Windows.Input;
using WMR_USB_Controller.YUART.Autostart;
using WMR_USB_Controller.YUART.Sleep_Mode;
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;

Expand All @@ -19,6 +20,7 @@ public partial class MainWindow
private AutostartManager _autostartManager;
private TrayIconManager _trayIconManager;
private SleepModeManager _sleepModeManager;
private VirtualScreensManager _virtualScreensManager;

public MainWindow()
{
Expand All @@ -27,6 +29,7 @@ public MainWindow()
SetupTrayIconManager();
SetupAutostartManager();
SetupSleepModeManager();
SetupVirtualScreensManager();

_usbDevicesManager.Initialize();

Expand All @@ -51,6 +54,12 @@ private void SetupSleepModeManager()
_sleepModeManager.Initialize();
}

private void SetupVirtualScreensManager()
{
_virtualScreensManager = new VirtualScreensManager(VirtualScreensCheckbox);
_virtualScreensManager.Initialize();
}

private void DisableWmrDeviceOnStartup()
{
ChangeWmrDeviceState(false);
Expand Down Expand Up @@ -122,5 +131,15 @@ 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);
}
}
}
16 changes: 15 additions & 1 deletion WMR USB Controller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand All @@ -61,7 +62,9 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="YUART\Autostart\AutostartManager.cs" />
<Compile Include="YUART\Sleep Mode\SleepModeManager.cs" />
<Compile Include="YUART\Holographic\HolographicManager.cs" />
<Compile Include="YUART\Holographic\Sleep Mode\SleepModeManager.cs" />
<Compile Include="YUART\Holographic\VirtualScreens\VirtualScreensManager.cs" />
<Compile Include="YUART\Tray Icon\TrayIconManager.cs" />
<Compile Include="YUART\USB\UsbDevicesManager.cs" />
<Compile Include="YUART\Utilities\IntBoolConverter.cs" />
Expand Down Expand Up @@ -110,5 +113,16 @@
<ItemGroup>
<Resource Include="WMR USB Controller Main Icon.ico" />
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
48 changes: 38 additions & 10 deletions YUART/Autostart/AutostartManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Windows.Controls;
using Microsoft.Win32;
using WMR_USB_Controller.YUART.Utilities;
using System;
using System.Windows.Controls;
using IWshRuntimeLibrary;
using Application = System.Windows.Application;
using File = System.IO.File;

namespace WMR_USB_Controller.YUART.Autostart
{
Expand All @@ -10,13 +11,16 @@ namespace WMR_USB_Controller.YUART.Autostart
/// </summary>
public sealed class AutostartManager
{
private const string PathToAutostartRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";

private readonly RegistryKey _autostartRegKey = Registry.CurrentUser.OpenSubKey(PathToAutostartRegKey, true);
private readonly string _appExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
private const string PathToTrayIcon = "WMR USB Controller Main Icon.ico";

private readonly WshShell _wshShell = new WshShell();
private readonly string _workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
private readonly CheckBox _autostartCheckbox;

private string _appName;
private string _autostartShortcutPath;
private string _iconLocation;

public AutostartManager(CheckBox autostartCheckbox)
{
Expand All @@ -30,6 +34,10 @@ public void Initialize()
{
SetApplicationName();

SetAutostartShortcutPath();

SetIconLocation();

SetAutostartCheckboxValue();
}

Expand All @@ -38,11 +46,21 @@ private void SetApplicationName()
_appName = Application.Current.MainWindow?.Title;
}

private void SetAutostartShortcutPath()
{
_autostartShortcutPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\{_appName}.lnk";
}

private void SetIconLocation()
{
_iconLocation = $"{_workingDirectory}{PathToTrayIcon}";
}

private void SetAutostartCheckboxValue()
{
if (_autostartCheckbox.IsChecked == null) return;

_autostartCheckbox.IsChecked = _autostartRegKey.IsExists(_appName);
_autostartCheckbox.IsChecked = File.Exists(_autostartShortcutPath);
}

/// <summary>
Expand All @@ -54,12 +72,22 @@ public void SetToAutostart()

if (_autostartCheckbox.IsChecked.Value)
{
_autostartRegKey.SetValue(_appName, _appExecutionPath);
CreateNewAutostartShortcut();
}
else
{
_autostartRegKey.DeleteValue(_appName, false);
File.Delete(_autostartShortcutPath);
}
}

private void CreateNewAutostartShortcut()
{
var shortcut = (IWshShortcut) _wshShell.CreateShortcut(_autostartShortcutPath);
shortcut.Description = _appName;
shortcut.WorkingDirectory = _workingDirectory;
shortcut.TargetPath = _assemblyLocation;
shortcut.IconLocation = _iconLocation;
shortcut.Save();
}
}
}
13 changes: 13 additions & 0 deletions YUART/Holographic/HolographicManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Win32;

namespace WMR_USB_Controller.YUART.Holographic
{
/// <summary>
/// Base class, that provides base data and behaviour for holographic managers.
/// </summary>
public class HolographicManager
{
private const string PathToHololensRegKeys = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Holographic";
protected readonly RegistryKey HololensRegKey = Registry.CurrentUser.OpenSubKey(PathToHololensRegKeys, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using System;
using System.Windows.Controls;
using Microsoft.Win32;
using System.Windows.Controls;
using WMR_USB_Controller.YUART.Utilities;

namespace WMR_USB_Controller.YUART.Sleep_Mode
namespace WMR_USB_Controller.YUART.Holographic.Sleep_Mode
{
/// <summary>
/// Class, that provide controls for sleep mode of WMR.
/// </summary>
public sealed class SleepModeManager
public sealed class SleepModeManager : HolographicManager
{
private const string PathToHololensRegKeys = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Holographic";
private const string SleepDelayRegkeyName = "IdleTimerDuration";
private const string ScreensaverModeRegkeyName = "ScreensaverModeEnabled";
private const int DefaultSleepDelay = 15;

private readonly RegistryKey _hololensRegKey = Registry.CurrentUser.OpenSubKey(PathToHololensRegKeys, true);

private readonly Label _sleepDelayValueLabel;
private readonly Label _screensaverModeStatusLabel;
private readonly CheckBox _screensaverModeCheckbox;
Expand Down Expand Up @@ -50,7 +46,7 @@ private void UpdateLabelsValues()

private void SetCurrentSleepDelayValue()
{
_sleepDelayValueLabel.Content = $"{(_hololensRegKey.IsExists(SleepDelayRegkeyName) ? TimeConverter.ConvertMillisecondsIntoMinutes((int) _hololensRegKey.GetValue(SleepDelayRegkeyName)) : DefaultSleepDelay).ToString()} minutes";
_sleepDelayValueLabel.Content = $"{(HololensRegKey.IsExists(SleepDelayRegkeyName) ? TimeConverter.ConvertMillisecondsIntoMinutes((int) HololensRegKey.GetValue(SleepDelayRegkeyName)) : DefaultSleepDelay).ToString()} minutes";
}

private void SetCurrentScreensaverModeStatus()
Expand All @@ -67,7 +63,7 @@ private void SetScreensaverModeCheckboxValue()

private bool GetCurrentScreensaverModeStatusFromRegistry()
{
return _hololensRegKey.IsExists(ScreensaverModeRegkeyName) && ((int) _hololensRegKey.GetValue(ScreensaverModeRegkeyName)).ConvertIntToBool();
return HololensRegKey.IsExists(ScreensaverModeRegkeyName) && ((int) HololensRegKey.GetValue(ScreensaverModeRegkeyName)).ConvertIntToBool();
}

/// <summary>
Expand All @@ -76,7 +72,7 @@ private bool GetCurrentScreensaverModeStatusFromRegistry()
/// <param name="newDelayInMinutes">New value of the sleep delay in minutes.</param>
public void SetNewSleepDelay(int newDelayInMinutes)
{
_hololensRegKey.SetValue(SleepDelayRegkeyName, TimeConverter.ConvertMinutesIntoMilliseconds(newDelayInMinutes));
HololensRegKey.SetValue(SleepDelayRegkeyName, TimeConverter.ConvertMinutesIntoMilliseconds(newDelayInMinutes));

SetCurrentSleepDelayValue();
}
Expand All @@ -87,7 +83,7 @@ public void SetNewSleepDelay(int newDelayInMinutes)
/// <param name="newStatus">New status (on/off)</param>
public void SetScreensaverModeStatus(bool newStatus)
{
_hololensRegKey.SetValue(ScreensaverModeRegkeyName, newStatus.ConvertBoolToInt());
HololensRegKey.SetValue(ScreensaverModeRegkeyName, newStatus.ConvertBoolToInt());

SetCurrentScreensaverModeStatus();
}
Expand All @@ -97,8 +93,8 @@ public void SetScreensaverModeStatus(bool newStatus)
/// </summary>
public void ResetSleepModeValues()
{
_hololensRegKey.DeleteValue(SleepDelayRegkeyName);
_hololensRegKey.DeleteValue(ScreensaverModeRegkeyName);
HololensRegKey.DeleteValue(SleepDelayRegkeyName);
HololensRegKey.DeleteValue(ScreensaverModeRegkeyName);

UpdateUiValues();
}
Expand Down
49 changes: 49 additions & 0 deletions YUART/Holographic/VirtualScreens/VirtualScreensManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Windows.Controls;
using WMR_USB_Controller.YUART.Utilities;

namespace WMR_USB_Controller.YUART.Holographic.VirtualScreens
{
/// <summary>
/// Class, that provide methods to manage Virtual Screens Allocation option.
/// </summary>
public sealed class VirtualScreensManager : HolographicManager
{
private const string VirtualScreensRegkey = "PreallocateVirtualMonitors";

private readonly CheckBox _virtualScreensCheckbox;

public VirtualScreensManager(CheckBox virtualScreensCheckbox)
{
_virtualScreensCheckbox = virtualScreensCheckbox;
}

/// <summary>
/// Initialize class and set startup UI values
/// </summary>
public void Initialize()
{
SetVirtualMonitorsCheckboxValue();
}

private void SetVirtualMonitorsCheckboxValue()
{
if (_virtualScreensCheckbox.IsChecked == null) return;

_virtualScreensCheckbox.IsChecked = !GetCurrentVirtualScreensStatusFromRegistry();
}

private bool GetCurrentVirtualScreensStatusFromRegistry()
{
return HololensRegKey.IsExists(VirtualScreensRegkey) && ((int) HololensRegKey.GetValue(VirtualScreensRegkey)).ConvertIntToBool();
}

/// <summary>
/// Set new status for Virtual Screens option.
/// </summary>
/// <param name="newStatus">Turn on/off virtual screens</param>
public void SetVirtualScreensStatus(bool newStatus)
{
HololensRegKey.SetValue(VirtualScreensRegkey, newStatus.ConvertBoolToInt());
}
}
}

0 comments on commit 3c0d054

Please sign in to comment.