Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
ba659449ac CmdPal: Fix crash on summon by dispatching HandleSummon to UI thread
When UseLowLevelGlobalHotkey is enabled, the ProcessCommand callback is
invoked directly from the WH_KEYBOARD_LL low-level keyboard hook, which
is an input-synchronous context. Calling ShowWindow/Hide from that
context triggers WinUI COM calls that COM forbids inside input-sync
calls, causing RPC_E_CANTCALLOUT_ININPUTSYNCCALL (0x8001010D).

Fix: wrap the callback with DispatcherQueue.TryEnqueue so HandleSummon
runs on the UI thread after the hook callback returns.

Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/17ab0175-9459-4b42-928e-5f7f27b97f6a

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
2026-04-29 10:01:02 +00:00
copilot-swe-agent[bot]
27eab5c739 Initial plan 2026-04-29 08:52:05 +00:00

View File

@@ -133,7 +133,17 @@ public sealed partial class MainWindow : WindowEx,
_keyboardListener = new KeyboardListener();
_keyboardListener.Start();
_keyboardListener.SetProcessCommand(new CmdPalKeyboardService.ProcessCommand(HandleSummon));
// Dispatch HandleSummon to the UI thread. When UseLowLevelGlobalHotkey is enabled,
// this ProcessCommand callback is invoked directly from the WH_KEYBOARD_LL low-level
// keyboard hook callback, which is an input-synchronous context. Calling window/WinUI
// operations (e.g. ShowWindow, Hide) from that context triggers outgoing COM calls that
// COM forbids inside input-sync calls, causing RPC_E_CANTCALLOUT_ININPUTSYNCCALL (0x8001010D).
// TryEnqueue posts the work to the UI thread's message queue so it runs after the hook
// callback returns, outside the input-sync restriction.
// Note: the standard WM_HOTKEY path (HotKeyPrc) already runs on the UI thread's message
// pump and does not require this dispatch.
_keyboardListener.SetProcessCommand(new CmdPalKeyboardService.ProcessCommand(
(id) => DispatcherQueue.TryEnqueue(() => HandleSummon(id))));
WM_TASKBAR_RESTART = PInvoke.RegisterWindowMessage("TaskbarCreated");