From bc3d604df6b663e047d81e6d85f5ec2609a75639 Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Wed, 6 Sep 2023 16:23:52 +0200 Subject: [PATCH] ModuleInterface --- PowerToys.sln | 17 +- src/common/interop/shared_constants.h | 4 + src/common/logger/logger_settings.h | 1 + src/common/utils/gpo.h | 5 + ...nvironmentVariablesModuleInterface.base.rc | 40 +++ ...nvironmentVariablesModuleInterface.vcxproj | 111 +++++++ ...ntVariablesModuleInterface.vcxproj.filters | 52 ++++ .../Resource.resx | 123 ++++++++ .../dllmain.cpp | 280 ++++++++++++++++++ .../pch.cpp | 5 + .../EnvironmentVariablesModuleInterface/pch.h | 18 ++ .../resource.base.h | 13 + .../trace.cpp | 40 +++ .../trace.h | 14 + src/runner/main.cpp | 1 + 15 files changed, 723 insertions(+), 1 deletion(-) create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp create mode 100644 src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h diff --git a/PowerToys.sln b/PowerToys.sln index b25c575a9d..e43b07f076 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -539,7 +539,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CropAndLockModuleInterface" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EnvironmentVariables", "EnvironmentVariables", "{538ED0BB-B863-4B20-98CC-BCDF7FA0B68A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnvironmentVariables", "src\modules\EnvironmentVariables\EnvironmentVariables\EnvironmentVariables.csproj", "{51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnvironmentVariables", "src\modules\EnvironmentVariables\EnvironmentVariables\EnvironmentVariables.csproj", "{51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EnvironmentVariablesModuleInterface", "src\modules\EnvironmentVariables\EnvironmentVariablesModuleInterface\EnvironmentVariablesModuleInterface.vcxproj", "{B9420661-B0E4-4241-ABD4-4A27A1F64250}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -2323,6 +2325,18 @@ Global {51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}.Release|x64.Build.0 = Release|x64 {51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}.Release|x86.ActiveCfg = Release|x64 {51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}.Release|x86.Build.0 = Release|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|ARM64.Build.0 = Debug|ARM64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|x64.ActiveCfg = Debug|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|x64.Build.0 = Debug|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|x86.ActiveCfg = Debug|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Debug|x86.Build.0 = Debug|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|ARM64.ActiveCfg = Release|ARM64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|ARM64.Build.0 = Release|ARM64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|x64.ActiveCfg = Release|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|x64.Build.0 = Release|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|x86.ActiveCfg = Release|x64 + {B9420661-B0E4-4241-ABD4-4A27A1F64250}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2519,6 +2533,7 @@ Global {3157FA75-86CF-4EE2-8F62-C43F776493C6} = {3B227528-4BA6-4CAF-B44A-A10C78A64849} {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA} = {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A} + {B9420661-B0E4-4241-ABD4-4A27A1F64250} = {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/common/interop/shared_constants.h b/src/common/interop/shared_constants.h index 1535a3aa87..a32051b079 100644 --- a/src/common/interop/shared_constants.h +++ b/src/common/interop/shared_constants.h @@ -79,6 +79,10 @@ namespace CommonSharedConstants const wchar_t CROP_AND_LOCK_THUMBNAIL_EVENT[] = L"Local\\PowerToysCropAndLockThumbnailEvent-1637be50-da72-46b2-9220-b32b206b2434"; const wchar_t CROP_AND_LOCK_EXIT_EVENT[] = L"Local\\PowerToysCropAndLockExitEvent-d995d409-7b70-482b-bad6-e7c8666f375a"; + // Path to the events used by EnvironmentVariables + const wchar_t SHOW_ENVIRONMENT_VARIABLES_EVENT[] = L"Local\\PowerToysEnvironmentVariables-ShowEnvironmentVariablesEvent-1021f616-e951-4d64-b231-a8f972159978"; + const wchar_t SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT[] = L"Local\\PowerToysEnvironmentVariables-EnvironmentVariablesAdminEvent-8c95d2ad-047c-49a2-9e8b-b4656326cfb2"; + // Max DWORD for key code to disable keys. const DWORD VK_DISABLED = 0x100; } diff --git a/src/common/logger/logger_settings.h b/src/common/logger/logger_settings.h index 8498f9bf4b..038a9a8e20 100644 --- a/src/common/logger/logger_settings.h +++ b/src/common/logger/logger_settings.h @@ -62,6 +62,7 @@ struct LogSettings inline const static std::string registryPreviewLoggerName = "registrypreview"; inline const static std::string cropAndLockLoggerName = "crop-and-lock"; inline const static std::wstring registryPreviewLogPath = L"Logs\\registryPreview-log.txt"; + inline const static std::string environmentVariablesLoggerName = "environment-variables"; inline const static int retention = 30; std::wstring logLevel; LogSettings(); diff --git a/src/common/utils/gpo.h b/src/common/utils/gpo.h index 3da87d62ae..53cb7faee0 100644 --- a/src/common/utils/gpo.h +++ b/src/common/utils/gpo.h @@ -52,6 +52,7 @@ namespace powertoys_gpo { const std::wstring POLICY_CONFIGURE_ENABLED_REGISTRY_PREVIEW = L"ConfigureEnabledUtilityRegistryPreview"; const std::wstring POLICY_CONFIGURE_ENABLED_MOUSE_WITHOUT_BORDERS = L"ConfigureEnabledUtilityMouseWithoutBorders"; const std::wstring POLICY_CONFIGURE_ENABLED_PEEK = L"ConfigureEnabledUtilityPeek"; + const std::wstring POLICY_CONFIGURE_ENABLED_ENVIRONMENT_VARIABLES = L"ConfigureEnabledUtilityEnvironmentVariables"; // The registry value names for PowerToys installer and update policies. const std::wstring POLICY_DISABLE_PER_USER_INSTALLATION = L"PerUserInstallationDisabled"; @@ -305,4 +306,8 @@ namespace powertoys_gpo { return getConfiguredValue(POLICY_ALLOW_EXPERIMENTATION); } + inline gpo_rule_configured_t getConfiguredEnvironmentVariablesEnabledValue() + { + return getConfiguredValue(POLICY_CONFIGURE_ENABLED_ENVIRONMENT_VARIABLES); + } } diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc new file mode 100644 index 0000000000..5fa3c8b90d --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.base.rc @@ -0,0 +1,40 @@ +#include +#include "resource.h" +#include "../../../common/version/version.h" + +#define APSTUDIO_READONLY_SYMBOLS +#include "winres.h" +#undef APSTUDIO_READONLY_SYMBOLS + +1 VERSIONINFO +FILEVERSION FILE_VERSION +PRODUCTVERSION PRODUCT_VERSION +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG +FILEFLAGS VS_FF_DEBUG +#else +FILEFLAGS 0x0L +#endif +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" // US English (0x0409), Unicode (0x04B0) charset + BEGIN + VALUE "CompanyName", COMPANY_NAME + VALUE "FileDescription", FILE_DESCRIPTION + VALUE "FileVersion", FILE_VERSION_STRING + VALUE "InternalName", INTERNAL_NAME + VALUE "LegalCopyright", COPYRIGHT_NOTE + VALUE "OriginalFilename", ORIGINAL_FILENAME + VALUE "ProductName", PRODUCT_NAME + VALUE "ProductVersion", PRODUCT_VERSION_STRING + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 // US English (0x0409), Unicode (1200) charset + END +END diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj new file mode 100644 index 0000000000..97ea5075cf --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj @@ -0,0 +1,111 @@ + + + + + + + 17.0 + Win32Proj + {b9420661-b0e4-4241-abd4-4a27a1f64250} + EnvironmentVariablesModuleInterface + EnvironmentVariablesModuleInterface + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + ..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\ + PowerToys.EnvironmentVariablesModuleInterface + + + + Level3 + true + WIN32;_DEBUG;ENVIRONMENTVARIABLESMODULEINTERFACE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;ENVIRONMENTVARIABLESMODULEINTERFACE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + + + Windows + true + true + true + false + + + + + $(SolutionDir)src;$(SolutionDir)src\modules;$(SolutionDir)src\common\Telemetry;%(AdditionalIncludeDirectories) + + + + + + + + + + + + Create + + + + + + + + + + + + {d9b8fc84-322a-4f9f-bbb9-20915c47ddfd} + + + {6955446d-23f7-4023-9bb3-8657f904af99} + + + {cc6e41ac-8174-4e8a-8d22-85dd7f4851df} + + + + + + + \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters new file mode 100644 index 0000000000..14b6af8966 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj.filters @@ -0,0 +1,52 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Resource Files + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx new file mode 100644 index 0000000000..c6531374a1 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/Resource.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Environment Variables + + \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp new file mode 100644 index 0000000000..27c2961683 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/dllmain.cpp @@ -0,0 +1,280 @@ +// dllmain.cpp : Defines the entry point for the DLL application. +#include "pch.h" + +#include "Generated Files/resource.h" +#include "trace.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern "C" IMAGE_DOS_HEADER __ImageBase; + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + Trace::RegisterProvider(); + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + Trace::UnregisterProvider(); + break; + } + return TRUE; +} + +namespace +{ + // Name of the powertoy module. + inline const std::wstring ModuleKey = L"EnvironmentVariables"; +} + +class EnvironmentVariablesModuleInterface : public PowertoyModuleIface +{ +private: + bool m_enabled = false; + + std::wstring app_name; + + //contains the non localized key of the powertoy + std::wstring app_key; + + HANDLE m_hProcess; + + HANDLE m_hShowEvent; + + EventWaiter m_showEventWaiter; + + HANDLE m_hShowAdminEvent; + + EventWaiter m_showAdminEventWaiter; + + bool is_process_running() + { + return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT; + } + + void bring_process_to_front() + { + auto enum_windows = [](HWND hwnd, LPARAM param) -> BOOL { + HANDLE process_handle = reinterpret_cast(param); + DWORD window_process_id = 0; + + GetWindowThreadProcessId(hwnd, &window_process_id); + if (GetProcessId(process_handle) == window_process_id) + { + SetForegroundWindow(hwnd); + return FALSE; + } + return TRUE; + }; + + EnumWindows(enum_windows, (LPARAM)m_hProcess); + } + + void launch_process(bool runas) + { + Logger::trace("EnvironmentVariablesModuleInterface::launch_process()"); + unsigned long powertoys_pid = GetCurrentProcessId(); + + std::wstring executable_args = L""; + executable_args.append(std::to_wstring(powertoys_pid)); + + SHELLEXECUTEINFOW sei{ sizeof(sei) }; + sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI }; + sei.lpFile = L"WinUI3Apps\\PowerToys.EnvironmentVariables.exe"; + sei.nShow = SW_SHOWNORMAL; + sei.lpParameters = executable_args.data(); + + if (runas) + { + sei.lpVerb = L"runas"; + } + + if (ShellExecuteExW(&sei)) + { + Logger::trace("Successfully started the Environment Variables process"); + } + else + { + Logger::error(L"Environment Variables failed to start. {}", get_last_error_or_default(GetLastError())); + } + + m_hProcess = sei.hProcess; + } + +public: + EnvironmentVariablesModuleInterface() + { + app_name = GET_RESOURCE_STRING(IDS_ENVIRONMENTVARIABLES_NAME); + app_key = ModuleKey; + LoggerHelpers::init_logger(app_key, L"ModuleInterface", LogSettings::environmentVariablesLoggerName); + + m_hShowEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT); + if (!m_hShowEvent) + { + Logger::error(L"Failed to create show Environment Variables event"); + auto message = get_last_error_message(GetLastError()); + if (message.has_value()) + { + Logger::error(message.value()); + } + } + + m_hShowAdminEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT); + if (!m_hShowAdminEvent) + { + Logger::error(L"Failed to create show Environment Variables admin event"); + auto message = get_last_error_message(GetLastError()); + if (message.has_value()) + { + Logger::error(message.value()); + } + } + + m_showEventWaiter = EventWaiter(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT, [&](int err) { + if (m_enabled && err == ERROR_SUCCESS) + { + Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT); + + if (is_process_running()) + { + bring_process_to_front(); + } + else + { + launch_process(false); + } + + Trace::ActivateEnvironmentVariables(); + } + }); + + m_showAdminEventWaiter = EventWaiter(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT, [&](int err) { + if (m_enabled && err == ERROR_SUCCESS) + { + Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT); + + if (is_process_running()) + { + bring_process_to_front(); + } + else + { + launch_process(true); + } + + Trace::ActivateEnvironmentVariables(); + } + }); + } + + ~EnvironmentVariablesModuleInterface() + { + m_enabled = false; + } + + // Destroy the powertoy and free memory + virtual void destroy() override + { + Logger::trace("EnvironmentVariablesModuleInterface::destroy()"); + + if (m_hShowEvent) + { + CloseHandle(m_hShowEvent); + m_hShowEvent = nullptr; + } + + if (m_hShowAdminEvent) + { + CloseHandle(m_hShowAdminEvent); + m_hShowAdminEvent = nullptr; + } + + delete this; + } + + // Return the localized display name of the powertoy + virtual const wchar_t* get_name() override + { + return app_name.c_str(); + } + + // Return the non localized key of the powertoy, this will be cached by the runner + virtual const wchar_t* get_key() override + { + return app_key.c_str(); + } + + // Return the configured status for the gpo policy for the module + virtual powertoys_gpo::gpo_rule_configured_t gpo_policy_enabled_configuration() override + { + return powertoys_gpo::getConfiguredEnvironmentVariablesEnabledValue(); + } + + virtual bool get_config(wchar_t* /*buffer*/, int* /*buffer_size*/) override + { + return false; + } + + virtual void call_custom_action(const wchar_t* /*action*/) override + { + } + + virtual void set_config(const wchar_t* /*config*/) override + { + } + + virtual bool is_enabled() override + { + return m_enabled; + } + + virtual void enable() + { + Logger::trace("EnvironmentVariablesModuleInterface::enable()"); + m_enabled = true; + Trace::EnableEnvironmentVariables(true); + } + + virtual void disable() + { + Logger::trace("EnvrionmentVariablesModuleInterface::disable()"); + if (m_enabled) + { + if (m_hShowEvent) + { + ResetEvent(m_hShowEvent); + } + + if (m_hShowAdminEvent) + { + ResetEvent(m_hShowAdminEvent); + } + + TerminateProcess(m_hProcess, 1); + } + + m_enabled = false; + Trace::EnableEnvironmentVariables(false); + } +}; + +extern "C" __declspec(dllexport) PowertoyModuleIface * __cdecl powertoy_create() +{ + return new EnvironmentVariablesModuleInterface(); +} \ No newline at end of file diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp new file mode 100644 index 0000000000..64b7eef6d6 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.cpp @@ -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. diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h new file mode 100644 index 0000000000..6f70098567 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/pch.h @@ -0,0 +1,18 @@ +// 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 +// Windows Header Files +#include +#include + +#include +#include + +#endif //PCH_H diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h new file mode 100644 index 0000000000..da4dc076a8 --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/resource.base.h @@ -0,0 +1,13 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by AlwaysOnTopModuleInterface.rc + +////////////////////////////// +// Non-localizable + +#define FILE_DESCRIPTION "PowerToys Environment Variables Module" +#define INTERNAL_NAME "PowerToys.EnvironmentVariablesModuleInterface" +#define ORIGINAL_FILENAME "PowerToys.EnvironmentVariablesModuleInterface.dll" + +// Non-localizable +////////////////////////////// diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp new file mode 100644 index 0000000000..bb458c1b6d --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.cpp @@ -0,0 +1,40 @@ +#include "pch.h" +#include "trace.h" + +TRACELOGGING_DEFINE_PROVIDER( + g_hProvider, + "Microsoft.PowerToys", + // {38e8889b-9731-53f5-e901-e8a7c1753074} + (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( + g_hProvider, + "EnvironmentVariables_EnableEnvironmentVariables", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE), + TraceLoggingBoolean(enabled, "Enabled")); +} + +// Log that the user tried to activate the editor +void Trace::ActivateEnvironmentVariables() noexcept +{ + TraceLoggingWrite( + g_hProvider, + "EnvironmentVariables_Activate", + ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance), + TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE)); +} diff --git a/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h new file mode 100644 index 0000000000..791e2728ae --- /dev/null +++ b/src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/trace.h @@ -0,0 +1,14 @@ +#pragma once + +class Trace +{ +public: + static void RegisterProvider() noexcept; + static void UnregisterProvider() noexcept; + + // Log if the user has HostsFileEditor enabled or disabled + static void EnableEnvironmentVariables(const bool enabled) noexcept; + + // Log that the user tried to activate the editor + static void ActivateEnvironmentVariables() noexcept; +}; diff --git a/src/runner/main.cpp b/src/runner/main.cpp index 2cda7f1363..faf8b9cf99 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -155,6 +155,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow L"WinUI3Apps/PowerToys.MeasureToolModuleInterface.dll", L"WinUI3Apps/PowerToys.HostsModuleInterface.dll", L"WinUI3Apps/PowerToys.Peek.dll", + L"WinUI3Apps/PowerToys.EnvironmentVariables.dll", L"PowerToys.MouseWithoutBordersModuleInterface.dll", L"PowerToys.CropAndLockModuleInterface.dll", };