mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
Data diagnostics opt-in
This commit is contained in:
@@ -224,4 +224,8 @@ namespace winrt::PowerToys::GPOWrapper::implementation
|
||||
{
|
||||
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredNewPlusHideTemplateFilenameExtensionValue());
|
||||
}
|
||||
GpoRuleConfigured GPOWrapper::GetAllowDataDiagnosticsValue()
|
||||
{
|
||||
return static_cast<GpoRuleConfigured>(powertoys_gpo::getAllowDataDiagnosticsValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace winrt::PowerToys::GPOWrapper::implementation
|
||||
static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue();
|
||||
static winrt::hstring GPOWrapper::GetConfiguredMwbPolicyDefinedIpMappingRules();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
|
||||
static GpoRuleConfigured GetAllowDataDiagnosticsValue();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace PowerToys
|
||||
static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue();
|
||||
static String GetConfiguredMwbPolicyDefinedIpMappingRules();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
|
||||
static GpoRuleConfigured GetAllowDataDiagnosticsValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
107
src/common/ManagedTelemetry/Telemetry/DataDiagnosticsSettings.cs
Normal file
107
src/common/ManagedTelemetry/Telemetry/DataDiagnosticsSettings.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
// 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;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Microsoft.PowerToys.Telemetry
|
||||
{
|
||||
public static class DataDiagnosticsSettings
|
||||
{
|
||||
private static readonly string DataDiagnosticsRegistryKey = @"HKEY_CURRENT_USER\Software\Classes\PowerToys\";
|
||||
private static readonly string DataDiagnosticsRegistryValueName = @"AllowDataDiagnostics";
|
||||
private static readonly string DataDiagnosticsDataDiagnosticsUserActionRegistryValueName = @"DataDiagnosticsUserAction";
|
||||
private static readonly string DataDiagnosticsDataDiagnosticsViewDataRegistryValueName = @"DataDiagnosticsViewEnabled";
|
||||
|
||||
public static bool GetEnabledValue()
|
||||
{
|
||||
object registryValue = null;
|
||||
try
|
||||
{
|
||||
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (registryValue is not null)
|
||||
{
|
||||
return (int)registryValue == 1 ? true : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetEnabledValue(bool value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Registry.SetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, value ? 1 : 0);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetUserActionValue()
|
||||
{
|
||||
object registryValue = null;
|
||||
try
|
||||
{
|
||||
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsUserActionRegistryValueName, 0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (registryValue is not null)
|
||||
{
|
||||
return (int)registryValue == 1 ? true : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetUserActionValue(bool value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Registry.SetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsUserActionRegistryValueName, value ? 1 : 0);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetViewEnabledValue()
|
||||
{
|
||||
object registryValue = null;
|
||||
try
|
||||
{
|
||||
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsViewDataRegistryValueName, 0);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (registryValue is not null)
|
||||
{
|
||||
return (int)registryValue == 1 ? true : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetViewEnabledValue(bool value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Registry.SetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsViewDataRegistryValueName, value ? 1 : 0);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
147
src/common/ManagedTelemetry/Telemetry/EtwTrace.cs
Normal file
147
src/common/ManagedTelemetry/Telemetry/EtwTrace.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
// 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;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Microsoft.Diagnostics.Tracing.Session;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
namespace Microsoft.PowerToys.Telemetry
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is based loosely on the C++ ETWTrace class in Win32client/Framework project.
|
||||
/// It is intended to record telemetry events generated by the PowerToys processes so that end users
|
||||
/// can view them if they want.
|
||||
/// </summary>
|
||||
public class ETWTrace : IDisposable
|
||||
{
|
||||
internal const EventKeywords TelemetryKeyword = (EventKeywords)0x0000200000000000;
|
||||
internal const EventKeywords MeasuresKeyword = (EventKeywords)0x0000400000000000;
|
||||
internal const EventKeywords CriticalDataKeyword = (EventKeywords)0x0000800000000000;
|
||||
|
||||
private readonly bool telemetryEnabled = DataDiagnosticsSettings.GetEnabledValue(); // This is the global telemetry setting on whether to log events
|
||||
private readonly bool telemetryRecordingEnabled = DataDiagnosticsSettings.GetViewEnabledValue(); // This is the setting for recording telemetry events to disk for vewng
|
||||
private readonly string etwFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\", "etw");
|
||||
private bool disposedValue;
|
||||
private string sessionName;
|
||||
private string etwFilePath;
|
||||
private bool started;
|
||||
#nullable enable
|
||||
private TraceEventSession? traceSession;
|
||||
|
||||
internal sealed class Lister : EventListener
|
||||
{
|
||||
public Lister()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private Lister? listener;
|
||||
#nullable disable
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ETWTrace"/> class.
|
||||
/// </summary>
|
||||
public ETWTrace()
|
||||
{
|
||||
if (File.Exists(etwFolderPath))
|
||||
{
|
||||
File.Delete(etwFolderPath);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(etwFolderPath))
|
||||
{
|
||||
Directory.CreateDirectory(etwFolderPath);
|
||||
}
|
||||
|
||||
if (this.telemetryEnabled && this.telemetryRecordingEnabled)
|
||||
{
|
||||
this.Start();
|
||||
}
|
||||
|
||||
listener = new Lister();
|
||||
listener.EnableEvents(PowerToysTelemetry.Log, EventLevel.LogAlways);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
this.Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the trace session.
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (this.started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string executable = Process.GetCurrentProcess().ProcessName;
|
||||
string dateTimeNow = DateTime.Now.ToString("MM-d-yyy__H_mm_ss", CultureInfo.InvariantCulture);
|
||||
this.sessionName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}", executable, Environment.ProcessId, dateTimeNow);
|
||||
this.etwFilePath = Path.Combine(etwFolderPath, $"{this.sessionName}.etl");
|
||||
|
||||
this.traceSession = new TraceEventSession(
|
||||
this.sessionName, this.etwFilePath, (TraceEventSessionOptions)(TraceEventSessionOptions.Create | TraceEventSessionOptions.PrivateLogger | TraceEventSessionOptions.PrivateInProcLogger));
|
||||
TraceEventProviderOptions args = new TraceEventProviderOptions();
|
||||
|
||||
this.traceSession.EnableProvider(
|
||||
PowerToysTelemetry.Log.Guid,
|
||||
matchAnyKeywords: (ulong)TelemetryKeyword | (ulong)MeasuresKeyword | (ulong)CriticalDataKeyword);
|
||||
|
||||
this.started = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the trace session.
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!this.started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.traceSession != null)
|
||||
{
|
||||
Trace.TraceInformation("Disposing EventTraceSession");
|
||||
this.traceSession.Dispose();
|
||||
this.traceSession = null;
|
||||
this.started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the object.
|
||||
/// </summary>
|
||||
/// <param name="disposing">boolean for disposing.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
this.Stop();
|
||||
}
|
||||
|
||||
this.disposedValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>PowerToys Telemetry</Description>
|
||||
<AssemblyName>PowerToys.ManagedTelemetry</AssemblyName>
|
||||
@@ -11,4 +11,9 @@
|
||||
<Compile Include="..\..\Telemetry\TelemetryBase.cs" Link="TelemetryBase.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" />
|
||||
<PackageReference Include="System.Diagnostics.Tracing" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -37,14 +37,17 @@ namespace Microsoft.PowerToys.Telemetry
|
||||
public void WriteEvent<T>(T telemetryEvent)
|
||||
where T : EventBase, IEvent
|
||||
{
|
||||
this.Write<T>(
|
||||
telemetryEvent.EventName,
|
||||
new EventSourceOptions()
|
||||
{
|
||||
Keywords = ProjectKeywordMeasure,
|
||||
Tags = ProjectTelemetryTagProductAndServicePerformance,
|
||||
},
|
||||
telemetryEvent);
|
||||
if (DataDiagnosticsSettings.GetEnabledValue())
|
||||
{
|
||||
this.Write<T>(
|
||||
telemetryEvent.EventName,
|
||||
new EventSourceOptions()
|
||||
{
|
||||
Keywords = ProjectKeywordMeasure,
|
||||
Tags = ProjectTelemetryTagProductAndServicePerformance,
|
||||
},
|
||||
telemetryEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace PTSettingsHelper
|
||||
constexpr inline const wchar_t* last_version_run_filename = L"last_version_run.json";
|
||||
constexpr inline const wchar_t* opened_at_first_launch_json_field_name = L"openedAtFirstLaunch";
|
||||
constexpr inline const wchar_t* last_version_json_field_name = L"last_version";
|
||||
constexpr inline const wchar_t* DataDiagnosticsRegKey = L"Software\\Classes\\PowerToys";
|
||||
constexpr inline const wchar_t* DataDiagnosticsRegValueName = L"AllowDataDiagnostics";
|
||||
|
||||
std::wstring get_root_save_folder_location()
|
||||
{
|
||||
@@ -25,7 +27,7 @@ namespace PTSettingsHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring get_local_low_folder_location()
|
||||
std::wstring get_local_low_folder_location()
|
||||
{
|
||||
PWSTR local_app_path;
|
||||
winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppDataLow, 0, NULL, &local_app_path));
|
||||
@@ -112,7 +114,7 @@ namespace PTSettingsHelper
|
||||
bool opened = saved_settings->GetNamedBoolean(opened_at_first_launch_json_field_name, false);
|
||||
return opened;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -124,12 +126,11 @@ namespace PTSettingsHelper
|
||||
json::JsonObject obj;
|
||||
obj.SetNamedValue(opened_at_first_launch_json_field_name, json::value(true));
|
||||
|
||||
json::to_file(oobePath.c_str(), obj);
|
||||
json::to_file(oobePath.c_str(), obj);
|
||||
}
|
||||
|
||||
std::wstring get_last_version_run()
|
||||
{
|
||||
|
||||
std::filesystem::path lastVersionRunPath(PTSettingsHelper::get_root_save_folder_location());
|
||||
lastVersionRunPath = lastVersionRunPath.append(last_version_run_filename);
|
||||
if (std::filesystem::exists(lastVersionRunPath))
|
||||
@@ -157,4 +158,29 @@ namespace PTSettingsHelper
|
||||
json::to_file(lastVersionRunPath.c_str(), obj);
|
||||
}
|
||||
|
||||
void save_data_diagnostics(bool enabled)
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||
DataDiagnosticsRegKey,
|
||||
0,
|
||||
nullptr,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
nullptr,
|
||||
&key,
|
||||
nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const bool value = enabled;
|
||||
const size_t buf_size = sizeof(bool);
|
||||
if (RegSetValueExW(key, DataDiagnosticsRegValueName, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&value), buf_size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,6 @@ namespace PTSettingsHelper
|
||||
void save_oobe_opened_state();
|
||||
std::wstring get_last_version_run();
|
||||
void save_last_version_run(const std::wstring& version);
|
||||
|
||||
void save_data_diagnostics(bool enabled);
|
||||
}
|
||||
|
||||
252
src/common/Telemetry/EtwTrace/EtwTrace.cpp
Normal file
252
src/common/Telemetry/EtwTrace/EtwTrace.cpp
Normal file
@@ -0,0 +1,252 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
#include "ETWTrace.h"
|
||||
|
||||
#include <wil\stl.h>
|
||||
#include <wil\win32_helpers.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr inline const wchar_t* DataDiagnosticsRegKey = L"Software\\Classes\\PowerToys";
|
||||
constexpr inline const wchar_t* ViewDataDiagnosticsRegValueName = L"DataDiagnosticsViewEnabled";
|
||||
|
||||
inline std::wstring get_root_save_folder_location()
|
||||
{
|
||||
PWSTR local_app_path;
|
||||
winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &local_app_path));
|
||||
std::wstring result{ local_app_path };
|
||||
CoTaskMemFree(local_app_path);
|
||||
|
||||
result += L"\\Microsoft\\PowerToys";
|
||||
std::filesystem::path save_path(result);
|
||||
if (!std::filesystem::exists(save_path))
|
||||
{
|
||||
std::filesystem::create_directories(save_path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isViewDataDiagnosticEnabled()
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
DataDiagnosticsRegKey,
|
||||
0,
|
||||
KEY_READ,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD isDataDiagnosticsEnabled = 0;
|
||||
DWORD size = sizeof(isDataDiagnosticsEnabled);
|
||||
|
||||
if (RegGetValueW(
|
||||
HKEY_CURRENT_USER,
|
||||
DataDiagnosticsRegKey,
|
||||
ViewDataDiagnosticsRegValueName,
|
||||
RRF_RT_REG_DWORD,
|
||||
nullptr,
|
||||
&isDataDiagnosticsEnabled,
|
||||
&size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
|
||||
return isDataDiagnosticsEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Shared
|
||||
{
|
||||
namespace Trace
|
||||
{
|
||||
ETWTrace::ETWTrace() :
|
||||
ETWTrace(PowerToysProviderGUID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ETWTrace::ETWTrace(const std::wstring& providerGUIDstr)
|
||||
{
|
||||
GUID id;
|
||||
if (SUCCEEDED(CLSIDFromString(providerGUIDstr.c_str(), &id)))
|
||||
{
|
||||
m_providerGUID = id;
|
||||
}
|
||||
|
||||
fs::path outputFolder = get_root_save_folder_location();
|
||||
m_etwFolder = (outputFolder / c_etwFolderName);
|
||||
}
|
||||
|
||||
ETWTrace::ETWTrace(const GUID& providerGUID) :
|
||||
m_providerGUID(providerGUID)
|
||||
{
|
||||
fs::path outputFolder = get_root_save_folder_location();
|
||||
m_etwFolder = (outputFolder / c_etwFolderName);
|
||||
}
|
||||
|
||||
ETWTrace::~ETWTrace()
|
||||
{
|
||||
Stop();
|
||||
m_etwFolder.clear();
|
||||
m_providerGUID = {};
|
||||
}
|
||||
|
||||
void ETWTrace::UpdateState(bool tracing)
|
||||
{
|
||||
if (tracing)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void ETWTrace::Flush()
|
||||
{
|
||||
if (m_tracing)
|
||||
{
|
||||
Control(EVENT_TRACE_CONTROL_FLUSH);
|
||||
Control(EVENT_TRACE_CONTROL_INCREMENT_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
void ETWTrace::CreateEtwFolderIfNeeded()
|
||||
{
|
||||
if (!std::filesystem::exists(m_etwFolder))
|
||||
{
|
||||
std::filesystem::create_directories(m_etwFolder);
|
||||
}
|
||||
else if (!std::filesystem::is_directory(m_etwFolder))
|
||||
{
|
||||
std::filesystem::remove(m_etwFolder);
|
||||
std::filesystem::create_directory(m_etwFolder);
|
||||
}
|
||||
|
||||
THROW_HR_IF(E_UNEXPECTED, !std::filesystem::exists(m_etwFolder));
|
||||
}
|
||||
|
||||
void ETWTrace::InitEventTraceProperties()
|
||||
{
|
||||
const std::filesystem::path exePath(wil::GetModuleFileNameW<std::wstring>(nullptr));
|
||||
const auto exeName = exePath.stem().wstring();
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto timeNow = std::chrono::system_clock::to_time_t(now);
|
||||
std::wstringstream dateTime;
|
||||
struct tm timeInfo
|
||||
{
|
||||
};
|
||||
errno_t err = localtime_s(&timeInfo, &timeNow);
|
||||
if (err == 0)
|
||||
{
|
||||
dateTime << std::put_time(&timeInfo, L"-%m-%d-%Y__%H_%M_%S");
|
||||
}
|
||||
|
||||
m_sessionName = wil::str_printf<std::wstring>(L"%ws-%d%ws", exeName.c_str(), GetCurrentProcessId(), dateTime.str().c_str());
|
||||
std::replace(m_sessionName.begin(), m_sessionName.end(), '.', '_');
|
||||
|
||||
const ULONG etwSessionNameCharCount = static_cast<ULONG>(m_sessionName.size() + 1);
|
||||
const ULONG etwSessionNameByteSize = etwSessionNameCharCount * sizeof(m_sessionName[0]);
|
||||
|
||||
auto etlFileNameFormattedCounter = m_sessionName + c_etwNewFileFormattedCounter;
|
||||
std::filesystem::path etlFilePath = m_etwFolder / etlFileNameFormattedCounter;
|
||||
etlFilePath.replace_extension(c_etwFileNameEnd);
|
||||
THROW_HR_IF(E_UNEXPECTED, etlFilePath.empty());
|
||||
|
||||
const auto etlFilePathStr = etlFilePath.wstring();
|
||||
// std::string/wstring returns number of characters not including the null terminator, so add +1 for that.
|
||||
const ULONG etwFilePathCharCount = static_cast<ULONG>(etlFilePathStr.size() + 1);
|
||||
const ULONG etwFilePathByteSize = etwFilePathCharCount * sizeof(etlFilePathStr[0]);
|
||||
|
||||
const ULONG bufferSizeInBytes = sizeof(EVENT_TRACE_PROPERTIES) + etwSessionNameByteSize + etwFilePathByteSize;
|
||||
auto eventTracePropertiesBuffer = std::make_unique<unsigned char[]>(bufferSizeInBytes);
|
||||
ZeroMemory(eventTracePropertiesBuffer.get(), bufferSizeInBytes);
|
||||
auto eventTraceProperties = reinterpret_cast<EVENT_TRACE_PROPERTIES*>(eventTracePropertiesBuffer.get());
|
||||
|
||||
eventTraceProperties->Wnode.BufferSize = bufferSizeInBytes;
|
||||
eventTraceProperties->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
|
||||
eventTraceProperties->Wnode.ClientContext = 1; // QPC clock resolution
|
||||
eventTraceProperties->Wnode.Guid = m_providerGUID;
|
||||
eventTraceProperties->BufferSize = 4; // 4KB, the minimum size
|
||||
eventTraceProperties->LogFileMode = EVENT_TRACE_PRIVATE_LOGGER_MODE | EVENT_TRACE_PRIVATE_IN_PROC | EVENT_TRACE_FILE_MODE_NEWFILE;
|
||||
eventTraceProperties->MaximumFileSize = 1; // 1 MB
|
||||
|
||||
// LoggerName is placed at the end of EVENT_TRACE_PROPERTIES structure
|
||||
eventTraceProperties->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
|
||||
wcsncpy_s(reinterpret_cast<LPWSTR>(eventTracePropertiesBuffer.get() + eventTraceProperties->LoggerNameOffset), etwSessionNameCharCount, m_sessionName.c_str(), etwSessionNameCharCount);
|
||||
|
||||
// LogFileName is placed at the end of the Logger Name
|
||||
eventTraceProperties->LogFileNameOffset = eventTraceProperties->LoggerNameOffset + etwSessionNameByteSize;
|
||||
wcsncpy_s(reinterpret_cast<LPWSTR>(eventTracePropertiesBuffer.get() + eventTraceProperties->LogFileNameOffset), etwFilePathCharCount, etlFilePathStr.c_str(), etwFilePathCharCount);
|
||||
|
||||
m_eventTracePropertiesBuffer = std::move(eventTracePropertiesBuffer);
|
||||
}
|
||||
|
||||
void ETWTrace::Start()
|
||||
{
|
||||
if (m_tracing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isViewDataDiagnosticEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CreateEtwFolderIfNeeded();
|
||||
InitEventTraceProperties();
|
||||
|
||||
auto eventTraceProperties = reinterpret_cast<EVENT_TRACE_PROPERTIES*>(m_eventTracePropertiesBuffer.get());
|
||||
THROW_IF_WIN32_ERROR(StartTrace(&m_traceHandle, m_sessionName.c_str(), eventTraceProperties));
|
||||
Enable(EVENT_CONTROL_CODE_ENABLE_PROVIDER);
|
||||
|
||||
m_tracing = true;
|
||||
}
|
||||
|
||||
void ETWTrace::Stop()
|
||||
{
|
||||
if (!m_tracing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Enable(EVENT_CONTROL_CODE_DISABLE_PROVIDER);
|
||||
|
||||
// ControlTrace with EVENT_TRACE_CONTROL_STOP on the trace handle,
|
||||
// which is equivalent to calling CloseTrace() on the trace handle.
|
||||
Control(EVENT_TRACE_CONTROL_STOP);
|
||||
|
||||
m_traceHandle = INVALID_PROCESSTRACE_HANDLE;
|
||||
m_eventTracePropertiesBuffer.reset();
|
||||
m_tracing = false;
|
||||
}
|
||||
|
||||
void ETWTrace::Control(ULONG traceControlCode)
|
||||
{
|
||||
auto eventTraceProperties = reinterpret_cast<EVENT_TRACE_PROPERTIES*>(m_eventTracePropertiesBuffer.get());
|
||||
const ULONG result = ControlTrace(m_traceHandle, m_sessionName.c_str(), eventTraceProperties, traceControlCode);
|
||||
THROW_IF_FAILED(HRESULT_FROM_WIN32(result));
|
||||
}
|
||||
|
||||
void ETWTrace::Enable(ULONG eventControlCode)
|
||||
{
|
||||
// Control the main provider
|
||||
THROW_IF_WIN32_ERROR(EnableTraceEx2(m_traceHandle, &m_providerGUID, eventControlCode, TRACE_LEVEL_VERBOSE, 0, 0, 0, nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/common/Telemetry/EtwTrace/EtwTrace.h
Normal file
48
src/common/Telemetry/EtwTrace/EtwTrace.h
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
#include <evntrace.h>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Shared
|
||||
{
|
||||
namespace Trace
|
||||
{
|
||||
class ETWTrace
|
||||
{
|
||||
public:
|
||||
static inline const wchar_t* PowerToysProviderGUID = L"{38e8889b-9731-53f5-e901-e8a7c1753074}";
|
||||
|
||||
ETWTrace();
|
||||
ETWTrace(const std::wstring& providerGUID);
|
||||
ETWTrace(const GUID& providerGUID);
|
||||
~ETWTrace();
|
||||
|
||||
void UpdateState(bool tracing);
|
||||
void Flush();
|
||||
|
||||
private:
|
||||
void CreateEtwFolderIfNeeded();
|
||||
void InitEventTraceProperties();
|
||||
void Start();
|
||||
void Stop();
|
||||
void Control(const ULONG traceControlCode);
|
||||
void Enable(const ULONG eventControlCode);
|
||||
|
||||
GUID m_providerGUID{};
|
||||
std::filesystem::path m_etwFolder;
|
||||
std::wstring m_sessionName;
|
||||
TRACEHANDLE m_traceHandle{ INVALID_PROCESSTRACE_HANDLE };
|
||||
std::unique_ptr<unsigned char[]> m_eventTracePropertiesBuffer;
|
||||
bool m_tracing{ false };
|
||||
|
||||
static constexpr PCWSTR c_etwFolderName = L"etw";
|
||||
static constexpr PCWSTR c_etwNewFileFormattedCounter = L"-%d";
|
||||
static constexpr PCWSTR c_etwFileNameEnd = L".etl";
|
||||
};
|
||||
}
|
||||
}
|
||||
51
src/common/Telemetry/EtwTrace/EtwTrace.vcxproj
Normal file
51
src/common/Telemetry/EtwTrace/EtwTrace.vcxproj
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build"
|
||||
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{8f021b46-362b-485c-bfba-ccf83e820cbd}</ProjectGuid>
|
||||
<RootNamespace>EtwTrace</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<ClInclude Include="EtwTrace.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EtwTrace.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
39
src/common/Telemetry/EtwTrace/EtwTrace.vcxproj.filters
Normal file
39
src/common/Telemetry/EtwTrace/EtwTrace.vcxproj.filters
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EtwTrace.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EtwTrace.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
5
src/common/Telemetry/EtwTrace/packages.config
Normal file
5
src/common/Telemetry/EtwTrace/packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" />
|
||||
</packages>
|
||||
5
src/common/Telemetry/EtwTrace/pch.cpp
Normal file
5
src/common/Telemetry/EtwTrace/pch.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// pch.cpp: source file corresponding to the pre-compiled header
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
|
||||
23
src/common/Telemetry/EtwTrace/pch.h
Normal file
23
src/common/Telemetry/EtwTrace/pch.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <ShlObj.h>
|
||||
#include <sstream>
|
||||
#include <strsafe.h>
|
||||
|
||||
#include <winrt/base.h>
|
||||
|
||||
#endif //PCH_H
|
||||
63
src/common/Telemetry/TraceBase.h
Normal file
63
src/common/Telemetry/TraceBase.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "ProjectTelemetry.h"
|
||||
|
||||
#define TraceLoggingWriteWrapper(provider, eventName, ...) \
|
||||
if (IsDataDiagnosticsEnabled()) \
|
||||
{ \
|
||||
TraceLoggingWrite(provider, eventName, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
namespace telemetry
|
||||
{
|
||||
|
||||
constexpr inline const wchar_t* DataDiagnosticsRegKey = L"Software\\Classes\\PowerToys";
|
||||
constexpr inline const wchar_t* DataDiagnosticsRegValueName = L"AllowDataDiagnostics";
|
||||
|
||||
class TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider()
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
static void UnregisterProvider()
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
static bool IsDataDiagnosticsEnabled()
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
DataDiagnosticsRegKey,
|
||||
0,
|
||||
KEY_READ,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD isDataDiagnosticsEnabled = 0;
|
||||
DWORD size = sizeof(isDataDiagnosticsEnabled);
|
||||
|
||||
if (RegGetValueW(
|
||||
HKEY_CURRENT_USER,
|
||||
DataDiagnosticsRegKey,
|
||||
DataDiagnosticsRegValueName,
|
||||
RRF_RT_REG_DWORD,
|
||||
nullptr,
|
||||
&isDataDiagnosticsEnabled,
|
||||
&size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
|
||||
return isDataDiagnosticsEnabled;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace telemetry
|
||||
@@ -4,3 +4,4 @@
|
||||
#define ProjectTelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "Ignore")
|
||||
#define ProjectTelemetryTag_ProductAndServicePerformance 0x0u
|
||||
#define PROJECT_KEYWORD_MEASURE 0x0
|
||||
#define MICROSOFT_EVENTTAG_DROP_PII 0x02000000
|
||||
@@ -51,6 +51,10 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::TerminateColorPickerSharedEvent()
|
||||
{
|
||||
return CommonSharedConstants::TERMINATE_COLOR_PICKER_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::AdvancedPasteShowUIMessage()
|
||||
{
|
||||
return CommonSharedConstants::ADVANCED_PASTE_SHOW_UI_MESSAGE;
|
||||
@@ -67,10 +71,18 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::ADVANCED_PASTE_CUSTOM_ACTION_MESSAGE;
|
||||
}
|
||||
hstring Constants::AdvancedPasteTerminateAppMessage()
|
||||
{
|
||||
return CommonSharedConstants::ADVANCED_PASTE_TERMINATE_APP_MESSAGE;
|
||||
}
|
||||
hstring Constants::ShowPowerOCRSharedEvent()
|
||||
{
|
||||
return CommonSharedConstants::SHOW_POWEROCR_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::TerminatePowerOCRSharedEvent()
|
||||
{
|
||||
return CommonSharedConstants::TERMINATE_POWEROCR_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::MouseJumpShowPreviewEvent()
|
||||
{
|
||||
return CommonSharedConstants::MOUSE_JUMP_SHOW_PREVIEW_EVENT;
|
||||
@@ -83,6 +95,10 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::SHOW_PEEK_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::TerminatePeekEvent()
|
||||
{
|
||||
return CommonSharedConstants::TERMINATE_PEEK_SHARED_EVENT;
|
||||
}
|
||||
hstring Constants::PowerAccentExitEvent()
|
||||
{
|
||||
return CommonSharedConstants::POWERACCENT_EXIT_EVENT;
|
||||
@@ -131,6 +147,10 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT;
|
||||
}
|
||||
hstring Constants::TerminateHostsSharedEvent()
|
||||
{
|
||||
return CommonSharedConstants::TERMINATE_HOSTS_EVENT;
|
||||
}
|
||||
hstring Constants::CropAndLockThumbnailEvent()
|
||||
{
|
||||
return CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT;
|
||||
@@ -155,4 +175,8 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::WORKSPACES_HOTKEY_EVENT;
|
||||
}
|
||||
hstring Constants::PowerToysRunnerTerminateSettingsEvent()
|
||||
{
|
||||
return CommonSharedConstants::TERMINATE_SETTINGS_SHARED_EVENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,18 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
static hstring FZEToggleEvent();
|
||||
static hstring ColorPickerSendSettingsTelemetryEvent();
|
||||
static hstring ShowColorPickerSharedEvent();
|
||||
static hstring TerminateColorPickerSharedEvent();
|
||||
static hstring AdvancedPasteShowUIMessage();
|
||||
static hstring AdvancedPasteMarkdownMessage();
|
||||
static hstring AdvancedPasteJsonMessage();
|
||||
static hstring AdvancedPasteCustomActionMessage();
|
||||
static hstring AdvancedPasteTerminateAppMessage();
|
||||
static hstring ShowPowerOCRSharedEvent();
|
||||
static hstring TerminatePowerOCRSharedEvent();
|
||||
static hstring MouseJumpShowPreviewEvent();
|
||||
static hstring AwakeExitEvent();
|
||||
static hstring ShowPeekEvent();
|
||||
static hstring TerminatePeekEvent();
|
||||
static hstring PowerAccentExitEvent();
|
||||
static hstring ShortcutGuideTriggerEvent();
|
||||
static hstring RegistryPreviewTriggerEvent();
|
||||
@@ -36,12 +40,14 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
static hstring SvgPreviewResizeEvent();
|
||||
static hstring ShowHostsSharedEvent();
|
||||
static hstring ShowHostsAdminSharedEvent();
|
||||
static hstring TerminateHostsSharedEvent();
|
||||
static hstring CropAndLockThumbnailEvent();
|
||||
static hstring CropAndLockReparentEvent();
|
||||
static hstring ShowEnvironmentVariablesSharedEvent();
|
||||
static hstring ShowEnvironmentVariablesAdminSharedEvent();
|
||||
static hstring WorkspacesLaunchEditorEvent();
|
||||
static hstring WorkspacesHotkeyEvent();
|
||||
static hstring PowerToysRunnerTerminateSettingsEvent();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,18 @@ namespace PowerToys
|
||||
static String FZEToggleEvent();
|
||||
static String ColorPickerSendSettingsTelemetryEvent();
|
||||
static String ShowColorPickerSharedEvent();
|
||||
static String TerminateColorPickerSharedEvent();
|
||||
static String AdvancedPasteShowUIMessage();
|
||||
static String AdvancedPasteMarkdownMessage();
|
||||
static String AdvancedPasteJsonMessage();
|
||||
static String AdvancedPasteCustomActionMessage();
|
||||
static String AdvancedPasteTerminateAppMessage();
|
||||
static String ShowPowerOCRSharedEvent();
|
||||
static String TerminatePowerOCRSharedEvent();
|
||||
static String MouseJumpShowPreviewEvent();
|
||||
static String AwakeExitEvent();
|
||||
static String ShowPeekEvent();
|
||||
static String TerminatePeekEvent();
|
||||
static String PowerAccentExitEvent();
|
||||
static String ShortcutGuideTriggerEvent();
|
||||
static String RegistryPreviewTriggerEvent();
|
||||
@@ -33,12 +37,14 @@ namespace PowerToys
|
||||
static String SvgPreviewResizeEvent();
|
||||
static String ShowHostsSharedEvent();
|
||||
static String ShowHostsAdminSharedEvent();
|
||||
static String TerminateHostsSharedEvent();
|
||||
static String CropAndLockThumbnailEvent();
|
||||
static String CropAndLockReparentEvent();
|
||||
static String ShowEnvironmentVariablesSharedEvent();
|
||||
static String ShowEnvironmentVariablesAdminSharedEvent();
|
||||
static String WorkspacesLaunchEditorEvent();
|
||||
static String WorkspacesHotkeyEvent();
|
||||
static String PowerToysRunnerTerminateSettingsEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ namespace CommonSharedConstants
|
||||
|
||||
const wchar_t APPDATA_PATH[] = L"Microsoft\\PowerToys";
|
||||
|
||||
// Path to the event used by runner to terminate Settings app
|
||||
const wchar_t TERMINATE_SETTINGS_SHARED_EVENT[] = L"Local\\PowerToysRunnerTerminateSettingsEvent-c34cb661-2e69-4613-a1f8-4e39c25d7ef6";
|
||||
|
||||
// Path to the event used by PowerLauncher
|
||||
const wchar_t POWER_LAUNCHER_SHARED_EVENT[] = L"Local\\PowerToysRunInvokeEvent-30f26ad7-d36d-4c0e-ab02-68bb5ff3c4ab";
|
||||
|
||||
@@ -34,9 +37,13 @@ namespace CommonSharedConstants
|
||||
|
||||
const wchar_t ADVANCED_PASTE_CUSTOM_ACTION_MESSAGE[] = L"CustomAction";
|
||||
|
||||
const wchar_t ADVANCED_PASTE_TERMINATE_APP_MESSAGE[] = L"TerminateApp";
|
||||
|
||||
// Path to the event used to show Color Picker
|
||||
const wchar_t SHOW_COLOR_PICKER_SHARED_EVENT[] = L"Local\\ShowColorPickerEvent-8c46be2a-3e05-4186-b56b-4ae986ef2525";
|
||||
|
||||
const wchar_t TERMINATE_COLOR_PICKER_SHARED_EVENT[] = L"Local\\TerminateColorPickerEvent-3d676258-c4d5-424e-a87a-4be22020e813";
|
||||
|
||||
const wchar_t SHORTCUT_GUIDE_TRIGGER_EVENT[] = L"Local\\ShortcutGuide-TriggerEvent-d4275ad3-2531-4d19-9252-c0becbd9b496";
|
||||
|
||||
const wchar_t SHORTCUT_GUIDE_EXIT_EVENT[] = L"Local\\ShortcutGuide-ExitEvent-35697cdd-a3d2-47d6-a246-34efcc73eac0";
|
||||
@@ -51,18 +58,24 @@ namespace CommonSharedConstants
|
||||
|
||||
const wchar_t SHOW_HOSTS_ADMIN_EVENT[] = L"Local\\Hosts-ShowHostsAdminEvent-60ff44e2-efd3-43bf-928a-f4d269f98bec";
|
||||
|
||||
const wchar_t TERMINATE_HOSTS_EVENT[] = L"Local\\Hosts-TerminateHostsEvent-d5410d5e-45a6-4d11-bbf0-a4ec2d064888";
|
||||
|
||||
// Path to the event used by Awake
|
||||
const wchar_t AWAKE_EXIT_EVENT[] = L"Local\\PowerToysAwakeExitEvent-c0d5e305-35fc-4fb5-83ec-f6070cfaf7fe";
|
||||
|
||||
// Path to the event used by AlwaysOnTop
|
||||
const wchar_t ALWAYS_ON_TOP_PIN_EVENT[] = L"Local\\AlwaysOnTopPinEvent-892e0aa2-cfa8-4cc4-b196-ddeb32314ce8";
|
||||
|
||||
const wchar_t ALWAYS_ON_TOP_TERMINATE_EVENT[] = L"Local\\AlwaysOnTopTerminateEvent-cfdf1eae-791f-4953-8021-2f18f3837eae";
|
||||
|
||||
// Path to the event used by PowerAccent
|
||||
const wchar_t POWERACCENT_EXIT_EVENT[] = L"Local\\PowerToysPowerAccentExitEvent-53e93389-d19a-4fbb-9b36-1981c8965e17";
|
||||
|
||||
// Path to the event used by PowerOCR
|
||||
const wchar_t SHOW_POWEROCR_SHARED_EVENT[] = L"Local\\PowerOCREvent-dc864e06-e1af-4ecc-9078-f98bee745e3a";
|
||||
|
||||
const wchar_t TERMINATE_POWEROCR_SHARED_EVENT[] = L"Local\\TerminatePowerOCREvent-08e5de9d-15df-4ea8-8840-487c13435a67";
|
||||
|
||||
// Path to the events used by Mouse Jump
|
||||
const wchar_t MOUSE_JUMP_SHOW_PREVIEW_EVENT[] = L"Local\\MouseJumpEvent-aa0be051-3396-4976-b7ba-1a9cc7d236a5";
|
||||
|
||||
@@ -92,6 +105,11 @@ namespace CommonSharedConstants
|
||||
|
||||
// Path to the event used to show Peek
|
||||
const wchar_t SHOW_PEEK_SHARED_EVENT[] = L"Local\\ShowPeekEvent";
|
||||
// Path to the event used to terminate Peek
|
||||
const wchar_t TERMINATE_PEEK_SHARED_EVENT[] = L"Local\\TerminatePeekEvent-267149fe-7ed2-427d-a3ad-9e18203c037c";
|
||||
|
||||
// Path to the event used to terminate KBM
|
||||
const wchar_t TERMINATE_KBM_SHARED_EVENT[] = L"Local\\TerminateKBMSharedEvent-a787c967-55b6-47de-94d9-56f39fed839e";
|
||||
|
||||
// Path to the events used by CropAndLock
|
||||
const wchar_t CROP_AND_LOCK_REPARENT_EVENT[] = L"Local\\PowerToysCropAndLockReparentEvent-6060860a-76a1-44e8-8d0e-6355785e9c36";
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace powertoys_gpo {
|
||||
|
||||
// The registry value names for other PowerToys policies.
|
||||
const std::wstring POLICY_ALLOW_EXPERIMENTATION = L"AllowExperimentation";
|
||||
const std::wstring POLICY_ALLOW_DATA_DIAGNOSTICS = L"AllowDataDiagnostics";
|
||||
const std::wstring POLICY_CONFIGURE_ENABLED_POWER_LAUNCHER_ALL_PLUGINS = L"PowerLauncherAllPluginsEnabledState";
|
||||
const std::wstring POLICY_ALLOW_ADVANCED_PASTE_ONLINE_AI_MODELS = L"AllowPowerToysAdvancedPasteOnlineAIModels";
|
||||
const std::wstring POLICY_MWB_CLIPBOARD_SHARING_ENABLED = L"MwbClipboardSharingEnabled";
|
||||
@@ -487,6 +488,11 @@ namespace powertoys_gpo {
|
||||
return getConfiguredValue(POLICY_ALLOW_EXPERIMENTATION);
|
||||
}
|
||||
|
||||
inline gpo_rule_configured_t getAllowDataDiagnosticsValue()
|
||||
{
|
||||
return getConfiguredValue(POLICY_ALLOW_DATA_DIAGNOSTICS);
|
||||
}
|
||||
|
||||
inline gpo_rule_configured_t getRunPluginEnabledValue(std::string pluginID)
|
||||
{
|
||||
if (pluginID == "" || pluginID == " ")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<policyNamespaces>
|
||||
<target prefix="powertoys" namespace="Microsoft.Policies.PowerToys" />
|
||||
</policyNamespaces>
|
||||
<resources minRequiredRevision="1.13"/><!-- Last changed with PowerToys v0.85.0 -->
|
||||
<resources minRequiredRevision="1.14"/><!-- Last changed with PowerToys v0.86.0 -->
|
||||
<supportedOn>
|
||||
<definitions>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_64_0" displayName="$(string.SUPPORTED_POWERTOYS_0_64_0)"/>
|
||||
@@ -22,6 +22,7 @@
|
||||
<definition name="SUPPORTED_POWERTOYS_0_83_0" displayName="$(string.SUPPORTED_POWERTOYS_0_83_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_84_0" displayName="$(string.SUPPORTED_POWERTOYS_0_84_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_85_0" displayName="$(string.SUPPORTED_POWERTOYS_0_85_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_86_0" displayName="$(string.SUPPORTED_POWERTOYS_0_86_0)"/>
|
||||
</definitions>
|
||||
</supportedOn>
|
||||
<categories>
|
||||
@@ -509,6 +510,16 @@
|
||||
<decimal value="0" />
|
||||
</disabledValue>
|
||||
</policy>
|
||||
<policy name="AllowDiagnosticData" class="Both" displayName="$(string.AllowDiagnosticData)" explainText="$(string.AllowDiagnosticDataDescription)" key="Software\Policies\PowerToys" valueName="AllowDataDiagnostics">
|
||||
<parentCategory ref="GeneralSettings" />
|
||||
<supportedOn ref="SUPPORTED_POWERTOYS_0_86_0" />
|
||||
<enabledValue>
|
||||
<decimal value="1" />
|
||||
</enabledValue>
|
||||
<disabledValue>
|
||||
<decimal value="0" />
|
||||
</disabledValue>
|
||||
</policy>
|
||||
<policy name="PowerToysRunAllPluginsEnabledState" class="Both" displayName="$(string.PowerToysRunAllPluginsEnabledState)" explainText="$(string.PowerToysRunAllPluginsEnabledStateDescription)" key="Software\Policies\PowerToys" valueName="PowerLauncherAllPluginsEnabledState">
|
||||
<parentCategory ref="PowerToysRun" />
|
||||
<supportedOn ref="SUPPORTED_POWERTOYS_0_75_0" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) Microsoft Corporation.
|
||||
Licensed under the MIT License. -->
|
||||
<policyDefinitionResources xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.13" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
|
||||
<policyDefinitionResources xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.14" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
|
||||
<displayName>PowerToys</displayName>
|
||||
<description>PowerToys</description>
|
||||
<resources>
|
||||
@@ -28,6 +28,7 @@
|
||||
<string id="SUPPORTED_POWERTOYS_0_83_0">PowerToys version 0.83.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_84_0">PowerToys version 0.84.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_85_0">PowerToys version 0.85.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_86_0">PowerToys version 0.86.0 or later</string>
|
||||
|
||||
<string id="ConfigureAllUtilityGlobalEnabledStateDescription">This policy configures the enabled state for all PowerToys utilities.
|
||||
|
||||
@@ -101,6 +102,12 @@ If disabled or not configured, the user can control this in the settings of Powe
|
||||
If this setting is enabled or not configured, the user can control experimentation in the PowerToys settings menu.
|
||||
|
||||
If this setting is disabled, experimentation is not allowed.
|
||||
</string>
|
||||
<string id="AllowDiagnosticDataDescription">This policy configures whether sending of PowerToys diagnostic data is allowed. With diagnostic data sending allowed the user helps inform bug fixes, performance and improvements.
|
||||
|
||||
If this setting is enabled or not configured, the user can control diagnostic data sending in the PowerToys settings menu.
|
||||
|
||||
If this setting is disabled, diagnostic data sending is not allowed.
|
||||
</string>
|
||||
<string id="PowerToysRunAllPluginsEnabledStateDescription">This policy configures the enabled state for all PowerToys Run plugins. All plugins will have the same state.
|
||||
|
||||
@@ -258,6 +265,8 @@ If you don't configure this policy, the user takes control over the setting and
|
||||
<string id="MwbDisableUserDefinedIpMappingRules">Disable user defined IP Address mapping rules</string>
|
||||
<string id="MwbPolicyDefinedIpMappingRules">Predefined IP Address mapping rules</string>
|
||||
<string id="NewPlusHideTemplateFilenameExtension">Hide template filename extension</string>
|
||||
<string id="AllowPowerToysAdvancedPasteOnlineAIModels">Advanced Paste: Allow using online AI models</string>
|
||||
<string id="AllowDiagnosticData">Allow sending diagnostic data</string>
|
||||
</stringTable>
|
||||
|
||||
<presentationTable>
|
||||
|
||||
@@ -14,6 +14,7 @@ using AdvancedPaste.ViewModels;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Windows.Graphics;
|
||||
@@ -34,6 +35,8 @@ namespace AdvancedPaste
|
||||
{
|
||||
public IHost Host { get; private set; }
|
||||
|
||||
public ETWTrace EtwTrace { get; private set; } = new ETWTrace();
|
||||
|
||||
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
private readonly OptionsViewModel viewModel;
|
||||
|
||||
@@ -58,6 +61,8 @@ namespace AdvancedPaste
|
||||
|
||||
this.InitializeComponent();
|
||||
|
||||
EtwTrace.Start();
|
||||
|
||||
Host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder().UseContentRoot(AppContext.BaseDirectory).ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddSingleton<OptionsViewModel>();
|
||||
@@ -98,6 +103,7 @@ namespace AdvancedPaste
|
||||
{
|
||||
RunnerHelper.WaitForPowerToysRunner(powerToysRunnerPid, () =>
|
||||
{
|
||||
Dispose();
|
||||
Environment.Exit(0);
|
||||
});
|
||||
}
|
||||
@@ -141,6 +147,11 @@ namespace AdvancedPaste
|
||||
{
|
||||
OnAdvancedPasteCustomActionHotkey(messageParts);
|
||||
}
|
||||
else if (messageType == PowerToys.Interop.Constants.AdvancedPasteTerminateAppMessage())
|
||||
{
|
||||
Dispose();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
||||
@@ -229,6 +240,7 @@ namespace AdvancedPaste
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
EtwTrace?.Dispose();
|
||||
window.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using AdvancedPaste.Helpers;
|
||||
using AdvancedPaste.Settings;
|
||||
using AdvancedPaste.ViewModels;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using WinUIEx;
|
||||
@@ -85,6 +86,7 @@ namespace AdvancedPaste
|
||||
if (!_disposedValue)
|
||||
{
|
||||
_msgMonitor?.Dispose();
|
||||
(Application.Current as App).EtwTrace?.Dispose();
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
|
||||
@@ -763,6 +763,9 @@ public:
|
||||
Logger::trace("AdvancedPaste::disable()");
|
||||
if (m_enabled)
|
||||
{
|
||||
send_named_pipe_message(CommonSharedConstants::ADVANCED_PASTE_TERMINATE_APP_MESSAGE);
|
||||
WaitForSingleObject(m_hProcess, 1000);
|
||||
|
||||
m_write_pipe = nullptr;
|
||||
|
||||
TerminateProcess(m_hProcess, 1);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <windows.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <shellapi.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <filesystem>
|
||||
@@ -8,46 +8,39 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider()
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider()
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has AdvancedPaste enabled or disabled
|
||||
void Trace::AdvancedPaste_Enable(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"AdvancedPaste_EnableAdvancedPaste",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log if the user has invoked AdvancedPaste
|
||||
void Trace::AdvancedPaste_Invoked(std::wstring mode) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"AdvancedPaste_InvokeAdvancedPaste",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingValue(mode.c_str(), "Mode"));
|
||||
}
|
||||
|
||||
// Log if an error occurs in AdvancedPaste
|
||||
void Trace::AdvancedPaste_Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"AdvancedPaste_Error",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingValue(methodName.c_str(), "MethodName"),
|
||||
TraceLoggingValue(errorCode, "ErrorCode"),
|
||||
TraceLoggingValue(errorMessage.c_str(), "ErrorMessage"));
|
||||
@@ -88,15 +81,15 @@ void Trace::AdvancedPaste_SettingsTelemetry(const PowertoyModuleIface::Hotkey& p
|
||||
std::wstring(pasteJsonHotkey.alt ? L"Alt + " : L"") +
|
||||
std::wstring(L"VK ") + std::to_wstring(pasteJsonHotkey.key);
|
||||
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"AdvancedPaste_Settings",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingWideString(pastePlainHotkeyStr.c_str(), "PastePlainHotkey"),
|
||||
TraceLoggingWideString(advancedPasteUIHotkeyStr.c_str(), "AdvancedPasteUIHotkey"),
|
||||
TraceLoggingWideString(pasteMarkdownHotkeyStr.c_str(), "PasteMarkdownHotkey"),
|
||||
TraceLoggingWideString(pasteJsonHotkeyStr.c_str(), "PasteJsonHotkey"),
|
||||
TraceLoggingBoolean(preview_custom_format_output, "ShowCustomPreview")
|
||||
);
|
||||
TraceLoggingBoolean(preview_custom_format_output, "ShowCustomPreview"));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
#pragma once
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
#include <interface/powertoy_module_interface.h>
|
||||
|
||||
class Trace
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider();
|
||||
static void UnregisterProvider();
|
||||
|
||||
// Log if the user has AdvancedPaste enabled or disabled
|
||||
static void AdvancedPaste_Enable(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -151,6 +151,9 @@
|
||||
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
||||
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\common\Telemetry\EtwTrace\EtwTrace.vcxproj">
|
||||
<Project>{8f021b46-362b-485c-bfba-ccf83e820cbd}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<Import Project="..\..\..\..\deps\spdlog.props" />
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<ClInclude Include="ChildWindow.h" />
|
||||
<ClInclude Include="trace.h" />
|
||||
<ClInclude Include="ModuleConstants.h" />
|
||||
<ClInclude Include="DispatcherQueue.desktop.interop.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="CropAndLock.rc" />
|
||||
|
||||
@@ -4,15 +4,19 @@
|
||||
#include "CropAndLockWindow.h"
|
||||
#include "ThumbnailCropAndLockWindow.h"
|
||||
#include "ReparentCropAndLockWindow.h"
|
||||
#include <common/interop/shared_constants.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
#include <common/utils/UnhandledExceptionHandler.h>
|
||||
#include <common/utils/gpo.h>
|
||||
#include "ModuleConstants.h"
|
||||
#include <common/utils/ProcessWaiter.h>
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/interop/shared_constants.h>
|
||||
|
||||
#include <common/utils/gpo.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
#include <common/utils/ProcessWaiter.h>
|
||||
#include <common/utils/UnhandledExceptionHandler.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
#include <common/Telemetry/EtwTrace/EtwTrace.h>
|
||||
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
|
||||
namespace winrt
|
||||
@@ -36,6 +40,9 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
// Initialize COM
|
||||
winrt::init_apartment(winrt::apartment_type::single_threaded);
|
||||
|
||||
Shared::Trace::ETWTrace trace;
|
||||
trace.UpdateState(true);
|
||||
|
||||
// Initialize logger automatic logging of exceptions.
|
||||
LoggerHelpers::init_logger(NonLocalizable::ModuleKey, L"", LogSettings::cropAndLockLoggerName);
|
||||
InitUnhandledExceptionHandler();
|
||||
@@ -153,6 +160,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
croppedWindow = std::make_shared<ThumbnailCropAndLockWindow>(title, 800, 600);
|
||||
Logger::trace(L"Creating a thumbnail window");
|
||||
Trace::CropAndLock::CreateThumbnailWindow();
|
||||
Trace::CropAndLock::ActivateThumbnail();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -195,6 +203,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
}
|
||||
|
||||
m_event_triggers_thread = std::thread([&]() {
|
||||
|
||||
MSG msg;
|
||||
HANDLE event_handles[3] = {m_reparent_event_handle, m_thumbnail_event_handle, m_exit_event_handle};
|
||||
while (m_running)
|
||||
@@ -258,6 +267,8 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
trace.Flush();
|
||||
|
||||
m_running = false;
|
||||
// Needed to unblock MsgWaitForMultipleObjects one last time
|
||||
SetEvent(m_reparent_event_handle);
|
||||
|
||||
@@ -74,7 +74,6 @@
|
||||
#include "WindowRectUtil.h"
|
||||
|
||||
// PowerToys
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
// Application resources
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
// Telemetry strings should not be localized.
|
||||
#define LoggingProviderKey "Microsoft.PowerToys"
|
||||
|
||||
@@ -11,60 +13,55 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::CropAndLock::Enable(bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_EnableCropAndLock",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
void Trace::CropAndLock::ActivateReparent() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_ActivateReparent",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::CropAndLock::ActivateThumbnail() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_ActivateThumbnail",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::CropAndLock::CreateReparentWindow() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_CreateReparentWindow",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::CropAndLock::CreateThumbnailWindow() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_CreateThumbnailWindow",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
// Event to send settings telemetry.
|
||||
@@ -84,12 +81,12 @@ void Trace::CropAndLock::SettingsTelemetry(PowertoyModuleIface::Hotkey& reparent
|
||||
std::wstring(thumbnailHotkey.alt ? L"Alt + " : L"") +
|
||||
std::wstring(L"VK ") + std::to_wstring(thumbnailHotkey.key);
|
||||
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"CropAndLock_Settings",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingWideString(hotKeyStrReparent.c_str(), "ReparentHotKey"),
|
||||
TraceLoggingWideString(hotKeyStrThumbnail.c_str(), "ThumbnailHotkey")
|
||||
);
|
||||
TraceLoggingWideString(hotKeyStrThumbnail.c_str(), "ThumbnailHotkey"));
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
#include <modules/interface/powertoy_module_interface.h>
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
class CropAndLock
|
||||
class CropAndLock : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void Enable(bool enabled) noexcept;
|
||||
|
||||
@@ -40,13 +40,13 @@ BOOL APIENTRY DllMain( HMODULE /*hModule*/,
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
Trace::RegisterProvider();
|
||||
Trace::CropAndLock::RegisterProvider();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
Trace::UnregisterProvider();
|
||||
Trace::CropAndLock::UnregisterProvider();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -6,7 +6,5 @@
|
||||
#include <winrt/base.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <TraceLoggingActivity.h>
|
||||
#include <wil\common.h>
|
||||
#include <wil\result.h>
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace EnvironmentVariables
|
||||
{
|
||||
public IHost Host { get; }
|
||||
|
||||
public ETWTrace EtwTrace { get; } = new ETWTrace();
|
||||
|
||||
public static T GetService<T>()
|
||||
where T : class
|
||||
{
|
||||
@@ -78,6 +80,8 @@ namespace EnvironmentVariables
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
||||
{
|
||||
EtwTrace.Start();
|
||||
|
||||
var cmdArgs = Environment.GetCommandLineArgs();
|
||||
if (cmdArgs?.Length > 1)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
x:Uid="Window"
|
||||
MinWidth="700"
|
||||
MinHeight="480"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
Closed="Window_Closed">
|
||||
<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
|
||||
@@ -88,5 +88,10 @@ namespace EnvironmentVariables
|
||||
|
||||
return NativeMethods.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, WindowEventArgs args)
|
||||
{
|
||||
(App.Current as EnvironmentVariables.App).EtwTrace?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files
|
||||
#include <windows.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,33 +10,25 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has Environment Variables enabled or disabled
|
||||
void Trace::EnableEnvironmentVariables(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"EnvironmentVariables_EnableEnvironmentVariables",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log that the user tried to activate the editor
|
||||
void Trace::ActivateEnvironmentVariables() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"EnvironmentVariables_Activate",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
// Log if the user has EnvironmentVariables enabled or disabled
|
||||
static void EnableEnvironmentVariables(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="4.0"
|
||||
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "Trace.h"
|
||||
#include "../common/Telemetry/ProjectTelemetry.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
@@ -10,51 +11,45 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::EnableFileLocksmith(_In_ bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FileLocksmith_EnableFileLocksmith",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
void Trace::Invoked() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FileLocksmith_Invoked",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::InvokedRet(_In_ HRESULT hr) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FileLocksmith_InvokedRet",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingHResult(hr),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::QueryContextMenuError(_In_ HRESULT hr) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FileLocksmith_QueryContextMenuError",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingHResult(hr),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
static void EnableFileLocksmith(_In_ bool enabled) noexcept;
|
||||
static void Invoked() noexcept;
|
||||
static void InvokedRet(_In_ HRESULT hr) noexcept;
|
||||
|
||||
30
src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs
Normal file
30
src/modules/Hosts/Hosts/Helpers/NativeEventWaiter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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;
|
||||
using System.Threading;
|
||||
|
||||
using Microsoft.UI.Dispatching;
|
||||
|
||||
namespace Hosts.Helpers
|
||||
{
|
||||
public static class NativeEventWaiter
|
||||
{
|
||||
public static void WaitForEventLoop(string eventName, Action callback)
|
||||
{
|
||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
new Thread(() =>
|
||||
{
|
||||
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
|
||||
while (true)
|
||||
{
|
||||
if (eventHandle.WaitOne())
|
||||
{
|
||||
dispatcherQueue.TryEnqueue(() => callback());
|
||||
}
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
using PowerToys.Interop;
|
||||
using static HostsUILib.Settings.IUserSettings;
|
||||
|
||||
using Host = Hosts.Helpers.Host;
|
||||
@@ -93,6 +93,12 @@ namespace Hosts
|
||||
cleanupBackupThread.Start();
|
||||
|
||||
UnhandledException += App_UnhandledException;
|
||||
|
||||
Hosts.Helpers.NativeEventWaiter.WaitForEventLoop(Constants.TerminateHostsSharedEvent(), () =>
|
||||
{
|
||||
EtwTrace?.Dispose();
|
||||
Environment.Exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,6 +107,8 @@ namespace Hosts
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
EtwTrace.Start();
|
||||
|
||||
var cmdArgs = Environment.GetCommandLineArgs();
|
||||
if (cmdArgs?.Length > 1)
|
||||
{
|
||||
@@ -112,6 +120,7 @@ namespace Hosts
|
||||
RunnerHelper.WaitForPowerToysRunner(powerToysRunnerPid, () =>
|
||||
{
|
||||
Logger.LogInfo("PowerToys Runner exited. Exiting Hosts");
|
||||
EtwTrace?.Dispose();
|
||||
dispatcher.TryEnqueue(App.Current.Exit);
|
||||
});
|
||||
}
|
||||
@@ -133,5 +142,7 @@ namespace Hosts
|
||||
}
|
||||
|
||||
private Window window;
|
||||
|
||||
public ETWTrace EtwTrace { get; private set; } = new ETWTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
Width="680"
|
||||
MinWidth="520"
|
||||
MinHeight="320"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
Closed="WindowEx_Closed">
|
||||
<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
|
||||
@@ -62,5 +62,10 @@ namespace Hosts
|
||||
MainGrid.Children.Add(MainPage);
|
||||
Grid.SetRow(MainPage, 1);
|
||||
}
|
||||
|
||||
private void WindowEx_Closed(object sender, WindowEventArgs args)
|
||||
{
|
||||
(Application.Current as App).EtwTrace?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ private:
|
||||
|
||||
HANDLE m_hShowAdminEvent{};
|
||||
|
||||
HANDLE m_hTerminateEvent{};
|
||||
|
||||
bool is_process_running()
|
||||
{
|
||||
return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT;
|
||||
@@ -142,6 +144,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
m_hTerminateEvent = CreateDefaultEvent(CommonSharedConstants::TERMINATE_HOSTS_EVENT);
|
||||
if (!m_hTerminateEvent)
|
||||
{
|
||||
Logger::error(L"Failed to create terminate hosts event");
|
||||
auto message = get_last_error_message(GetLastError());
|
||||
if (message.has_value())
|
||||
{
|
||||
Logger::error(message.value());
|
||||
}
|
||||
}
|
||||
|
||||
m_showEventWaiter = EventWaiter(CommonSharedConstants::SHOW_HOSTS_EVENT, [&](int err)
|
||||
{
|
||||
if (m_enabled && err == ERROR_SUCCESS)
|
||||
@@ -264,6 +277,8 @@ public:
|
||||
ResetEvent(m_hShowAdminEvent);
|
||||
}
|
||||
|
||||
SetEvent(m_hTerminateEvent);
|
||||
WaitForSingleObject(m_hProcess, 1000);
|
||||
TerminateProcess(m_hProcess, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,33 +10,25 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has HostsFileEditor enabled or disabled
|
||||
void Trace::EnableHostsFileEditor(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"HostsFileEditor_EnableHostsFileEditor",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log that the user tried to activate the editor
|
||||
void Trace::ActivateEditor() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"HostsFileEditor_Activate",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
// Log if the user has HostsFileEditor enabled or disabled
|
||||
static void EnableHostsFileEditor(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <string_view>
|
||||
#include <chrono>
|
||||
#include <stdio.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
|
||||
// Undefine GetCurrentTime macro to prevent
|
||||
// conflict with Storyboard::GetCurrentTime
|
||||
|
||||
@@ -9,6 +9,5 @@
|
||||
#include <thread>
|
||||
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,40 +10,33 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::EnableMeasureTool(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MeasureTool_EnableMeasureTool",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
void Trace::BoundsToolActivated() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MeasureTool_BoundsToolActivated",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::MeasureToolActivated() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MeasureTool_MeasureToolActivated",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
static void EnableMeasureTool(const bool enabled) noexcept;
|
||||
|
||||
static void BoundsToolActivated() noexcept;
|
||||
|
||||
@@ -15,6 +15,5 @@
|
||||
#endif
|
||||
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,33 +10,25 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has FindMyMouse enabled or disabled
|
||||
void Trace::EnableFindMyMouse(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FindMyMouse_EnableFindMyMouse",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log that the user activated the module by focusing the mouse pointer
|
||||
void Trace::MousePointerFocused() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"FindMyMouse_MousePointerFocused",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
// Log if the user has FindMyMouse enabled or disabled
|
||||
static void EnableFindMyMouse(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#endif
|
||||
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,33 +10,25 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has MouseHighlighter enabled or disabled
|
||||
void Trace::EnableMouseHighlighter(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseHighlighter_EnableMouseHighlighter",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log that the user activated the module by starting a highlighting session
|
||||
void Trace::StartHighlightingSession() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseHighlighter_StartHighlightingSession",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
// Log if the user has MouseHighlighter enabled or disabled
|
||||
static void EnableMouseHighlighter(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -5,6 +5,5 @@
|
||||
#include <shellapi.h>
|
||||
|
||||
//#include <common/common.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,31 +10,23 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider()
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider()
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::EnableJumpTool(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseJump_EnableJumpTool",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
void Trace::InvokeJumpTool() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseJump_InvokeJumpTool",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider();
|
||||
static void UnregisterProvider();
|
||||
|
||||
static void EnableJumpTool(const bool enabled) noexcept;
|
||||
|
||||
static void InvokeJumpTool() noexcept;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.System.h>
|
||||
#include <winrt/Windows.UI.Composition.Desktop.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <thread>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,33 +10,25 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has MousePointerCrosshairs enabled or disabled
|
||||
void Trace::EnableMousePointerCrosshairs(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MousePointerCrosshairs_EnableMousePointerCrosshairs",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
// Log that the user activated the module by having the crosshairs be drawn
|
||||
void Trace::StartDrawingCrosshairs() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MousePointerCrosshairs_StartDrawingCrosshairs",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
// Log if the user has MousePointerCrosshairs enabled or disabled
|
||||
static void EnableMousePointerCrosshairs(const bool enabled) noexcept;
|
||||
|
||||
|
||||
@@ -3,20 +3,22 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using MouseWithoutBorders.Class;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
internal class ShutdownWithPowerToys
|
||||
{
|
||||
public static void WaitForPowerToysRunner()
|
||||
public static void WaitForPowerToysRunner(ETWTrace etwTrace)
|
||||
{
|
||||
try
|
||||
{
|
||||
RunnerHelper.WaitForPowerToysRunnerExitFallback(() =>
|
||||
{
|
||||
etwTrace?.Dispose();
|
||||
Common.MainForm.Quit(true, false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ namespace MouseWithoutBorders.Class
|
||||
ManagedCommon.Logger.InitializeLogger("\\MouseWithoutBorders\\Logs");
|
||||
Common.Log(Application.ProductName + " Started!");
|
||||
|
||||
ETWTrace etwTrace = new ETWTrace();
|
||||
|
||||
etwTrace.Start();
|
||||
|
||||
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
Common.Log("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
@@ -115,7 +119,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
}
|
||||
|
||||
ShutdownWithPowerToys.WaitForPowerToysRunner();
|
||||
ShutdownWithPowerToys.WaitForPowerToysRunner(etwTrace);
|
||||
|
||||
if (firstArg != string.Empty)
|
||||
{
|
||||
@@ -223,6 +227,8 @@ namespace MouseWithoutBorders.Class
|
||||
var formScreen = new FrmScreen();
|
||||
|
||||
Application.Run(formScreen);
|
||||
|
||||
etwTrace?.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -38,8 +39,12 @@ namespace MouseWithoutBorders
|
||||
return;
|
||||
}
|
||||
|
||||
ETWTrace etwTrace = new ETWTrace();
|
||||
etwTrace.Start();
|
||||
|
||||
RunnerHelper.WaitForPowerToysRunnerExitFallback(() =>
|
||||
{
|
||||
etwTrace?.Dispose();
|
||||
Application.Exit();
|
||||
});
|
||||
|
||||
@@ -76,6 +81,8 @@ namespace MouseWithoutBorders
|
||||
|
||||
dotForm = new FormDot();
|
||||
Application.Run(FormHelper = new FormHelper());
|
||||
|
||||
etwTrace?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID /*lpRese
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
g_hInst_MouseWithoutBorders = hModule;
|
||||
Trace::RegisterProvider();
|
||||
Trace::MouseWithoutBorders::RegisterProvider();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
Trace::UnregisterProvider();
|
||||
Trace::MouseWithoutBorders::UnregisterProvider();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <winrt/base.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <TraceLoggingActivity.h>
|
||||
|
||||
#include <wil\common.h>
|
||||
#include <wil\result.h>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
// Telemetry strings should not be localized.
|
||||
#define LoggingProviderKey "Microsoft.PowerToys"
|
||||
|
||||
@@ -14,51 +16,45 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::MouseWithoutBorders::Enable(bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
EventEnableMouseWithoutBordersKey,
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, EventEnabledKey));
|
||||
}
|
||||
|
||||
void Trace::MouseWithoutBorders::ToggleServiceRegistration(bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseWithoutBorders_ToggleServiceRegistration",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, EventEnabledKey));
|
||||
}
|
||||
|
||||
void Trace::MouseWithoutBorders::Activate() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseWithoutBorders_Activate",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
// Log that the user tried to activate the editor
|
||||
void Trace::MouseWithoutBorders::AddFirewallRule() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"MouseWithoutBorders_AddFirewallRule",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
class MouseWithoutBorders
|
||||
class MouseWithoutBorders : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void Enable(bool enabled) noexcept;
|
||||
|
||||
@@ -10,19 +10,9 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::EventToggleOnOff(_In_ const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"NewPlus_EventToggleOnOff",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
@@ -32,7 +22,7 @@ void Trace::EventToggleOnOff(_In_ const bool enabled) noexcept
|
||||
|
||||
void Trace::EventChangedTemplateLocation() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"NewPlus_ChangedTemplateLocation",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
@@ -41,7 +31,7 @@ void Trace::EventChangedTemplateLocation() noexcept
|
||||
|
||||
void Trace::EventShowTemplateItems(const size_t number_of_templates) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"NewPlus_EventShowTemplateItems",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
@@ -51,7 +41,7 @@ void Trace::EventShowTemplateItems(const size_t number_of_templates) noexcept
|
||||
|
||||
void Trace::EventCopyTemplate(_In_ const std::wstring template_file_extension) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"NewPlus_EventCopyTemplate",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
@@ -61,7 +51,7 @@ void Trace::EventCopyTemplate(_In_ const std::wstring template_file_extension) n
|
||||
|
||||
void Trace::EventCopyTemplateResult(_In_ const HRESULT hr) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"NewPlus_EventCopyTemplateResult",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
static void EventToggleOnOff(_In_ const bool new_enabled_state) noexcept;
|
||||
static void EventChangedTemplateLocation() noexcept;
|
||||
static void EventShowTemplateItems(_In_ const size_t number_of_templates) noexcept;
|
||||
|
||||
@@ -6,10 +6,12 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
using Common.UI;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using PowerOCR.Keyboard;
|
||||
using PowerOCR.Settings;
|
||||
using PowerToys.Interop;
|
||||
|
||||
namespace PowerOCR;
|
||||
|
||||
@@ -22,6 +24,7 @@ public partial class App : Application, IDisposable
|
||||
private EventMonitor? eventMonitor;
|
||||
private Mutex? _instanceMutex;
|
||||
private int _powerToysRunnerPid;
|
||||
private ETWTrace etwTrace = new ETWTrace();
|
||||
|
||||
private CancellationTokenSource NativeThreadCTS { get; set; }
|
||||
|
||||
@@ -43,12 +46,21 @@ public partial class App : Application, IDisposable
|
||||
}
|
||||
|
||||
NativeThreadCTS = new CancellationTokenSource();
|
||||
|
||||
etwTrace.Start();
|
||||
|
||||
NativeEventWaiter.WaitForEventLoop(
|
||||
Constants.TerminatePowerOCRSharedEvent(),
|
||||
this.Shutdown,
|
||||
this.Dispatcher,
|
||||
NativeThreadCTS.Token);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
keyboardMonitor?.Dispose();
|
||||
etwTrace?.Dispose();
|
||||
}
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
|
||||
@@ -69,6 +69,8 @@ private:
|
||||
|
||||
// Handle to event used to invoke PowerOCR
|
||||
HANDLE m_hInvokeEvent;
|
||||
// Handle to event used to terminate PowerOCR
|
||||
HANDLE m_hTerminateEvent;
|
||||
|
||||
void parse_hotkey(PowerToysSettings::PowerToyValues& settings)
|
||||
{
|
||||
@@ -160,6 +162,7 @@ public:
|
||||
app_key = PowerOcrConstants::ModuleKey;
|
||||
LoggerHelpers::init_logger(app_key, L"ModuleInterface", "TextExtractor");
|
||||
m_hInvokeEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_POWEROCR_SHARED_EVENT);
|
||||
m_hTerminateEvent = CreateDefaultEvent(CommonSharedConstants::TERMINATE_POWEROCR_SHARED_EVENT);
|
||||
init_settings();
|
||||
}
|
||||
|
||||
@@ -249,6 +252,8 @@ public:
|
||||
if (m_enabled)
|
||||
{
|
||||
ResetEvent(m_hInvokeEvent);
|
||||
SetEvent(m_hTerminateEvent);
|
||||
WaitForSingleObject(m_hProcess, 1000);
|
||||
TerminateProcess(m_hProcess, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,5 @@
|
||||
#include <windows.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <shellapi.h>
|
||||
#include <Shlwapi.h>
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,23 +10,14 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider()
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider()
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
// Log if the user has PowerOCR enabled or disabled
|
||||
void Trace::EnablePowerOCR(const bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"PowerOCR_EnablePowerOCR",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII),
|
||||
TraceLoggingBoolean(enabled, "Enabled"));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
class Trace
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider();
|
||||
static void UnregisterProvider();
|
||||
|
||||
// Log if the user has PowerOCR enabled or disabled
|
||||
static void EnablePowerOCR(const bool enabled) noexcept;
|
||||
};
|
||||
|
||||
@@ -158,6 +158,9 @@
|
||||
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
||||
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\common\Telemetry\EtwTrace\EtwTrace.vcxproj">
|
||||
<Project>{8f021b46-362b-485c-bfba-ccf83e820cbd}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\common\Themes\Themes.vcxproj">
|
||||
<Project>{98537082-0fdb-40de-abd8-0dc5a4269bab}</Project>
|
||||
</ProjectReference>
|
||||
|
||||
@@ -116,7 +116,79 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\**">
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\1.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\2.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\3.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\4.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\5.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\6.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\7.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\8.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\9.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\no_active_window.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\overlay.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\overlay_portrait.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\0.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\1.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\2.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\3.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\4.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\5.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\6.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\7.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\8.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\9.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\no_active_window.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\overlay.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Assets\ShortcutGuide\overlay_portrait.svg">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <common/utils/EventWaiter.h>
|
||||
#include <common/utils/gpo.h>
|
||||
|
||||
#include <common/Telemetry/EtwTrace/EtwTrace.h>
|
||||
|
||||
#include "shortcut_guide.h"
|
||||
#include "target_state.h"
|
||||
#include "ShortcutGuideConstants.h"
|
||||
@@ -48,6 +50,9 @@ int WINAPI wWinMain(_In_ HINSTANCE /*hInstance*/, _In_opt_ HINSTANCE /*hPrevInst
|
||||
winrt::init_apartment();
|
||||
LoggerHelpers::init_logger(ShortcutGuideConstants::ModuleKey, L"ShortcutGuide", LogSettings::shortcutGuideLoggerName);
|
||||
|
||||
Shared::Trace::ETWTrace trace;
|
||||
trace.UpdateState(true);
|
||||
|
||||
if (powertoys_gpo::getConfiguredShortcutGuideEnabledValue() == powertoys_gpo::gpo_rule_configured_disabled)
|
||||
{
|
||||
Logger::warn(L"Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
@@ -132,6 +137,8 @@ int WINAPI wWinMain(_In_ HINSTANCE /*hInstance*/, _In_opt_ HINSTANCE /*hPrevInst
|
||||
|
||||
window.ShowWindow();
|
||||
run_message_loop();
|
||||
|
||||
trace.Flush();
|
||||
Trace::UnregisterProvider();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,5 @@
|
||||
#include <tuple>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <filesystem>
|
||||
#include <common/logger/logger.h>
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@@ -8,31 +10,22 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::SendGuideSession(const __int64 duration_ms, const wchar_t* close_type) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"ShortcutGuide_GuideSession",
|
||||
TraceLoggingInt64(duration_ms, "DurationInMs"),
|
||||
TraceLoggingWideString(close_type, "CloseType"),
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
void Trace::SendSettings(ShortcutGuideSettings settings) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"ShortcutGuide_Settings",
|
||||
TraceLoggingWideString(settings.hotkey.c_str(), "Hotkey"),
|
||||
@@ -44,5 +37,6 @@ void Trace::SendSettings(ShortcutGuideSettings settings) noexcept
|
||||
TraceLoggingInt32(settings.windowsKeyPressTimeForTaskbarIconShortcuts, "WindowsKeyPressTimeForTaskbarIconShortcuts"),
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingEventTag(MICROSOFT_EVENTTAG_DROP_PII));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "ShortcutGuideSettings.h"
|
||||
|
||||
class Trace
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
static void SendGuideSession(const __int64 duration_ms, const wchar_t* close_type) noexcept;
|
||||
static void SendSettings(ShortcutGuideSettings settings) noexcept;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define NOMINMAX
|
||||
#include <winrt/base.h>
|
||||
#include <Windows.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <filesystem>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/resources.h>
|
||||
@@ -9,6 +9,7 @@ using System.Windows;
|
||||
|
||||
using Common.UI;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using WorkspacesEditor.Utils;
|
||||
using WorkspacesEditor.ViewModels;
|
||||
|
||||
@@ -31,8 +32,11 @@ namespace WorkspacesEditor
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
private ETWTrace etwTrace = new ETWTrace();
|
||||
|
||||
public App()
|
||||
{
|
||||
etwTrace.Start();
|
||||
WorkspacesEditorIO = new WorkspacesEditorIO();
|
||||
}
|
||||
|
||||
@@ -135,6 +139,7 @@ namespace WorkspacesEditor
|
||||
{
|
||||
ThemeManager?.Dispose();
|
||||
_instanceMutex?.Dispose();
|
||||
etwTrace?.Dispose();
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using WorkspacesEditor.Utils;
|
||||
using WorkspacesEditor.ViewModels;
|
||||
|
||||
|
||||
@@ -155,6 +155,9 @@
|
||||
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
||||
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\common\Telemetry\EtwTrace\EtwTrace.vcxproj">
|
||||
<Project>{8f021b46-362b-485c-bfba-ccf83e820cbd}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\WorkspacesLib\WorkspacesLib.vcxproj">
|
||||
<Project>{b31fcc55-b5a4-4ea7-b414-2dceae6af332}</Project>
|
||||
</ProjectReference>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <common/utils/UnhandledExceptionHandler.h>
|
||||
#include <common/utils/resources.h>
|
||||
|
||||
#include <common/Telemetry/EtwTrace/EtwTrace.h>
|
||||
|
||||
#include <WorkspacesLib/JsonUtils.h>
|
||||
#include <WorkspacesLib/utils.h>
|
||||
|
||||
@@ -23,6 +25,9 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm
|
||||
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::workspacesLauncherLoggerName);
|
||||
InitUnhandledExceptionHandler();
|
||||
|
||||
Shared::Trace::ETWTrace trace{};
|
||||
trace.UpdateState(true);
|
||||
|
||||
if (powertoys_gpo::getConfiguredWorkspacesEnabledValue() == powertoys_gpo::gpo_rule_configured_disabled)
|
||||
{
|
||||
Logger::warn(L"Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
@@ -161,8 +166,12 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm
|
||||
return 1;
|
||||
}
|
||||
|
||||
Launcher launcher(projectToLaunch, workspaces, cmdArgs.invokePoint);
|
||||
{
|
||||
Launcher launcher(projectToLaunch, workspaces, cmdArgs.invokePoint);
|
||||
}
|
||||
|
||||
trace.Flush();
|
||||
trace.UpdateState(false);
|
||||
Logger::trace("Finished");
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
|
||||
@@ -13,19 +13,9 @@ TRACELOGGING_DEFINE_PROVIDER(
|
||||
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||
TraceLoggingOptionProjectTelemetry());
|
||||
|
||||
void Trace::RegisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingRegister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::UnregisterProvider() noexcept
|
||||
{
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::Workspaces::Enable(bool enabled) noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"Workspaces_Enable",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
@@ -77,7 +67,7 @@ void Trace::Workspaces::Launch(bool success,
|
||||
errorStr += exeName + L":" + errorMessage + L"; ";
|
||||
}
|
||||
|
||||
TraceLoggingWrite(
|
||||
TraceLoggingWriteWrapper(
|
||||
g_hProvider,
|
||||
"Workspaces_LaunchEvent",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
#include <WorkspacesLib/WorkspacesData.h>
|
||||
#include <workspaces-common/InvokePoint.h>
|
||||
|
||||
#include <common/Telemetry/TraceBase.h>
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider() noexcept;
|
||||
static void UnregisterProvider() noexcept;
|
||||
|
||||
class Workspaces
|
||||
class Workspaces : public telemetry::TraceBase
|
||||
{
|
||||
public:
|
||||
static void Enable(bool enabled) noexcept;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user