From 9f00966e67d9c37c1eb8a2459bd96dab46899eca Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Mon, 14 Oct 2024 13:52:36 +0200 Subject: [PATCH] Do not start manually C# EtwTrace. FZ engine exit event. --- .../AdvancedPaste/AdvancedPasteXAML/App.xaml.cs | 2 -- .../EnvironmentVariablesXAML/App.xaml.cs | 2 -- src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs | 2 -- src/modules/MouseWithoutBorders/App/Class/Program.cs | 2 -- src/modules/MouseWithoutBorders/App/Helper/Program.cs | 1 - src/modules/PowerOCR/PowerOCR/App.xaml.cs | 2 -- src/modules/Workspaces/WorkspacesEditor/App.xaml.cs | 1 - src/modules/awake/Awake/Program.cs | 1 - src/modules/colorPicker/ColorPickerUI/App.xaml.cs | 1 - src/modules/fancyzones/FancyZones/FancyZonesApp.cpp | 11 ++++++++++- src/modules/fancyzones/FancyZones/FancyZonesApp.h | 6 +++++- src/modules/launcher/PowerLauncher/App.xaml.cs | 1 - src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs | 2 -- src/modules/poweraccent/PowerAccent.UI/App.xaml.cs | 1 - .../RegistryPreview/RegistryPreviewXAML/App.xaml.cs | 1 - src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs | 1 - 16 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs index ad6d461f7d..4922967f92 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs @@ -61,8 +61,6 @@ namespace AdvancedPaste this.InitializeComponent(); - EtwTrace.Start(); - Host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder().UseContentRoot(AppContext.BaseDirectory).ConfigureServices((context, services) => { services.AddSingleton(); diff --git a/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/App.xaml.cs b/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/App.xaml.cs index 1869bd1a80..e40478f222 100644 --- a/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/App.xaml.cs +++ b/src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/App.xaml.cs @@ -80,8 +80,6 @@ namespace EnvironmentVariables /// Details about the launch request and process. protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { - EtwTrace.Start(); - var cmdArgs = Environment.GetCommandLineArgs(); if (cmdArgs?.Length > 1) { diff --git a/src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs b/src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs index 7e68319e99..7c4d6c389e 100644 --- a/src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs +++ b/src/modules/Hosts/Hosts/HostsXAML/App.xaml.cs @@ -107,8 +107,6 @@ namespace Hosts /// Details about the launch request and process. protected override void OnLaunched(LaunchActivatedEventArgs args) { - EtwTrace.Start(); - var cmdArgs = Environment.GetCommandLineArgs(); if (cmdArgs?.Length > 1) { diff --git a/src/modules/MouseWithoutBorders/App/Class/Program.cs b/src/modules/MouseWithoutBorders/App/Class/Program.cs index 3da9cbca31..8beb5809c5 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Program.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Program.cs @@ -57,8 +57,6 @@ namespace MouseWithoutBorders.Class 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."); diff --git a/src/modules/MouseWithoutBorders/App/Helper/Program.cs b/src/modules/MouseWithoutBorders/App/Helper/Program.cs index 90be6a13ea..874a0ac2a4 100644 --- a/src/modules/MouseWithoutBorders/App/Helper/Program.cs +++ b/src/modules/MouseWithoutBorders/App/Helper/Program.cs @@ -40,7 +40,6 @@ namespace MouseWithoutBorders } ETWTrace etwTrace = new ETWTrace(); - etwTrace.Start(); RunnerHelper.WaitForPowerToysRunnerExitFallback(() => { diff --git a/src/modules/PowerOCR/PowerOCR/App.xaml.cs b/src/modules/PowerOCR/PowerOCR/App.xaml.cs index a919f66a26..77987ab5cd 100644 --- a/src/modules/PowerOCR/PowerOCR/App.xaml.cs +++ b/src/modules/PowerOCR/PowerOCR/App.xaml.cs @@ -47,8 +47,6 @@ public partial class App : Application, IDisposable NativeThreadCTS = new CancellationTokenSource(); - etwTrace.Start(); - NativeEventWaiter.WaitForEventLoop( Constants.TerminatePowerOCRSharedEvent(), this.Shutdown, diff --git a/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs b/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs index e2e36b1e9f..669230b744 100644 --- a/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs +++ b/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs @@ -36,7 +36,6 @@ namespace WorkspacesEditor public App() { - etwTrace.Start(); WorkspacesEditorIO = new WorkspacesEditorIO(); } diff --git a/src/modules/awake/Awake/Program.cs b/src/modules/awake/Awake/Program.cs index f7e8ea69c7..a75fa29740 100644 --- a/src/modules/awake/Awake/Program.cs +++ b/src/modules/awake/Awake/Program.cs @@ -52,7 +52,6 @@ namespace Awake private static int Main(string[] args) { - _etwTrace.Start(); _settingsUtils = new SettingsUtils(); LockMutex = new Mutex(true, Core.Constants.AppName, out bool instantiated); Logger.InitializeLogger(Path.Combine("\\", Core.Constants.AppName, "Logs")); diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs index bf1aa2751b..0621fbc4b9 100644 --- a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs @@ -46,7 +46,6 @@ namespace ColorPickerUI Logger.LogError("CultureNotFoundException: " + ex.Message); } - EtwTrace.Start(); NativeThreadCTS = new CancellationTokenSource(); ExitToken = NativeThreadCTS.Token; diff --git a/src/modules/fancyzones/FancyZones/FancyZonesApp.cpp b/src/modules/fancyzones/FancyZones/FancyZonesApp.cpp index afa0bf610c..97faec65d5 100644 --- a/src/modules/fancyzones/FancyZones/FancyZonesApp.cpp +++ b/src/modules/fancyzones/FancyZones/FancyZonesApp.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,14 @@ FancyZonesApp::FancyZonesApp(const std::wstring& appName, const std::wstring& ap InitializeWinhookEventIds(); m_app = MakeFancyZones(reinterpret_cast(&__ImageBase), std::bind(&FancyZonesApp::DisableModule, this)); + m_mainThreadId = GetCurrentThreadId(); + m_exitEventWaiter = EventWaiter(CommonSharedConstants::FZE_EXIT_EVENT, [&](int err) { + if (err == ERROR_SUCCESS) + { + DisableModule(); + } + }); + InitHooks(); s_instance = this; @@ -111,7 +120,7 @@ void FancyZonesApp::InitHooks() void FancyZonesApp::DisableModule() noexcept { - PostQuitMessage(0); + PostThreadMessage(m_mainThreadId, WM_QUIT, 0, 0); } void FancyZonesApp::HandleWinHookEvent(WinHookEvent* data) noexcept diff --git a/src/modules/fancyzones/FancyZones/FancyZonesApp.h b/src/modules/fancyzones/FancyZones/FancyZonesApp.h index b66ba5b540..44c6a306a9 100644 --- a/src/modules/fancyzones/FancyZones/FancyZonesApp.h +++ b/src/modules/fancyzones/FancyZones/FancyZonesApp.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -15,11 +16,14 @@ public: private: static inline FancyZonesApp* s_instance = nullptr; static inline HHOOK s_llKeyboardHook = nullptr; - + winrt::com_ptr m_app; HWINEVENTHOOK m_objectLocationWinEventHook = nullptr; std::vector m_staticWinEventHooks; + EventWaiter m_exitEventWaiter; + DWORD m_mainThreadId; + void DisableModule() noexcept; void InitHooks(); diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index b51a7d3ed6..f110bf7142 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -96,7 +96,6 @@ namespace PowerLauncher using (var application = new App()) { application.InitializeComponent(); - application.etwTrace.Start(); Common.UI.NativeEventWaiter.WaitForEventLoop( Constants.RunExitEvent(), diff --git a/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs b/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs index 21b3651c6e..a433b00e43 100644 --- a/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs +++ b/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs @@ -51,8 +51,6 @@ namespace Peek.UI InitializeComponent(); Logger.InitializeLogger("\\Peek\\Logs"); - EtwTrace.Start(); - Host = Microsoft.Extensions.Hosting.Host. CreateDefaultBuilder(). UseContentRoot(AppContext.BaseDirectory). diff --git a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs index dc5739cedf..297b5f2f7b 100644 --- a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs +++ b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs @@ -31,7 +31,6 @@ namespace PowerAccent.UI } base.OnStartup(e); - _etwTrace.Start(); } protected override void OnExit(ExitEventArgs e) diff --git a/src/modules/registrypreview/RegistryPreview/RegistryPreviewXAML/App.xaml.cs b/src/modules/registrypreview/RegistryPreview/RegistryPreviewXAML/App.xaml.cs index 6f47276caa..6930d8bc98 100644 --- a/src/modules/registrypreview/RegistryPreview/RegistryPreviewXAML/App.xaml.cs +++ b/src/modules/registrypreview/RegistryPreview/RegistryPreviewXAML/App.xaml.cs @@ -47,7 +47,6 @@ namespace RegistryPreview // #if DEBUG // System.Diagnostics.Debugger.Launch(); // #endif - EtwTrace.Start(); // Open With... handler - gets activation arguments if they are available. AppActivationArguments activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); diff --git a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs index e5aaff8e7e..3972d38582 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs @@ -81,7 +81,6 @@ namespace Microsoft.PowerToys.Settings.UI Logger.InitializeLogger(@"\Settings\Logs"); EtwTrace = new ETWTrace(); - EtwTrace.Start(); string appLanguage = LanguageHelper.LoadLanguage(); if (!string.IsNullOrEmpty(appLanguage))