mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
[Awake]Reset Awake mode to "Keep using the selected power plan" (#31402)
* [Awake] Reset Awake mode to "Keep using the selected power plan" * [Awake] Remove duplicated code. * [Awake] Set passive even there is an issue in settings file. * [Awake] Remove unnecessary code
This commit is contained in:
@@ -10,11 +10,13 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using Awake.Core.Models;
|
||||
using Awake.Core.Native;
|
||||
using Awake.Properties;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.Win32;
|
||||
|
||||
@@ -153,6 +155,8 @@ namespace Awake.Core
|
||||
{
|
||||
Logger.LogInfo($"Completed expirable keep-awake.");
|
||||
CancelExistingThread();
|
||||
|
||||
SetPassiveKeepAwakeMode(Constants.AppName);
|
||||
},
|
||||
_tokenSource.Token);
|
||||
}
|
||||
@@ -179,6 +183,8 @@ namespace Awake.Core
|
||||
{
|
||||
Logger.LogInfo($"Completed timed thread.");
|
||||
CancelExistingThread();
|
||||
|
||||
SetPassiveKeepAwakeMode(Constants.AppName);
|
||||
},
|
||||
_tokenSource.Token);
|
||||
}
|
||||
@@ -285,5 +291,22 @@ namespace Awake.Core
|
||||
};
|
||||
return optionsList;
|
||||
}
|
||||
|
||||
public static void SetPassiveKeepAwakeMode(string moduleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
SettingsUtils settingsUtils = new SettingsUtils();
|
||||
AwakeSettings settings = new AwakeSettings();
|
||||
|
||||
settings.Properties.Mode = AwakeMode.PASSIVE;
|
||||
settingsUtils.SaveSettings(JsonSerializer.Serialize(settings), moduleName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string? errorString = $"Failed to reset Awake mode: {ex.Message}";
|
||||
Logger.LogError(errorString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,20 +117,7 @@ namespace Awake.Core
|
||||
|
||||
private static void PassiveKeepAwakeCommandHandler(string moduleName)
|
||||
{
|
||||
AwakeSettings currentSettings;
|
||||
|
||||
try
|
||||
{
|
||||
currentSettings = ModuleSettings!.GetSettings<AwakeSettings>(moduleName);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
currentSettings = new AwakeSettings();
|
||||
}
|
||||
|
||||
currentSettings.Properties.Mode = AwakeMode.PASSIVE;
|
||||
|
||||
ModuleSettings!.SaveSettings(JsonSerializer.Serialize(currentSettings), moduleName);
|
||||
Manager.SetPassiveKeepAwakeMode(moduleName);
|
||||
}
|
||||
|
||||
private static void IndefiniteKeepAwakeCommandHandler(string moduleName)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
KeepDisplayOn = false;
|
||||
Mode = AwakeMode.PASSIVE;
|
||||
IntervalHours = 0;
|
||||
IntervalMinutes = 0;
|
||||
IntervalMinutes = 1;
|
||||
ExpirationDateTime = DateTimeOffset.Now;
|
||||
CustomTrayTimes = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user