Skip to content

Awake and DevEx improvements#44795

Merged
dend merged 26 commits intomicrosoft:mainfrom
dend:main
Jan 21, 2026
Merged

Awake and DevEx improvements#44795
dend merged 26 commits intomicrosoft:mainfrom
dend:main

Conversation

@dend
Copy link
Copy Markdown
Contributor

@dend dend commented Jan 18, 2026

This PR contains a set of bug fixes and general improvements to Awake and developer experience tooling for building the module.

Awake Fixes

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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.
@github-actions

This comment has been minimized.

@github-actions

This comment was marked as resolved.

@dend dend marked this pull request as ready for review January 20, 2026 02:21
@dend
Copy link
Copy Markdown
Contributor Author

dend commented Jan 20, 2026

@crutkas this is ready for review - I will hold off on other feature changes to Awake before this gets released.

@dend dend added Needs-Review This Pull Request awaits the review of a maintainer. Product-Awake Issues regarding the PowerToys Awake utility labels Jan 20, 2026
@dend dend requested a review from vanzue January 20, 2026 21:29
@dend dend merged commit 27dcd1e into microsoft:main Jan 21, 2026
11 checks passed
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.
@vanzue vanzue added this to the PowerToys 0.97 milestone Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Review This Pull Request awaits the review of a maintainer. Product-Awake Issues regarding the PowerToys Awake utility

Projects

None yet

3 participants