mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
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:
@@ -2,6 +2,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -13,25 +14,29 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
KeepDisplayOn = false;
|
||||
Mode = AwakeMode.PASSIVE;
|
||||
Hours = 0;
|
||||
Minutes = 0;
|
||||
TrayTimeShortcuts = new Dictionary<string, int>();
|
||||
IntervalHours = 0;
|
||||
IntervalMinutes = 0;
|
||||
ExpirationDateTime = DateTimeOffset.MinValue;
|
||||
CustomTrayTimes = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
[JsonPropertyName("awake_keep_display_on")]
|
||||
[JsonPropertyName("keepDisplayOn")]
|
||||
public bool KeepDisplayOn { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_mode")]
|
||||
[JsonPropertyName("mode")]
|
||||
public AwakeMode Mode { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_hours")]
|
||||
public uint Hours { get; set; }
|
||||
[JsonPropertyName("intervalHours")]
|
||||
public uint IntervalHours { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_minutes")]
|
||||
public uint Minutes { get; set; }
|
||||
[JsonPropertyName("intervalMinutes")]
|
||||
public uint IntervalMinutes { get; set; }
|
||||
|
||||
[JsonPropertyName("tray_times")]
|
||||
public Dictionary<string, int> TrayTimeShortcuts { get; set; }
|
||||
[JsonPropertyName("expirationDateTime")]
|
||||
public DateTimeOffset ExpirationDateTime { get; set; }
|
||||
|
||||
[JsonPropertyName("customTrayTimes")]
|
||||
public Dictionary<string, int> CustomTrayTimes { get; set; }
|
||||
}
|
||||
|
||||
public enum AwakeMode
|
||||
@@ -39,5 +44,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
PASSIVE = 0,
|
||||
INDEFINITE = 1,
|
||||
TIMED = 2,
|
||||
EXPIRABLE = 3,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
// 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.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class AwakeSettings : BasePTModuleSettings, ISettingsConfig
|
||||
public class AwakeSettings : BasePTModuleSettings, ISettingsConfig, ICloneable
|
||||
{
|
||||
public const string ModuleName = "Awake";
|
||||
public const string ModuleVersion = "0.0.1";
|
||||
public const string ModuleVersion = "0.0.2";
|
||||
|
||||
public AwakeSettings()
|
||||
{
|
||||
@@ -22,6 +24,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("properties")]
|
||||
public AwakeProperties Properties { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new AwakeSettings()
|
||||
{
|
||||
Name = Name,
|
||||
Version = Version,
|
||||
Properties = new AwakeProperties()
|
||||
{
|
||||
CustomTrayTimes = Properties.CustomTrayTimes.ToDictionary(entry => entry.Key, entry => entry.Value),
|
||||
Mode = Properties.Mode,
|
||||
KeepDisplayOn = Properties.KeepDisplayOn,
|
||||
IntervalMinutes = Properties.IntervalMinutes,
|
||||
IntervalHours = Properties.IntervalHours,
|
||||
ExpirationDateTime = Properties.ExpirationDateTime,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
|
||||
@@ -7,5 +7,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Interfaces
|
||||
public interface ISettingsRepository<T>
|
||||
{
|
||||
T SettingsConfig { get; set; }
|
||||
|
||||
bool ReloadSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,23 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
}
|
||||
|
||||
public bool ReloadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
T settingsItem = new T();
|
||||
settingsConfig = _settingsUtils.GetSettingsOrDefault<T>(settingsItem.GetModuleName());
|
||||
|
||||
SettingsConfig = settingsConfig;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Settings configurations shared across all viewmodels
|
||||
public T SettingsConfig
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user