Awake vNext - NOBLE_SIX_02162023 (#24183)

* Initial scaffolding for expiration configuration

* Simplifying the code and adding support for expiration events

* Bit more cleanup

* Initial support for expirable keep-awake

* Update some of the threading logic

* Logging and timing consistency

* Initial UI scaffolding

* Fix pathing issue for the icon when using config file

* Add missing definitions

* Update with basic interface

* Cleanup redundant calls

* Update name per convention

* Simplify declaration

* Proper binding to secondary Time property

* Cleanup the terminology use

* Standardize naming conventions.

* More Awake cleanup

* Ability to update the UI when the tray icon updates

* Small tweaks before ViewModel refactor

* Refactor the view model logic

* Some consistency fixes

* Remove the build props change

* Add settings scaffolding when a file does not exist

* Update expect.txt

* Fix typos

* Update build in logs

* Updating based on discussion in #24183.
This specifically addresses the fact that the `ExpirationDateTime` property was incorrectly auto-initialized to `DateTime.MinValue` when it should've been set to `DateTimeOffset.MinValue` to be consistent with the underlying type and assumptions around date/time.

---------

Co-authored-by: Clint Rutkas <clint@rutkas.com>
This commit is contained in:
Den
2023-03-15 01:42:47 -07:00
committed by GitHub
parent 13cb52763d
commit 466252745d
20 changed files with 664 additions and 323 deletions

View File

@@ -1812,35 +1812,41 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="Awake.ModuleDescription" xml:space="preserve">
<value>A convenient way to keep your PC awake on-demand.</value>
</data>
<data name="Awake_EnableAwake.Header" xml:space="preserve">
<data name="Awake_EnableSettingsCard.Header" xml:space="preserve">
<value>Enable Awake</value>
<comment>Awake is a product name, do not loc</comment>
</data>
<data name="Awake_NoKeepAwake.Content" xml:space="preserve">
<data name="Awake_NoKeepAwakeSelector.Content" xml:space="preserve">
<value>Keep using the selected power plan</value>
</data>
<data name="Awake_IndefiniteKeepAwake.Content" xml:space="preserve">
<data name="Awake_IndefiniteKeepAwakeSelector.Content" xml:space="preserve">
<value>Keep awake indefinitely</value>
</data>
<data name="Awake_TemporaryKeepAwake.Content" xml:space="preserve">
<value>Keep awake temporarily</value>
<data name="Awake_TemporaryKeepAwakeSelector.Content" xml:space="preserve">
<value>Keep awake for a time interval</value>
</data>
<data name="Awake_EnableDisplayKeepAwake.Header" xml:space="preserve">
<data name="Awake_ExpirableKeepAwakeSelector.Content" xml:space="preserve">
<value>Keep awake until expiration</value>
</data>
<data name="Awake_DisplaySettingsCard.Header" xml:space="preserve">
<value>Keep screen on</value>
</data>
<data name="Awake_EnableDisplayKeepAwake.Description" xml:space="preserve">
<data name="Awake_DisplaySettingsCard.Description" xml:space="preserve">
<value>This setting is only available when keeping the PC awake</value>
</data>
<data name="Awake_Mode.Header" xml:space="preserve">
<data name="Awake_ExpirationSettingsCard.Description" xml:space="preserve">
<value>Keep custom awakeness state until a specific date and time</value>
</data>
<data name="Awake_ModeSettingsCard.Header" xml:space="preserve">
<value>Mode</value>
</data>
<data name="Awake_Behavior_GroupSettings.Header" xml:space="preserve">
<data name="Awake_BehaviorSettingsGroup.Header" xml:space="preserve">
<value>Behavior</value>
</data>
<data name="Awake_TemporaryKeepAwake_Hours.Header" xml:space="preserve">
<data name="Awake_IntervalHoursInput.Header" xml:space="preserve">
<value>Hours</value>
</data>
<data name="Awake_TemporaryKeepAwake_Minutes.Header" xml:space="preserve">
<data name="Awake_IntervalMinutesInput.Header" xml:space="preserve">
<value>Minutes</value>
</data>
<data name="Oobe_Awake.Title" xml:space="preserve">
@@ -1930,7 +1936,7 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="SeeWhatsNew.Content" xml:space="preserve">
<value>See what's new</value>
</data>
<data name="Awake_Mode.Description" xml:space="preserve">
<data name="Awake_ModeSettingsCard.Description" xml:space="preserve">
<value>Manage the state of your device when Awake is active</value>
</data>
<data name="ExcludedApps.Header" xml:space="preserve">
@@ -2120,8 +2126,11 @@ From there, simply click on one of the supported files in the File Explorer and
<value>New size</value>
<comment>First part of the default name of new sizes that can be added in PT's settings ui.</comment>
</data>
<data name="Awake_TimeBeforeAwake.Header" xml:space="preserve">
<value>Time before returning to the previous awakeness state</value>
<data name="Awake_IntervalSettingsCard.Header" xml:space="preserve">
<value>Interval before returning to the previous awakeness state</value>
</data>
<data name="Awake_ExpirationSettingsCard.Header" xml:space="preserve">
<value>End date and time</value>
</data>
<data name="MouseUtils.ModuleTitle" xml:space="preserve">
<value>Mouse utilities</value>
@@ -3056,4 +3065,4 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="Hosts_Toggle_LoopbackDuplicates.Header" xml:space="preserve">
<value>Consider loopback addresses as duplicates</value>
</data>
</root>
</root>

View File

@@ -4,62 +4,29 @@
using System;
using System.Runtime.CompilerServices;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class AwakeViewModel : Observable
{
private GeneralSettings GeneralSettingsConfig { get; set; }
private AwakeSettings Settings { get; set; }
private Func<string, int> SendConfigMSG { get; }
public AwakeViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<AwakeSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
public AwakeViewModel()
{
// To obtain the general settings configurations of PowerToys Settings.
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
// To obtain the settings configurations of Fancy zones.
if (moduleSettingsRepository == null)
{
throw new ArgumentNullException(nameof(moduleSettingsRepository));
}
Settings = moduleSettingsRepository.SettingsConfig;
InitializeEnabledValue();
_keepDisplayOn = Settings.Properties.KeepDisplayOn;
_mode = Settings.Properties.Mode;
_hours = Settings.Properties.Hours;
_minutes = Settings.Properties.Minutes;
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
}
private void InitializeEnabledValue()
public AwakeSettings ModuleSettings
{
_enabledGpoRuleConfiguration = GPOWrapper.GetConfiguredAwakeEnabledValue();
if (_enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
get => _moduleSettings;
set
{
// Get the enabled state from GPO.
_enabledStateIsGPOConfigured = true;
_isEnabled = _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
else
{
_isEnabled = GeneralSettingsConfig.Enabled.Awake;
if (_moduleSettings != value)
{
_moduleSettings = value;
RefreshModuleSettings();
RefreshEnabledState();
}
}
}
@@ -78,13 +45,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_isEnabled = value;
GeneralSettingsConfig.Enabled.Awake = value;
OnPropertyChanged(nameof(IsEnabled));
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
OnPropertyChanged(nameof(IsScreenConfigurationPossibleEnabled));
RefreshEnabledState();
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
NotifyPropertyChanged();
}
}
@@ -93,31 +55,44 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public bool IsEnabledGpoConfigured
{
get => _enabledStateIsGPOConfigured;
set
{
if (_enabledStateIsGPOConfigured != value)
{
_enabledStateIsGPOConfigured = value;
NotifyPropertyChanged();
}
}
}
public bool IsExpirationConfigurationEnabled
{
get => ModuleSettings.Properties.Mode == AwakeMode.EXPIRABLE && IsEnabled;
}
public bool IsTimeConfigurationEnabled
{
get => _mode == AwakeMode.TIMED && _isEnabled;
get => ModuleSettings.Properties.Mode == AwakeMode.TIMED && IsEnabled;
}
public bool IsScreenConfigurationPossibleEnabled
{
get => _mode != AwakeMode.PASSIVE && _isEnabled;
get => ModuleSettings.Properties.Mode != AwakeMode.PASSIVE && IsEnabled;
}
public AwakeMode Mode
{
get => _mode;
get => ModuleSettings.Properties.Mode;
set
{
if (_mode != value)
if (ModuleSettings.Properties.Mode != value)
{
_mode = value;
OnPropertyChanged(nameof(Mode));
ModuleSettings.Properties.Mode = value;
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
OnPropertyChanged(nameof(IsScreenConfigurationPossibleEnabled));
OnPropertyChanged(nameof(IsExpirationConfigurationEnabled));
Settings.Properties.Mode = value;
NotifyPropertyChanged();
}
}
@@ -125,79 +100,93 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public bool KeepDisplayOn
{
get => _keepDisplayOn;
get => ModuleSettings.Properties.KeepDisplayOn;
set
{
if (_keepDisplayOn != value)
if (ModuleSettings.Properties.KeepDisplayOn != value)
{
_keepDisplayOn = value;
OnPropertyChanged(nameof(KeepDisplayOn));
Settings.Properties.KeepDisplayOn = value;
ModuleSettings.Properties.KeepDisplayOn = value;
NotifyPropertyChanged();
}
}
}
public uint Hours
public uint IntervalHours
{
get => _hours;
get => ModuleSettings.Properties.IntervalHours;
set
{
if (_hours != value)
if (ModuleSettings.Properties.IntervalHours != value)
{
_hours = value;
OnPropertyChanged(nameof(Hours));
Settings.Properties.Hours = value;
ModuleSettings.Properties.IntervalHours = value;
NotifyPropertyChanged();
}
}
}
public uint Minutes
public uint IntervalMinutes
{
get => _minutes;
get => ModuleSettings.Properties.IntervalMinutes;
set
{
if (_minutes != value)
if (ModuleSettings.Properties.IntervalMinutes != value)
{
_minutes = value;
OnPropertyChanged(nameof(Minutes));
Settings.Properties.Minutes = value;
ModuleSettings.Properties.IntervalMinutes = value;
NotifyPropertyChanged();
}
}
}
public DateTimeOffset ExpirationDateTime
{
get => ModuleSettings.Properties.ExpirationDateTime;
set
{
if (ModuleSettings.Properties.ExpirationDateTime != value)
{
ModuleSettings.Properties.ExpirationDateTime = value;
NotifyPropertyChanged();
}
}
}
public TimeSpan ExpirationTime
{
get => ExpirationDateTime.TimeOfDay;
set
{
if (ExpirationDateTime.TimeOfDay != value)
{
ExpirationDateTime = new DateTime(ExpirationDateTime.Year, ExpirationDateTime.Month, ExpirationDateTime.Day, value.Hours, value.Minutes, value.Seconds);
}
}
}
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
Logger.LogInfo($"Changed the property {propertyName}");
OnPropertyChanged(propertyName);
if (SendConfigMSG != null)
{
SndAwakeSettings outsettings = new SndAwakeSettings(Settings);
SndModuleSettings<SndAwakeSettings> ipcMessage = new SndModuleSettings<SndAwakeSettings>(outsettings);
string targetMessage = ipcMessage.ToJsonString();
SendConfigMSG(targetMessage);
}
}
public void RefreshEnabledState()
{
InitializeEnabledValue();
OnPropertyChanged(nameof(IsEnabled));
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
OnPropertyChanged(nameof(IsScreenConfigurationPossibleEnabled));
OnPropertyChanged(nameof(IsExpirationConfigurationEnabled));
}
public void RefreshModuleSettings()
{
OnPropertyChanged(nameof(Mode));
OnPropertyChanged(nameof(KeepDisplayOn));
OnPropertyChanged(nameof(IntervalHours));
OnPropertyChanged(nameof(IntervalMinutes));
OnPropertyChanged(nameof(ExpirationDateTime));
}
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private AwakeSettings _moduleSettings;
private bool _isEnabled;
private uint _hours;
private uint _minutes;
private bool _keepDisplayOn;
private AwakeMode _mode;
}
}

View File

@@ -8,6 +8,8 @@
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
xmlns:viewmodels="using:Microsoft.PowerToys.Settings.UI.ViewModels"
d:DataContext="{d:DesignInstance Type=viewmodels:AwakeViewModel}"
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">
@@ -22,7 +24,7 @@
<controls:SettingsPageControl.ModuleContent>
<StackPanel Orientation="Vertical" ChildrenTransitions="{StaticResource SettingsCardsAnimations}">
<labs:SettingsCard
x:Uid="Awake_EnableAwake"
x:Uid="Awake_EnableSettingsCard"
HeaderIcon="{ui:BitmapIcon Source=/Assets/FluentIcons/FluentIconsAwake.png}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabledGpoConfigured, Converter={StaticResource BoolNegationConverter}}">
<ToggleSwitch
@@ -37,37 +39,48 @@
Severity="Informational" />
<controls:SettingsGroup
x:Uid="Awake_Behavior_GroupSettings"
x:Uid="Awake_BehaviorSettingsGroup"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
<labs:SettingsCard
x:Uid="Awake_Mode"
x:Uid="Awake_ModeSettingsCard"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE945;}">
<ComboBox
MinWidth="{StaticResource SettingActionControlMinWidth}"
SelectedIndex="{x:Bind Path=ViewModel.Mode, Mode=TwoWay, Converter={StaticResource AwakeModeToIntConverter}}">
<ComboBoxItem x:Uid="Awake_NoKeepAwake" />
<ComboBoxItem x:Uid="Awake_IndefiniteKeepAwake" />
<ComboBoxItem x:Uid="Awake_TemporaryKeepAwake" />
<ComboBoxItem x:Uid="Awake_NoKeepAwakeSelector" />
<ComboBoxItem x:Uid="Awake_IndefiniteKeepAwakeSelector" />
<ComboBoxItem x:Uid="Awake_TemporaryKeepAwakeSelector" />
<ComboBoxItem x:Uid="Awake_ExpirableKeepAwakeSelector" />
</ComboBox>
</labs:SettingsCard>
<labs:SettingsCard
x:Uid="Awake_TimeBeforeAwake"
x:Uid="Awake_ExpirationSettingsCard"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xEC92;}"
Visibility="{x:Bind ViewModel.IsExpirationConfigurationEnabled, Mode=OneWay}">
<StackPanel Orientation="Horizontal">
<DatePicker Date="{x:Bind ViewModel.ExpirationDateTime, Mode=TwoWay}"></DatePicker>
<TimePicker Margin="8,0,0,0" Time="{x:Bind ViewModel.ExpirationTime, Mode=TwoWay}" ClockIdentifier="24HourClock"></TimePicker>
</StackPanel>
</labs:SettingsCard>
<labs:SettingsCard
x:Uid="Awake_IntervalSettingsCard"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE916;}"
Visibility="{x:Bind ViewModel.IsTimeConfigurationEnabled, Mode=OneWay}">
<StackPanel Orientation="Horizontal">
<NumberBox
x:Uid="Awake_TemporaryKeepAwake_Hours"
x:Uid="Awake_IntervalHoursInput"
Width="96"
HorizontalAlignment="Left"
LargeChange="5"
Minimum="0"
SmallChange="1"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.Hours, Mode=TwoWay}" />
Value="{x:Bind ViewModel.IntervalHours, Mode=TwoWay}" />
<NumberBox
x:Uid="Awake_TemporaryKeepAwake_Minutes"
x:Uid="Awake_IntervalMinutesInput"
Width="96"
Margin="8,0,0,0"
HorizontalAlignment="Left"
@@ -76,16 +89,15 @@
Minimum="0"
SmallChange="1"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.Minutes, Mode=TwoWay}" />
Value="{x:Bind ViewModel.IntervalMinutes, Mode=TwoWay}" />
</StackPanel>
</labs:SettingsCard>
<labs:SettingsCard
x:Uid="Awake_EnableDisplayKeepAwake"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE7FB;}"
x:Uid="Awake_DisplaySettingsCard"
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xE7F4;}"
IsEnabled="{x:Bind ViewModel.IsScreenConfigurationPossibleEnabled, Mode=OneWay}">
<ToggleSwitch
x:Uid="ToggleSwitch"
IsOn="{x:Bind ViewModel.KeepDisplayOn, Mode=TwoWay}" />
</labs:SettingsCard>
</controls:SettingsGroup>
@@ -99,7 +111,7 @@
</controls:SettingsPageControl.PrimaryLinks>
<controls:SettingsPageControl.SecondaryLinks>
<controls:PageLink
Link="https://Awake.den.dev"
Link="https://awake.den.dev"
Text="Den Delimarsky's work on creating Awake" />
</controls:SettingsPageControl.SecondaryLinks>
</controls:SettingsPageControl>

View File

@@ -2,25 +2,184 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.IO.Abstractions;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
using PowerToys.GPOWrapper;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class AwakePage : Page, IRefreshablePage
{
private readonly string _appName = "Awake";
private readonly SettingsUtils _settingsUtils;
private readonly SettingsRepository<GeneralSettings> _generalSettingsRepository;
private readonly SettingsRepository<AwakeSettings> _moduleSettingsRepository;
private readonly IFileSystem _fileSystem;
private readonly IFileSystemWatcher _fileSystemWatcher;
private readonly DispatcherQueue _dispatcherQueue;
private readonly Func<string, int> _sendConfigMsg;
private AwakeViewModel ViewModel { get; set; }
public AwakePage()
{
var settingsUtils = new SettingsUtils();
ViewModel = new AwakeViewModel(SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), SettingsRepository<AwakeSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
_fileSystem = new FileSystem();
_settingsUtils = new SettingsUtils();
_sendConfigMsg = ShellPage.SendDefaultIPCMessage;
ViewModel = new AwakeViewModel();
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
_generalSettingsRepository = SettingsRepository<GeneralSettings>.GetInstance(_settingsUtils);
_moduleSettingsRepository = SettingsRepository<AwakeSettings>.GetInstance(_settingsUtils);
// We load the view model settings first.
LoadSettings(_generalSettingsRepository, _moduleSettingsRepository);
DataContext = ViewModel;
var settingsPath = _settingsUtils.GetSettingsFilePath(_appName);
_fileSystemWatcher = _fileSystem.FileSystemWatcher.CreateNew();
_fileSystemWatcher.Path = _fileSystem.Path.GetDirectoryName(settingsPath);
_fileSystemWatcher.Filter = _fileSystem.Path.GetFileName(settingsPath);
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime;
_fileSystemWatcher.Changed += Settings_Changed;
_fileSystemWatcher.EnableRaisingEvents = true;
InitializeComponent();
}
/// <summary>
/// Triggered whenever a view model property changes. This is done in addition to the baked-in view model changes.
/// </summary>
/// <remarks>
/// TODO: The logic here needs to be optimized since doing string comparison on values is not ideal.
/// </remarks>
/// <param name="sender">Sender of the change.</param>
/// <param name="e">Property parameter.</param>
private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (_sendConfigMsg != null)
{
if (e.PropertyName == "IsEnabled")
{
if (ViewModel.IsEnabled != _generalSettingsRepository.SettingsConfig.Enabled.Awake)
{
_generalSettingsRepository.SettingsConfig.Enabled.Awake = ViewModel.IsEnabled;
var generalSettingsMessage = new OutGoingGeneralSettings(_generalSettingsRepository.SettingsConfig).ToString();
Logger.LogInfo($"Saved general settings from Awake page.");
_sendConfigMsg(generalSettingsMessage);
}
}
else
{
if (ViewModel.ModuleSettings != null)
{
SndAwakeSettings currentSettings = new(_moduleSettingsRepository.SettingsConfig);
SndModuleSettings<SndAwakeSettings> csIpcMessage = new(currentSettings);
SndAwakeSettings outSettings = new(ViewModel.ModuleSettings);
SndModuleSettings<SndAwakeSettings> outIpcMessage = new(outSettings);
string csMessage = csIpcMessage.ToJsonString();
string outMessage = outIpcMessage.ToJsonString();
if (!csMessage.Equals(outMessage))
{
Logger.LogInfo($"Saved Awake settings from Awake page.");
_sendConfigMsg(outMessage);
}
}
}
}
}
private void LoadSettings(ISettingsRepository<GeneralSettings> generalSettingsRepository, ISettingsRepository<AwakeSettings> moduleSettingsRepository)
{
if (generalSettingsRepository != null)
{
if (moduleSettingsRepository != null)
{
UpdateViewModelSettings(moduleSettingsRepository.SettingsConfig, generalSettingsRepository.SettingsConfig);
}
else
{
throw new ArgumentNullException(nameof(moduleSettingsRepository));
}
}
else
{
throw new ArgumentNullException(nameof(generalSettingsRepository));
}
}
private void UpdateViewModelSettings(AwakeSettings awakeSettings, GeneralSettings generalSettings)
{
if (awakeSettings != null)
{
if (generalSettings != null)
{
ViewModel.IsEnabled = generalSettings.Enabled.Awake;
ViewModel.ModuleSettings = (AwakeSettings)awakeSettings.Clone();
UpdateEnabledState(generalSettings.Enabled.Awake);
}
else
{
throw new ArgumentNullException(nameof(generalSettings));
}
}
else
{
throw new ArgumentNullException(nameof(awakeSettings));
}
}
/// <summary>
/// Updates the tool enablement state.
/// </summary>
/// <param name="recommendedState">The state that is recommended for the tool, but can be overridden if a GPO policy is in place.</param>
private void UpdateEnabledState(bool recommendedState)
{
var enabledGpoRuleConfiguration = GPOWrapper.GetConfiguredAwakeEnabledValue();
if (enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
{
// Get the enabled state from GPO.
ViewModel.IsEnabledGpoConfigured = true;
ViewModel.IsEnabled = enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
else
{
ViewModel.IsEnabled = recommendedState;
}
}
private void Settings_Changed(object sender, FileSystemEventArgs e)
{
bool taskAdded = _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Normal, () =>
{
_moduleSettingsRepository.ReloadSettings();
LoadSettings(_generalSettingsRepository, _moduleSettingsRepository);
});
}
public void RefreshEnabledState()
{
ViewModel.RefreshEnabledState();