Merged
Conversation
Added documentation for issue microsoft#44134 explaining that enabling 'Keep display on' uses ES_DISPLAY_REQUIRED, which blocks Windows Task Scheduler from detecting idle state and prevents scheduled maintenance tasks. Provided workarounds and referenced relevant Microsoft documentation.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This was
linked to
issues
Jan 19, 2026
Closed
This was
linked to
issues
Jan 19, 2026
Resolved tray icon not appearing after Windows updates by increasing retry attempts and delays for Add operations. Fixed tray icon not disappearing when Awake is disabled by allowing Delete operations without an icon. Addressed potential stack overflow in EXPIRABLE mode by adding an early return after correcting expiration times.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
Author
|
@crutkas this is ready for review - I will hold off on other feature changes to Awake before this gets released. |
vanzue
approved these changes
Jan 20, 2026
vanzue
approved these changes
Jan 21, 2026
yeelam-gordon
pushed a commit
that referenced
this pull request
Jan 31, 2026
This PR contains a set of bug fixes and general improvements to [Awake](https://awake.den.dev/) and developer experience tooling for building the module. ### Awake Fixes - **#32544** - Fixed an issue where Awake settings became non-functional after the PC wakes from sleep. Added `WM_POWERBROADCAST` handling to detect system resume events (`PBT_APMRESUMEAUTOMATIC`, `PBT_APMRESUMESUSPEND`) and re-apply `SetThreadExecutionState` to restore the awake state. - **#36150** - Fixed an issue where Awake would not prevent sleep when AC power is connected. Added `PBT_APMPOWERSTATUSCHANGE` handling to re-apply `SetThreadExecutionState` when the power source changes (AC/battery transitions). - **#41674** - Fixed silent failure when `SetThreadExecutionState` fails. The monitor thread now handles the return value, logs an error, and reverts to passive mode with updated tray icon. - **#41738** - Fixed `--display-on` CLI flag default from `true` to `false` to align with documentation and PowerToys settings behavior. This is a breaking change for scripts relying on the undocumented default. - **#41918** - Fixed `WM_COMMAND` message processing flaw in `TrayHelper.WndProc` that incorrectly compared enum values against enum count. Added proper bounds checking for custom tray time entries. - **#44134** - Documented that `ES_DISPLAY_REQUIRED` (used when "Keep display on" is enabled) blocks Task Scheduler idle detection, preventing scheduled maintenance tasks like SSD TRIM. Workaround: disable "Keep display on" or manually run `Optimize-Volume -DriveLetter C -ReTrim`. - **#38770** - Fixed tray icon failing to appear after Windows updates. Increased retry attempts and delays for icon Add operations (10 attempts, up to ~15.5 seconds total) while keeping existing fast retry behavior for Update/Delete operations. - **#40501** - Fixed tray icon not disappearing when Awake is disabled. The `SetShellIcon` function was incorrectly requiring an icon for Delete operations, causing the `NIM_DELETE` message to never be sent. - Fixed an issue where toggling "Keep screen on" during an active timed session would disrupt the countdown timer. The display setting now updates directly without restarting the timer, preserving the exact remaining time. ### Performance Optimizations - Fixed O(n²) loop in `TrayHelper.CreateAwakeTimeSubMenu` by replacing `ElementAt(i)` with `foreach` iteration. - Fixed Observable subscription leak in `Manager.cs` by storing `IDisposable` and disposing in `CancelExistingThread()`. Also removed dead `_tokenSource` code that was no longer used. - Reduced allocations in `SingleThreadSynchronizationContext` by changing `Tuple<>` to `ValueTuple`. - Replaced dedicated exit event thread with `ThreadPool.RegisterWaitForSingleObject()` to reduce resource usage. ### Code Quality - Replaced `Console.WriteLine` with `Logger.LogError` in `TrayHelper.cs` for consistent logging. - Added proper error logging to silent exception catches in `AwakeService.cs`. - Removed dead `Math.Min(minutes, int.MaxValue)` code where `minutes` is already an `int`. - Extracted hardcoded tray icon ID to named constant `TrayIconId`. - Standardized null coalescing for `GetSettings<AwakeSettings>()` calls across all files. ### Debugging Experience Fixes - Fixed first-chance exceptions in `settings_window.cpp` during debugging. Added `HasKey()` check before accessing `hotkey_changed` property to prevent `hresult_error` exceptions when the property doesn't exist in module settings. - Fixed first-chance exceptions in FindMyMouse `parse_settings` during debugging. Refactored to extract the properties object once and added `HasKey()` checks before all `GetNamedObject()` calls. This prevents `winrt::hresult_error` exceptions when optional settings keys (like legacy `overlay_opacity`) don't exist, improving the debugging experience by eliminating spurious exception breaks. - Fixed LightSwitch.UITests build failures when building from a clean state. Added missing project references (`ManagedCommon`, `LightSwitchModuleInterface`) with `ReferenceOutputAssembly=false` to ensure proper build ordering, and added existence check for the native DLL copy operation. ### Developer Experience - Added `setup-dev-environment.ps1` script to automate development environment setup. - Added `clean-artifacts.ps1` script to resolve build errors from corrupted build state or missing image files. - Added build script that allows standalone command line build of the Awake module. - Added troubleshooting section to `doc/devdocs/development/debugging.md` with guidance on resolving common build errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains a set of bug fixes and general improvements to Awake and developer experience tooling for building the module.
Awake Fixes
Awake settings are ignored when PC is woken from sleep #32544 - Fixed an issue where Awake settings became non-functional after the PC wakes from sleep. Added
WM_POWERBROADCASThandling to detect system resume events (PBT_APMRESUMEAUTOMATIC,PBT_APMRESUMESUSPEND) and re-applySetThreadExecutionStateto restore the awake state.Awake does not work if DC power is connected #36150 - Fixed an issue where Awake would not prevent sleep when AC power is connected. Added
PBT_APMPOWERSTATUSCHANGEhandling to re-applySetThreadExecutionStatewhen the power source changes (AC/battery transitions).[Awake] SetThreadExecutionState failure not handled - silent failure bug when changing state #41674 - Fixed silent failure when
SetThreadExecutionStatefails. The monitor thread now handles the return value, logs an error, and reverts to passive mode with updated tray icon.[Awake] Inconsistency in --display-on default behaviour and documentation #41738 - Fixed
--display-onCLI flag default fromtruetofalseto align with documentation and PowerToys settings behavior. This is a breaking change for scripts relying on the undocumented default.[Awake] WM_COMMAND message processing flaw #41918 - Fixed
WM_COMMANDmessage processing flaw inTrayHelper.WndProcthat incorrectly compared enum values against enum count. Added proper bounds checking for custom tray time entries.Scheduled TRIM doesn't happen with Awake enabled. #44134 - Documented that
ES_DISPLAY_REQUIRED(used when "Keep display on" is enabled) blocks Task Scheduler idle detection, preventing scheduled maintenance tasks like SSD TRIM. Workaround: disable "Keep display on" or manually runOptimize-Volume -DriveLetter C -ReTrim.Awake Icon in tray is missing after windows update #38770 - Fixed tray icon failing to appear after Windows updates. Increased retry attempts and delays for icon Add operations (10 attempts, up to ~15.5 seconds total) while keeping existing fast retry behavior for Update/Delete operations.
The Awake tray icon does not disappear #40501 - Fixed tray icon not disappearing when Awake is disabled. The
SetShellIconfunction was incorrectly requiring an icon for Delete operations, causing theNIM_DELETEmessage to never be sent.Fixed an issue where toggling "Keep screen on" during an active timed session would disrupt the countdown timer. The display setting now updates directly without restarting the timer, preserving the exact remaining time.
Performance Optimizations
Fixed O(n²) loop in
TrayHelper.CreateAwakeTimeSubMenuby replacingElementAt(i)withforeachiteration.Fixed Observable subscription leak in
Manager.csby storingIDisposableand disposing inCancelExistingThread(). Also removed dead_tokenSourcecode that was no longer used.Reduced allocations in
SingleThreadSynchronizationContextby changingTuple<>toValueTuple.Replaced dedicated exit event thread with
ThreadPool.RegisterWaitForSingleObject()to reduce resource usage.Code Quality
Replaced
Console.WriteLinewithLogger.LogErrorinTrayHelper.csfor consistent logging.Added proper error logging to silent exception catches in
AwakeService.cs.Removed dead
Math.Min(minutes, int.MaxValue)code whereminutesis already anint.Extracted hardcoded tray icon ID to named constant
TrayIconId.Standardized null coalescing for
GetSettings<AwakeSettings>()calls across all files.Debugging Experience Fixes
Fixed first-chance exceptions in
settings_window.cppduring debugging. AddedHasKey()check before accessinghotkey_changedproperty to preventhresult_errorexceptions when the property doesn't exist in module settings.Fixed first-chance exceptions in FindMyMouse
parse_settingsduring debugging. Refactored to extract the properties object once and addedHasKey()checks before allGetNamedObject()calls. This preventswinrt::hresult_errorexceptions when optional settings keys (like legacyoverlay_opacity) don't exist, improving the debugging experience by eliminating spurious exception breaks.Fixed LightSwitch.UITests build failures when building from a clean state. Added missing project references (
ManagedCommon,LightSwitchModuleInterface) withReferenceOutputAssembly=falseto ensure proper build ordering, and added existence check for the native DLL copy operation.Developer Experience
setup-dev-environment.ps1script to automate development environment setup.clean-artifacts.ps1script to resolve build errors from corrupted build state or missing image files.doc/devdocs/development/debugging.mdwith guidance on resolving common build errors.