Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advanced Paste] Use background thread for interactions between runner and Advanced Paste #36858

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

drawbyperpetual
Copy link
Collaborator

Summary of the Pull Request

Before this change, the runner blocks on the Advanced Paste process connecting to the named pipe that it creates for communication. This slows down the PowerToys start-up routine and can hang PowerToys when the Advanced Paste process hangs or crashes.

This change fixes this issue by using a dedicated background thread (with a task queue) for all interactions between the runner and Advanced Paste.

PR Checklist

  • Closes: #xxx
  • [ X] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • Extracted code for runner-Advanced Paste interaction (launch / exit process, create named pipe, send messages, bring process to front) to a separate type.
  • Made interactions non-blocking by using src\common\utils\OnThreadExecutor.h
  • Added extra routine to consider Advanced Paste dead and kill it if it hasn't connected to named pipe in 5 seconds.
  • Made other miscellaneous improvements to code (refactoring, hardening, improved logging).

Validation Steps Performed

  • With Advanced Paste enabled, verify can bring up window via hotkey and send other app hotkeys.
  • Enable, disable, enable Advanced Paste from settings, verify can bring up window via hotkey.
  • Kill Advanced Paste process from Process Explorer, verify can bring up window via hotkey.
  • Simulate Advanced Paste process not connecting to named pipe, slow to start-up, dies after a few messages. Verify can bring up window via hotkey. Verify PowerToys / Settings does not hang.

Also verified logs are sensible in these situations.

@stefansjfw stefansjfw self-requested a review January 14, 2025 11:03
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.

1 participant