mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Settings telemetry for ColorPicker (#10417)
This commit is contained in:
@@ -149,6 +149,10 @@ public
|
||||
return gcnew String(CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT);
|
||||
}
|
||||
|
||||
static String ^ ColorPickerSendSettingsTelemetryEvent() {
|
||||
return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
|
||||
}
|
||||
|
||||
static String ^ ShowColorPickerSharedEvent() {
|
||||
return gcnew String(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace CommonSharedConstants
|
||||
|
||||
const wchar_t RUN_SEND_SETTINGS_TELEMETRY_EVENT[] = L"Local\\PowerToysRunInvokeEvent-638ec522-0018-4b96-837d-6bd88e06f0d6";
|
||||
|
||||
const wchar_t COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT[] = L"Local\\ColorPickerSettingsTelemetryEvent-6c7071d8-4014-46ec-b687-913bd8a422f1";
|
||||
|
||||
// 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";
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <common/utils/resources.h>
|
||||
|
||||
#include <colorPicker/ColorPicker/ColorPickerConstants.h>
|
||||
#include <common/interop/shared_constants.h>
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
@@ -47,11 +48,14 @@ private:
|
||||
// Time to wait for process to close after sending WM_CLOSE signal
|
||||
static const int MAX_WAIT_MILLISEC = 10000;
|
||||
|
||||
HANDLE send_telemetry_event;
|
||||
|
||||
public:
|
||||
ColorPicker()
|
||||
{
|
||||
app_name = GET_RESOURCE_STRING(IDS_COLORPICKER_NAME);
|
||||
app_key = ColorPickerConstants::ModuleKey;
|
||||
send_telemetry_event = CreateDefaultEvent(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT);
|
||||
}
|
||||
|
||||
~ColorPicker()
|
||||
@@ -119,6 +123,7 @@ public:
|
||||
|
||||
virtual void enable()
|
||||
{
|
||||
ResetEvent(send_telemetry_event);
|
||||
// use only with new settings?
|
||||
if (UseNewSettings())
|
||||
{
|
||||
@@ -144,6 +149,7 @@ public:
|
||||
{
|
||||
if (m_enabled)
|
||||
{
|
||||
ResetEvent(send_telemetry_event);
|
||||
TerminateProcess(m_hProcess, 1);
|
||||
}
|
||||
|
||||
@@ -154,6 +160,11 @@ public:
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
virtual void send_settings_telemetry() override
|
||||
{
|
||||
SetEvent(send_telemetry_event);
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
|
||||
|
||||
@@ -3,25 +3,13 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using interop;
|
||||
|
||||
namespace ColorPicker.Helpers
|
||||
{
|
||||
[Export(typeof(NativeEventWaiter))]
|
||||
public class NativeEventWaiter
|
||||
public static class NativeEventWaiter
|
||||
{
|
||||
private AppStateHandler _appStateHandler;
|
||||
|
||||
[ImportingConstructor]
|
||||
public NativeEventWaiter(AppStateHandler appStateHandler)
|
||||
{
|
||||
_appStateHandler = appStateHandler;
|
||||
WaitForEventLoop(Constants.ShowColorPickerSharedEvent(), _appStateHandler.StartUserSession);
|
||||
}
|
||||
|
||||
public static void WaitForEventLoop(string eventName, Action callback)
|
||||
{
|
||||
new Thread(() =>
|
||||
@@ -31,7 +19,7 @@ namespace ColorPicker.Helpers
|
||||
{
|
||||
if (eventHandle.WaitOne())
|
||||
{
|
||||
Logger.LogInfo("Successfully waited for SHOW_COLOR_PICKER_EVENT");
|
||||
Logger.LogInfo($"Successfully waited for {eventName}");
|
||||
Application.Current.Dispatcher.Invoke(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,7 @@ namespace ColorPicker.Settings
|
||||
ObservableCollection<string> VisibleColorFormats { get; }
|
||||
|
||||
SettingItem<bool> ShowColorName { get; }
|
||||
|
||||
void SendSettingsTelemetry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using ColorPicker.Common;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
namespace ColorPicker.Settings
|
||||
{
|
||||
@@ -160,5 +161,27 @@ namespace ColorPicker.Settings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SendSettingsTelemetry()
|
||||
{
|
||||
Logger.LogInfo("Sending settings telemetry");
|
||||
var settings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerModuleName);
|
||||
var properties = settings?.Properties;
|
||||
if (properties == null)
|
||||
{
|
||||
Logger.LogError("Failed to send settings telemetry");
|
||||
return;
|
||||
}
|
||||
|
||||
var telemetrySettings = new Telemetry.ColorPickerSettings(properties.VisibleColorFormats)
|
||||
{
|
||||
ActivationShortcut = properties.ActivationShortcut.ToString(),
|
||||
ActivationBehaviour = properties.ActivationAction.ToString(),
|
||||
ColorFormatForClipboard = properties.CopiedColorRepresentation.ToString(),
|
||||
ShowColorName = properties.ShowColorName,
|
||||
};
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(telemetrySettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace ColorPicker.Telemetry
|
||||
{
|
||||
[EventData]
|
||||
public class ColorPickerSettings : EventBase, IEvent
|
||||
{
|
||||
public ColorPickerSettings(IDictionary<string, bool> editorFormats)
|
||||
{
|
||||
EditorFormats = editorFormats;
|
||||
}
|
||||
|
||||
public string ActivationShortcut { get; set; }
|
||||
|
||||
public string ActivationBehaviour { get; set; }
|
||||
|
||||
public string ColorFormatForClipboard { get; set; }
|
||||
|
||||
public bool ShowColorName { get; set; }
|
||||
|
||||
public IDictionary<string, bool> EditorFormats { get; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using ColorPicker.Mouse;
|
||||
using ColorPicker.Settings;
|
||||
using ColorPicker.Telemetry;
|
||||
using ColorPicker.ViewModelContracts;
|
||||
using interop;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
@@ -26,7 +27,6 @@ namespace ColorPicker.ViewModels
|
||||
private readonly ZoomWindowHelper _zoomWindowHelper;
|
||||
private readonly AppStateHandler _appStateHandler;
|
||||
private readonly IUserSettings _userSettings;
|
||||
private readonly NativeEventWaiter _nativeEventWaiter;
|
||||
|
||||
/// <summary>
|
||||
/// Backing field for <see cref="OtherColor"/>
|
||||
@@ -49,13 +49,13 @@ namespace ColorPicker.ViewModels
|
||||
ZoomWindowHelper zoomWindowHelper,
|
||||
AppStateHandler appStateHandler,
|
||||
KeyboardMonitor keyboardMonitor,
|
||||
NativeEventWaiter nativeEventWaiter,
|
||||
IUserSettings userSettings)
|
||||
{
|
||||
_zoomWindowHelper = zoomWindowHelper;
|
||||
_appStateHandler = appStateHandler;
|
||||
_userSettings = userSettings;
|
||||
_nativeEventWaiter = nativeEventWaiter;
|
||||
NativeEventWaiter.WaitForEventLoop(Constants.ShowColorPickerSharedEvent(), _appStateHandler.StartUserSession);
|
||||
NativeEventWaiter.WaitForEventLoop(Constants.ColorPickerSendSettingsTelemetryEvent(), _userSettings.SendSettingsTelemetry);
|
||||
|
||||
if (mouseInfoProvider != null)
|
||||
{
|
||||
|
||||
@@ -86,6 +86,16 @@ public:
|
||||
virtual void send_settings_telemetry()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
HANDLE CreateDefaultEvent(const wchar_t* eventName)
|
||||
{
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.bInheritHandle = false;
|
||||
sa.lpSecurityDescriptor = NULL;
|
||||
return CreateEventW(&sa, FALSE, FALSE, eventName);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -83,15 +83,6 @@ private:
|
||||
|
||||
HANDLE send_telemetry_event;
|
||||
|
||||
SECURITY_ATTRIBUTES getDefaultSecurityAttribute()
|
||||
{
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.bInheritHandle = false;
|
||||
sa.lpSecurityDescriptor = NULL;
|
||||
return sa;
|
||||
}
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Microsoft_Launcher()
|
||||
@@ -104,10 +95,8 @@ public:
|
||||
Logger::info("Launcher object is constructing");
|
||||
init_settings();
|
||||
|
||||
auto sa1 = getDefaultSecurityAttribute();
|
||||
m_hEvent = CreateEventW(&sa1, FALSE, FALSE, CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT);
|
||||
auto sa2 = getDefaultSecurityAttribute();
|
||||
send_telemetry_event = CreateEventW(&sa2, FALSE, FALSE, CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT);
|
||||
m_hEvent = CreateDefaultEvent(CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT);
|
||||
send_telemetry_event = CreateDefaultEvent(CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT);
|
||||
};
|
||||
|
||||
~Microsoft_Launcher()
|
||||
|
||||
Reference in New Issue
Block a user