mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Awake]Refactor and update version - DAISY023_04102024 (#32378)
Improves the following: - Consolidates different code paths for easier maintenance. - Removes the dependency on Windows Forms and creates the system tray icon and handling through native Win32 APIs (massive thank you to @BrianPeek for helping write the window creation logic and diagnosing threading issues). - Changing modes in Awake now triggers icon changes in the tray (#11996). Massive thank you to @niels9001 for creating the icons. Fixes the following: - When in the UI and you select `0` as hours and `0` as minutes in `TIMED` awake mode, the UI becomes non-responsive whenever you try to get back to timed after it rolls back to `PASSIVE`. (#33630) - Adds the option to keep track of Awake state through tray tooltip. (#12714) --------- Co-authored-by: Clint Rutkas <clint@rutkas.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
x:Uid="Awake_EnableSettingsCard"
|
||||
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Awake.png}"
|
||||
IsEnabled="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
|
||||
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
|
||||
</tkcontrols:SettingsCard>
|
||||
<InfoBar
|
||||
x:Uid="GPO_SettingIsManaged"
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Runtime.CompilerServices;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
@@ -66,20 +65,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsExpirationConfigurationEnabled
|
||||
{
|
||||
get => ModuleSettings.Properties.Mode == AwakeMode.EXPIRABLE && IsEnabled;
|
||||
}
|
||||
public bool IsExpirationConfigurationEnabled => ModuleSettings.Properties.Mode == AwakeMode.EXPIRABLE && IsEnabled;
|
||||
|
||||
public bool IsTimeConfigurationEnabled
|
||||
{
|
||||
get => ModuleSettings.Properties.Mode == AwakeMode.TIMED && IsEnabled;
|
||||
}
|
||||
public bool IsTimeConfigurationEnabled => ModuleSettings.Properties.Mode == AwakeMode.TIMED && IsEnabled;
|
||||
|
||||
public bool IsScreenConfigurationPossibleEnabled
|
||||
{
|
||||
get => ModuleSettings.Properties.Mode != AwakeMode.PASSIVE && IsEnabled;
|
||||
}
|
||||
public bool IsScreenConfigurationPossibleEnabled => ModuleSettings.Properties.Mode != AwakeMode.PASSIVE && IsEnabled;
|
||||
|
||||
public AwakeMode Mode
|
||||
{
|
||||
@@ -90,6 +80,26 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
ModuleSettings.Properties.Mode = value;
|
||||
|
||||
if (value == AwakeMode.TIMED && IntervalMinutes == 0 && IntervalHours == 0)
|
||||
{
|
||||
// Handle the special case where both hours and minutes are zero.
|
||||
// Otherwise, this will reset to passive very quickly in the UI.
|
||||
ModuleSettings.Properties.IntervalMinutes = 1;
|
||||
OnPropertyChanged(nameof(IntervalMinutes));
|
||||
}
|
||||
else if (value == AwakeMode.EXPIRABLE && ExpirationDateTime <= DateTimeOffset.Now)
|
||||
{
|
||||
// To make sure that we're not tracking expirable keep-awake in the past,
|
||||
// let's make sure that every time it's enabled from the settings UI, it's
|
||||
// five (5) minutes into the future.
|
||||
ExpirationDateTime = DateTimeOffset.Now.AddMinutes(5);
|
||||
|
||||
// The expiration date/time is updated and will send the notification
|
||||
// but we need to do this manually for the expiration time that is
|
||||
// bound to the time control on the settings page.
|
||||
OnPropertyChanged(nameof(ExpirationTime));
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
|
||||
OnPropertyChanged(nameof(IsScreenConfigurationPossibleEnabled));
|
||||
OnPropertyChanged(nameof(IsExpirationConfigurationEnabled));
|
||||
|
||||
Reference in New Issue
Block a user