[MouseJump]Bring back telemetry events (#35582)

This commit is contained in:
Jaime Bernardo
2024-10-25 13:28:01 +01:00
committed by GitHub
parent 133aa85f2b
commit a0138cec5e
7 changed files with 38 additions and 6 deletions

View File

@@ -62,9 +62,12 @@ private:
Hotkey m_hotkey;
// Handle to event used to invoke PowerOCR
// Handle to event used to invoke MouseJump
HANDLE m_hInvokeEvent;
// Handle to event used to terminate MouseJump
HANDLE m_hTerminateEvent;
void parse_hotkey(PowerToysSettings::PowerToyValues& settings)
{
auto settingsObject = settings.get_raw_json();
@@ -154,6 +157,7 @@ public:
{
LoggerHelpers::init_logger(MODULE_NAME, L"ModuleInterface", LogSettings::mouseJumpLoggerName);
m_hInvokeEvent = CreateDefaultEvent(CommonSharedConstants::MOUSE_JUMP_SHOW_PREVIEW_EVENT);
m_hTerminateEvent = CreateDefaultEvent(CommonSharedConstants::TERMINATE_MOUSE_JUMP_SHARED_EVENT);
init_settings();
};
@@ -245,6 +249,8 @@ public:
if (m_enabled)
{
ResetEvent(m_hInvokeEvent);
SetEvent(m_hTerminateEvent);
WaitForSingleObject(m_hProcess, 1500);
TerminateProcess(m_hProcess, 1);
}

View File

@@ -166,6 +166,7 @@ internal sealed partial class MainForm : Form
// move mouse pointer
Logger.LogInfo($"clicked location = {clickedLocation}");
Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new Telemetry.MouseJumpTeleportCursorEvent());
MouseHelper.SetCursorPosition(clickedLocation);
}
@@ -202,6 +203,8 @@ internal sealed partial class MainForm : Form
stopwatch.Stop();
Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new Telemetry.MouseJumpShowEvent());
// we have to activate the form to make sure the deactivate event fires
this.Activate();
}

View File

@@ -13,6 +13,7 @@ using System.Windows.Threading;
using Common.UI;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Telemetry;
using MouseJumpUI.Helpers;
using PowerToys.Interop;
@@ -20,6 +21,8 @@ namespace MouseJumpUI;
internal static class Program
{
private static CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
/// <summary>
/// The main entry point for the application.
/// </summary>
@@ -27,6 +30,7 @@ internal static class Program
private static void Main(string[] args)
{
Logger.InitializeLogger("\\MouseJump\\Logs");
ETWTrace etwTrace = new ETWTrace();
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
@@ -62,13 +66,10 @@ internal static class Program
Logger.LogInfo($"Mouse Jump started from the PowerToys Runner. Runner pid={runnerPid}");
var cancellationTokenSource = new CancellationTokenSource();
RunnerHelper.WaitForPowerToysRunner(runnerPid, () =>
{
Logger.LogInfo("PowerToys Runner exited. Exiting Mouse Jump");
cancellationTokenSource.Cancel();
Application.Exit();
Logger.LogInfo("PowerToys Runner exited.");
TerminateApp();
});
var settingsHelper = new SettingsHelper();
@@ -80,7 +81,21 @@ internal static class Program
Dispatcher.CurrentDispatcher,
cancellationTokenSource.Token);
NativeEventWaiter.WaitForEventLoop(
Constants.TerminateMouseJumpSharedEvent(),
TerminateApp,
Dispatcher.CurrentDispatcher,
cancellationTokenSource.Token);
Application.Run();
etwTrace?.Dispose();
}
private static void TerminateApp()
{
Logger.LogInfo("Exiting Mouse Jump.");
cancellationTokenSource.Cancel();
Application.Exit();
}
private static MouseJumpSettings ReadSettings()