mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Add telemetry event for general settings (#1269)
* telemetry for general settings
This commit is contained in:
parent
550d76a447
commit
2bef7631ae
@ -8,6 +8,8 @@
|
||||
#include <common/windows_colors.h>
|
||||
#include <common/winstore.h>
|
||||
|
||||
#include "trace.h"
|
||||
|
||||
static std::wstring settings_theme = L"system";
|
||||
static bool run_as_elevated = false;
|
||||
|
||||
@ -18,6 +20,33 @@ namespace localized_strings
|
||||
const std::wstring_view STARTUP_DISABLED_BY_USER = LR"(This setting has been disabled manually via <a href="https://ms_settings_startupapps" target="_blank">Startup Settings</a>.)";
|
||||
}
|
||||
|
||||
json::JsonObject GeneralSettings::to_json()
|
||||
{
|
||||
json::JsonObject result;
|
||||
|
||||
result.SetNamedValue(L"packaged", json::value(isPackaged));
|
||||
result.SetNamedValue(L"startup", json::value(isStartupEnabled));
|
||||
if (!startupDisabledReason.empty())
|
||||
{
|
||||
result.SetNamedValue(L"startup_disabled_reason", json::value(startupDisabledReason));
|
||||
}
|
||||
|
||||
json::JsonObject enabled;
|
||||
for (const auto& [name, isEnabled] : isModulesEnabledMap)
|
||||
{
|
||||
enabled.SetNamedValue(name, json::value(isEnabled));
|
||||
}
|
||||
result.SetNamedValue(L"enabled", std::move(enabled));
|
||||
|
||||
result.SetNamedValue(L"is_elevated", json::value(isElevated));
|
||||
result.SetNamedValue(L"run_elevated", json::value(isRunElevated));
|
||||
result.SetNamedValue(L"theme", json::value(theme));
|
||||
result.SetNamedValue(L"system_theme", json::value(systemTheme));
|
||||
result.SetNamedValue(L"powertoys_version", json::value(powerToysVersion));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
json::JsonObject load_general_settings()
|
||||
{
|
||||
auto loaded = PTSettingsHelper::load_general_settings();
|
||||
@ -30,14 +59,17 @@ json::JsonObject load_general_settings()
|
||||
return loaded;
|
||||
}
|
||||
|
||||
json::JsonObject get_general_settings()
|
||||
GeneralSettings get_settings()
|
||||
{
|
||||
json::JsonObject result;
|
||||
GeneralSettings settings{
|
||||
.isPackaged = winstore::running_as_packaged(),
|
||||
.isElevated = is_process_elevated(),
|
||||
.isRunElevated = run_as_elevated,
|
||||
.theme = settings_theme,
|
||||
.systemTheme = WindowsColors::is_dark_mode() ? L"dark" : L"light",
|
||||
.powerToysVersion = get_product_version(),
|
||||
};
|
||||
|
||||
const bool packaged = winstore::running_as_packaged();
|
||||
result.SetNamedValue(L"packaged", json::value(packaged));
|
||||
|
||||
bool startup{};
|
||||
if (winstore::running_as_packaged())
|
||||
{
|
||||
using namespace localized_strings;
|
||||
@ -45,41 +77,38 @@ json::JsonObject get_general_settings()
|
||||
switch (task_state)
|
||||
{
|
||||
case winstore::StartupTaskState::Disabled:
|
||||
startup = false;
|
||||
settings.isStartupEnabled = false;
|
||||
break;
|
||||
case winstore::StartupTaskState::Enabled:
|
||||
startup = true;
|
||||
settings.isStartupEnabled = true;
|
||||
break;
|
||||
case winstore::StartupTaskState::DisabledByPolicy:
|
||||
result.SetNamedValue(L"startup_disabled_reason", json::value(STARTUP_DISABLED_BY_POLICY));
|
||||
startup = false;
|
||||
settings.startupDisabledReason = STARTUP_DISABLED_BY_POLICY;
|
||||
settings.isStartupEnabled = false;
|
||||
break;
|
||||
case winstore::StartupTaskState::DisabledByUser:
|
||||
result.SetNamedValue(L"startup_disabled_reason", json::value(STARTUP_DISABLED_BY_USER));
|
||||
startup = false;
|
||||
settings.startupDisabledReason = STARTUP_DISABLED_BY_USER;
|
||||
settings.isStartupEnabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
startup = is_auto_start_task_active_for_this_user();
|
||||
settings.isStartupEnabled = is_auto_start_task_active_for_this_user();
|
||||
}
|
||||
result.SetNamedValue(L"startup", json::value(startup));
|
||||
|
||||
json::JsonObject enabled;
|
||||
for (auto& [name, powertoy] : modules())
|
||||
{
|
||||
enabled.SetNamedValue(name, json::value(powertoy.is_enabled()));
|
||||
settings.isModulesEnabledMap[name] = powertoy.is_enabled();
|
||||
}
|
||||
result.SetNamedValue(L"enabled", std::move(enabled));
|
||||
|
||||
bool is_elevated = is_process_elevated();
|
||||
result.SetNamedValue(L"is_elevated", json::value(is_elevated));
|
||||
result.SetNamedValue(L"run_elevated", json::value(run_as_elevated));
|
||||
result.SetNamedValue(L"theme", json::value(settings_theme));
|
||||
result.SetNamedValue(L"system_theme", json::value(WindowsColors::is_dark_mode() ? L"dark" : L"light"));
|
||||
result.SetNamedValue(L"powertoys_version", json::value(get_product_version()));
|
||||
return result;
|
||||
return settings;
|
||||
}
|
||||
|
||||
json::JsonObject get_general_settings()
|
||||
{
|
||||
auto settings = get_settings();
|
||||
return settings.to_json();
|
||||
}
|
||||
|
||||
void apply_general_settings(const json::JsonObject& general_configs)
|
||||
@ -143,8 +172,10 @@ void apply_general_settings(const json::JsonObject& general_configs)
|
||||
{
|
||||
settings_theme = general_configs.GetNamedString(L"theme");
|
||||
}
|
||||
json::JsonObject save_settings = get_general_settings();
|
||||
PTSettingsHelper::save_general_settings(save_settings);
|
||||
|
||||
GeneralSettings save_settings = get_settings();
|
||||
PTSettingsHelper::save_general_settings(save_settings.to_json());
|
||||
Trace::SettingsChanged(save_settings);
|
||||
}
|
||||
|
||||
void start_initial_powertoys()
|
||||
|
@ -2,6 +2,21 @@
|
||||
|
||||
#include <common/json.h>
|
||||
|
||||
struct GeneralSettings
|
||||
{
|
||||
bool isPackaged;
|
||||
bool isStartupEnabled;
|
||||
std::wstring startupDisabledReason;
|
||||
std::unordered_map<std::wstring, bool> isModulesEnabledMap;
|
||||
bool isElevated;
|
||||
bool isRunElevated;
|
||||
std::wstring theme;
|
||||
std::wstring systemTheme;
|
||||
std::wstring powerToysVersion;
|
||||
|
||||
json::JsonObject to_json();
|
||||
};
|
||||
|
||||
json::JsonObject load_general_settings();
|
||||
json::JsonObject get_general_settings();
|
||||
void apply_general_settings(const json::JsonObject& general_configs);
|
||||
|
@ -34,7 +34,7 @@ void chdir_current_executable()
|
||||
}
|
||||
}
|
||||
|
||||
int runner()
|
||||
int runner(bool isProcessElevated)
|
||||
{
|
||||
DPIAware::EnableDPIAwarenessForThisProcess();
|
||||
|
||||
@ -79,7 +79,7 @@ int runner()
|
||||
// Start initial powertoys
|
||||
start_initial_powertoys();
|
||||
|
||||
Trace::EventLaunch(get_product_version());
|
||||
Trace::EventLaunch(get_product_version(), isProcessElevated);
|
||||
|
||||
result = run_message_loop();
|
||||
}
|
||||
@ -115,11 +115,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
auto general_settings = load_general_settings();
|
||||
int rvalue = 0;
|
||||
if (is_process_elevated() ||
|
||||
bool isProcessElevated = is_process_elevated();
|
||||
if (isProcessElevated ||
|
||||
general_settings.GetNamedBoolean(L"run_elevated", false) == false ||
|
||||
strcmp(lpCmdLine, "--dont-elevate") == 0)
|
||||
{
|
||||
result = runner();
|
||||
result = runner(isProcessElevated);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
|
||||
#include "general_settings.h"
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
"Microsoft.PowerToys",
|
||||
@ -18,12 +20,42 @@ void Trace::UnregisterProvider()
|
||||
TraceLoggingUnregister(g_hProvider);
|
||||
}
|
||||
|
||||
void Trace::EventLaunch(const std::wstring& versionNumber)
|
||||
void Trace::EventLaunch(const std::wstring& versionNumber, bool isProcessElevated)
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"Runner_Launch",
|
||||
TraceLoggingWideString(versionNumber.c_str(), "Version"),
|
||||
TraceLoggingBoolean(isProcessElevated, "Elevated"),
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
}
|
||||
|
||||
void Trace::SettingsChanged(const GeneralSettings& settings)
|
||||
{
|
||||
std::wstring enabledModules;
|
||||
for (const auto& [name, isEnabled] : settings.isModulesEnabledMap)
|
||||
{
|
||||
if (isEnabled)
|
||||
{
|
||||
if (!enabledModules.empty())
|
||||
{
|
||||
enabledModules += L", ";
|
||||
}
|
||||
|
||||
enabledModules += name;
|
||||
}
|
||||
}
|
||||
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"GeneralSettingsChanged",
|
||||
TraceLoggingBoolean(settings.isStartupEnabled, "RunAtStartup"),
|
||||
TraceLoggingWideString(settings.startupDisabledReason.c_str(), "StartupDisabledReason"),
|
||||
TraceLoggingWideString(enabledModules.c_str(), "ModulesEnabled"),
|
||||
TraceLoggingBoolean(settings.isRunElevated, "AlwaysRunElevated"),
|
||||
TraceLoggingWideString(settings.theme.c_str(), "Theme"),
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingBoolean(TRUE, "UTCReplace_AppSessionGuid"),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
|
@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
struct GeneralSettings;
|
||||
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
static void RegisterProvider();
|
||||
static void UnregisterProvider();
|
||||
static void EventLaunch(const std::wstring& versionNumber);
|
||||
static void EventLaunch(const std::wstring& versionNumber, bool isProcessElevated);
|
||||
static void SettingsChanged(const GeneralSettings& settings);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user