Skip to content

Commit 3df600a

Browse files
committed
fix find my mouse disappear too quickly
1 parent 2e24ca4 commit 3df600a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/MouseUtils/ToggleFindMyMouseCommand.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Threading;
7+
using System.Threading.Tasks;
78
using Microsoft.CommandPalette.Extensions.Toolkit;
89
using PowerToys.Interop;
910

@@ -21,15 +22,21 @@ public ToggleFindMyMouseCommand()
2122

2223
public override CommandResult Invoke()
2324
{
24-
try
25+
// Delay the trigger so the Command Palette dismisses first
26+
_ = Task.Run(async () =>
2527
{
26-
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FindMyMouseTriggerEvent());
27-
evt.Set();
28-
return CommandResult.Dismiss();
29-
}
30-
catch (Exception ex)
31-
{
32-
return CommandResult.ShowToast($"Failed to trigger Find My Mouse: {ex.Message}");
33-
}
28+
await Task.Delay(200).ConfigureAwait(false);
29+
try
30+
{
31+
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FindMyMouseTriggerEvent());
32+
evt.Set();
33+
}
34+
catch
35+
{
36+
// Ignore errors in background task
37+
}
38+
});
39+
40+
return CommandResult.Dismiss();
3441
}
3542
}

0 commit comments

Comments
 (0)