Skip to content

feat: let the controller wake the PC from sleep - #168

Merged
lippdev merged 4 commits into
mainfrom
feat/controller-wake
Oct 29, 2026
Merged

lippdev merged 4 commits into
mainfrom
feat/controller-wake

Conversation

@lippdev

@lippdev lippdev commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closes #155.

What wakes a sleeping PC is the device the controller talks through: the Xbox Wireless Adapter, the Bluetooth radio, or the controller itself on a cable. Windows only lets it once Allow this device to wake the computer is ticked in Device Manager. This PR finds those devices and ticks the box for them.

What changes

  • Services/ControllerWake.cs (pure, tested):
    • classifies the wake-capable devices by instance id + PnP class, which, unlike the name, isn't translated: Xbox adapter PIDs, Bluetooth radios (the USB\/PCI\ radio, not BTHENUM children), XInput &IG_ collections, XnaComposite/XboxComposite, and known gamepad vendors (Microsoft's VID is left out because it also covers keyboards and mice);
    • parses the query JSON and builds the scripts.
  • Services/ControllerWakeService.cs:
    • reads MSPower_DeviceWakeEnable and Win32_PnPEntity through a hidden PowerShell (about 0.5 s on the dev PC, no rights needed);
    • turns them on with Set-CimInstance in an elevated PowerShell (runas), so Windows shows the UAC prompt. A refused UAC (1223) is reported as "nothing changed".
  • UI:
    • a Wake the PC with the controller card in Settings (next to "Enter when a controller connects"), with the description, a live status line and a Turn on button;
    • a row in the console System tab → Controller, whose value is On / Turn on / Unavailable; pressing A runs it and the status explains the result.
    • The button re-reads the devices first, so an adapter plugged in after startup is picked up.
  • Strings in all 6 catalogs, the GUIDE paragraph in all 6 languages, a TESTING.md checklist.

Verified

  • dotnet test: 516 passed (14 new).
  • The app builds on Windows (x64 Debug) with 0 errors and no new warnings.
  • The query script runs on a real PC and returns the wake-capable devices with names and classes. That PC has no adapter or Bluetooth, and the console row correctly showed "Unavailable".
  • Not verified: the elevated enable step and an actual wake from sleep. They need the hardware; see the TESTING.md checklist.

🤖 Generated with Claude Code

lippdev and others added 2 commits October 21, 2026 10:44
Settings gets a "Wake the PC with the controller" card (and a row in the
console System tab) that lists the controller's adapters that can wake
the PC (Xbox Wireless Adapter, Bluetooth radio, wired controllers),
told apart by instance id through WMI MSPower_DeviceWakeEnable, and
turns "Allow this device to wake the computer" on for them through an
elevated PowerShell after the UAC prompt. Keyboards, mice and network
cards are left alone.

Closes #155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one edge case worth tightening inline.

Reviewed changes This review covers controller wake-device discovery, the elevated enable flow, its Settings and Console UI, and related tests, translations, and documentation.

  • Wake-device detection Classifies Xbox adapters, Bluetooth radios, and controller devices, then reads their Windows wake-enabled state.
  • Enable flow and UI Offers an elevated action from Settings and the Console System tab, with localized status reporting.
  • Coverage and documentation Adds pure-logic tests, translations, guide updates, and manual hardware checks.

Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • src/ConsoleMode/Services/ControllerWake.cs:401 (RIGHT) — line 401 (RIGHT) is not inside a diff hunk

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6-luna | 𝕏

@pullfrog

pullfrog Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

One edge case to address: if a device is unplugged while the UAC prompt is open, the enable script's filter can match no MSPower_DeviceWakeEnable instances and exit successfully. The service then reports Done even though no device was changed. Consider making a zero-match result fail or verifying the wake state after the update.

Pullfrog  | View workflow run | via Pullfrog | Using gpt-6-luna | 𝕏

…f Done

The enable script exits with code 2 when none of the devices is found, and the app reads the devices again afterwards: it only says Done when they really can wake the PC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one status message can misdiagnose a failed enable.

Reviewed changes This review covers the incremental update that detects wake devices disappearing while the administrator prompt is open and verifies their state after the enable attempt.

  • Enable result handling Added a distinct not-found exit code and post-enable reread to avoid reporting success when a device remains unarmed.
  • User feedback and coverage Added a localized message, tests, and a manual checklist for the disconnect-during-UAC case.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6-luna | 𝕏

if (result == ControllerWakeService.EnableResult.Done && ControllerWake.StillOff(off, _wakeDevices) is { Count: > 0 } stillOff)
{
AppLog.Write($"Acordar pelo controle: ainda desligado depois de ativar: {Names(stillOff)}");
result = _wakeDevices is null ? ControllerWakeService.EnableResult.Failed : ControllerWakeService.EnableResult.NotFound;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch labels every device still off after the write as NotFound, but StillOff also includes devices that are still present and simply did not become armed. In that case the UI tells the user the device was unplugged and to reconnect it; please distinguish a still-present device from one that disappeared so the status matches the failure.

# Conflicts:
#	CHANGELOG.en-US.md
#	CHANGELOG.md
#	docs/GUIDE.de-DE.md
#	docs/GUIDE.es-ES.md
#	docs/GUIDE.fr-FR.md
#	docs/GUIDE.md
#	docs/GUIDE.pt-BR.md
#	docs/GUIDE.ru-RU.md
#	tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj
@lippdev
lippdev merged commit 3631706 into main Oct 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feedback]

1 participant