Skip to content

Commit

Permalink
Fixes #35848
Browse files Browse the repository at this point in the history
  • Loading branch information
dend committed Nov 27, 2024
1 parent 763a537 commit 00ad336
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/modules/awake/Awake/Core/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Globalization;
using System.IO;
using System.Reactive.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -233,9 +234,9 @@ internal static void SetExpirableKeepAwake(DateTimeOffset expireAt, bool keepDis
}
}

internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true)
internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true, [CallerMemberName] string callerName = "")
{
Logger.LogInfo($"Timed keep-awake. Expected runtime: {seconds} seconds with display on setting set to {keepDisplayOn}.");
Logger.LogInfo($"Timed keep-awake invoked by {callerName}. Expected runtime: {seconds} seconds with display on setting set to {keepDisplayOn}.");

PowerToysTelemetry.Log.WriteEvent(new Telemetry.AwakeTimedKeepAwakeEvent());

Expand All @@ -262,7 +263,7 @@ internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true)
},
() =>
{
Console.WriteLine("Completed timed thread.");
Logger.LogInfo("Completed timed thread.");
CancelExistingThread();
if (IsUsingPowerToysConfig)
Expand All @@ -285,15 +286,19 @@ internal static void SetTimedKeepAwake(uint seconds, bool keepDisplayOn = true)
{
AwakeSettings currentSettings = ModuleSettings!.GetSettings<AwakeSettings>(Constants.AppName) ?? new AwakeSettings();
TimeSpan timeSpan = TimeSpan.FromSeconds(seconds);

uint totalHours = (uint)timeSpan.TotalHours;
uint remainingMinutes = (uint)(timeSpan.TotalMinutes % 60);

bool settingsChanged = currentSettings.Properties.Mode != AwakeMode.TIMED ||
currentSettings.Properties.IntervalHours != (uint)timeSpan.Hours ||
currentSettings.Properties.IntervalMinutes != (uint)timeSpan.Minutes;
currentSettings.Properties.IntervalHours != totalHours ||
currentSettings.Properties.IntervalMinutes != remainingMinutes;

if (settingsChanged)
{
currentSettings.Properties.Mode = AwakeMode.TIMED;
currentSettings.Properties.IntervalHours = (uint)timeSpan.Hours;
currentSettings.Properties.IntervalMinutes = (uint)timeSpan.Minutes;
currentSettings.Properties.IntervalHours = totalHours;
currentSettings.Properties.IntervalMinutes = remainingMinutes;
ModuleSettings!.SaveSettings(JsonSerializer.Serialize(currentSettings), Constants.AppName);
}
}
Expand Down

0 comments on commit 00ad336

Please sign in to comment.