Settings telemetry for PT Run (#10328)

This commit is contained in:
Mykhailo Pylyp
2021-03-19 19:03:12 +02:00
committed by GitHub
parent 057e92afb8
commit 612e9f8b99
13 changed files with 205 additions and 6 deletions

View File

@@ -82,6 +82,10 @@ public:
* if the key press is to be swallowed.
*/
virtual bool on_hotkey(size_t hotkeyId) { return false; }
virtual void send_settings_telemetry()
{
}
};
/*

View File

@@ -81,6 +81,17 @@ private:
// Handle to event used to invoke the Runner
HANDLE m_hEvent;
HANDLE send_telemetry_event;
SECURITY_ATTRIBUTES getDefaultSecurityAttribute()
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.bInheritHandle = false;
sa.lpSecurityDescriptor = NULL;
return sa;
}
public:
// Constructor
Microsoft_Launcher()
@@ -93,11 +104,10 @@ public:
Logger::info("Launcher object is constructing");
init_settings();
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.bInheritHandle = false;
sa.lpSecurityDescriptor = NULL;
m_hEvent = CreateEventW(&sa, FALSE, FALSE, CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT);
auto sa1 = getDefaultSecurityAttribute();
m_hEvent = CreateEventW(&sa1, FALSE, FALSE, CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT);
auto sa2 = getDefaultSecurityAttribute();
send_telemetry_event = CreateEventW(&sa2, FALSE, FALSE, CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT);
};
~Microsoft_Launcher()
@@ -185,6 +195,7 @@ public:
{
Logger::info("Launcher is enabling");
ResetEvent(m_hEvent);
ResetEvent(send_telemetry_event);
// Start PowerLauncher.exe only if the OS is 19H1 or higher
if (UseNewSettings())
{
@@ -265,6 +276,7 @@ public:
if (m_enabled)
{
ResetEvent(m_hEvent);
ResetEvent(send_telemetry_event);
terminateProcess();
}
@@ -347,6 +359,12 @@ public:
}
*/
}
virtual void send_settings_telemetry() override
{
Logger::info("Send settings telemetry");
SetEvent(send_telemetry_event);
}
};
// Load the settings file.

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.Tracing;
namespace PowerLauncher.Telemetry.Events
{
[EventData]
public class PluginModel
{
public bool Disabled { get; set; }
public bool IsGlobal { get; set; }
public string ActionKeyword { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace PowerLauncher.Telemetry.Events
{
[EventData]
public class RunPluginsSettingsEvent : EventBase, IEvent
{
public RunPluginsSettingsEvent(IDictionary<string, PluginModel> pluginManager)
{
PluginManager = pluginManager;
}
public IDictionary<string, PluginModel> PluginManager { get; private set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -21,7 +21,7 @@ namespace PowerLauncher.Helper
{
if (eventHandle.WaitOne())
{
Log.Info("Successfully waited for POWER_LAUNCHER_SHARED_EVENT", MethodBase.GetCurrentMethod().DeclaringType);
Log.Info($"Successfully waited for {eventName}", MethodBase.GetCurrentMethod().DeclaringType);
Application.Current.Dispatcher.Invoke(callback);
}
}

View File

@@ -4,14 +4,18 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
using interop;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
using PowerLauncher.Helper;
using PowerLauncher.Plugin;
using PowerLauncher.Telemetry.Events;
using PowerLauncher.ViewModel;
using Wox.Infrastructure.UserSettings;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
@@ -40,6 +44,21 @@ namespace PowerLauncher
_firstDeleteTimer.Elapsed += CheckForFirstDelete;
_firstDeleteTimer.Interval = 1000;
NativeEventWaiter.WaitForEventLoop(Constants.RunSendSettingsTelemetryEvent(), SendSettingsTelemetry);
}
private void SendSettingsTelemetry()
{
Log.Info("Send Run settings telemetry", this.GetType());
var plugins = PluginManager.AllPlugins.ToDictionary(x => x.Metadata.Name, x => new PluginModel()
{
Disabled = x.Metadata.Disabled,
ActionKeyword = x.Metadata.ActionKeyword,
IsGlobal = x.Metadata.IsGlobal,
});
var telemetryEvent = new RunPluginsSettingsEvent(plugins);
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
}
private void CheckForFirstDelete(object sender, ElapsedEventArgs e)