Reduce telemetry spam

This commit is contained in:
Jaime Bernardo 2024-11-22 11:47:58 +00:00
parent 63112b4828
commit 883e58b94e
5 changed files with 18 additions and 22 deletions

View File

@ -43,8 +43,6 @@ IFACEMETHODIMP shell_context_menu_win10::QueryContextMenu(HMENU menu_handle, UIN
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
}
Trace trace_on;
try
{
// Create the initial context popup menu containing the list of templates and open templates action
@ -124,9 +122,6 @@ IFACEMETHODIMP shell_context_menu_win10::QueryContextMenu(HMENU menu_handle, UIN
}
else
{
// Log that context menu was shown and with how many items
Trace::EventShowTemplateItems(number_of_templates);
// Return the amount if entries inserted
const auto number_of_items_inserted = menu_id - menu_first_cmd_id;
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, number_of_items_inserted);
@ -232,6 +227,12 @@ IFACEMETHODIMP shell_context_menu_win10::InvokeCommand(CMINVOKECOMMANDINFO* para
const auto number_of_templates = templates->list_of_templates.size();
const bool is_template_item = selected_menu_item_index < number_of_templates;
// Log that context menu was shown and with how many items
trace.UpdateState(true);
Trace::EventShowTemplateItems(number_of_templates);
trace.Flush();
trace.UpdateState(false);
if (is_template_item)
{
// It's a template menu item

View File

@ -345,8 +345,6 @@ namespace newplus::utilities
{
HRESULT hr = S_OK;
Trace trace_on;
try
{
Logger::info(L"Copying template");
@ -367,7 +365,10 @@ namespace newplus::utilities
// Copy file and determine final filename
std::filesystem::path target_final_fullpath = template_entry->copy_object_to(GetActiveWindow(), target_fullpath);
trace.UpdateState(true);
Trace::EventCopyTemplate(target_final_fullpath.extension().c_str());
trace.Flush();
trace.UpdateState(false);
// Refresh folder items
template_entry->refresh_target(target_final_fullpath);
@ -382,7 +383,10 @@ namespace newplus::utilities
hr = S_FALSE;
}
trace.UpdateState(true);
Trace::EventCopyTemplateResult(hr);
trace.Flush();
trace.UpdateState(false);
return hr;
}
@ -391,8 +395,6 @@ namespace newplus::utilities
{
HRESULT hr = S_OK;
Trace trace_on;
try
{
Logger::info(L"Open templates folder");
@ -400,7 +402,10 @@ namespace newplus::utilities
const std::wstring verb_hardcoded_do_not_change = L"open";
ShellExecute(nullptr, verb_hardcoded_do_not_change.c_str(), template_folder.c_str(), NULL, NULL, SW_SHOWNORMAL);
trace.UpdateState(true);
Trace::EventOpenTemplates();
trace.Flush();
trace.UpdateState(false);
}
catch (const std::exception& ex)
{

View File

@ -7,7 +7,6 @@ using namespace Microsoft::WRL;
// // Sub context menu command enumerator
shell_context_sub_menu::shell_context_sub_menu(const ComPtr<IUnknown> site_of_folder)
{
trace.UpdateState(true);
this->site_of_folder = site_of_folder;
// Determine the New+ Template folder location
@ -37,7 +36,10 @@ shell_context_sub_menu::shell_context_sub_menu(const ComPtr<IUnknown> site_of_fo
current_command = explorer_menu_item_commands.cbegin();
// Log that context menu was shown and with how many items
trace.UpdateState(true);
Trace::EventShowTemplateItems(number_of_templates);
trace.Flush();
trace.UpdateState(false);
}
// IEnumExplorerCommand

View File

@ -10,16 +10,6 @@ TRACELOGGING_DEFINE_PROVIDER(
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
TraceLoggingOptionProjectTelemetry());
Trace::Trace()
{
trace.UpdateState(true);
}
Trace::~Trace()
{
trace.Flush();
trace.UpdateState(false);
}
void Trace::EventToggleOnOff(_In_ const bool enabled) noexcept
{
TraceLoggingWriteWrapper(

View File

@ -7,8 +7,6 @@
class Trace : public telemetry::TraceBase
{
public:
Trace();
~Trace();
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;