From d42cd4bd3bdc83227a7e499ddbe10d03271a2db1 Mon Sep 17 00:00:00 2001 From: Seraphima Zykova Date: Thu, 29 Aug 2024 13:07:38 +0200 Subject: [PATCH] [Workspaces] Close editor when PT runner exited. (#34477) * [Workspaces] Close editor when PT runner exited. * removed trailing whitespace --- .../Workspaces/WorkspacesEditor/App.xaml.cs | 14 ++++++++++++++ .../WorkspacesModuleInterface/dllmain.cpp | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs b/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs index ca29a95e68..073ecfc802 100644 --- a/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs +++ b/src/modules/Workspaces/WorkspacesEditor/App.xaml.cs @@ -57,6 +57,20 @@ namespace WorkspacesEditor return; } + var args = e?.Args; + int powerToysRunnerPid; + if (args?.Length > 0) + { + _ = int.TryParse(args[0], out powerToysRunnerPid); + + Logger.LogInfo($"WorkspacesEditor started from the PowerToys Runner. Runner pid={powerToysRunnerPid}"); + RunnerHelper.WaitForPowerToysRunner(powerToysRunnerPid, () => + { + Logger.LogInfo("PowerToys Runner exited. Exiting WorkspacesEditor"); + Dispatcher.Invoke(Shutdown); + }); + } + ThemeManager = new ThemeManager(this); if (_mainViewModel == null) diff --git a/src/modules/Workspaces/WorkspacesModuleInterface/dllmain.cpp b/src/modules/Workspaces/WorkspacesModuleInterface/dllmain.cpp index 71176b217f..090e646118 100644 --- a/src/modules/Workspaces/WorkspacesModuleInterface/dllmain.cpp +++ b/src/modules/Workspaces/WorkspacesModuleInterface/dllmain.cpp @@ -309,15 +309,15 @@ private: { Logger::trace(L"Starting Workspaces Editor"); - /*unsigned long powertoys_pid = GetCurrentProcessId(); + unsigned long powertoys_pid = GetCurrentProcessId(); std::wstring executable_args = L""; - executable_args.append(std::to_wstring(powertoys_pid));*/ + executable_args.append(std::to_wstring(powertoys_pid)); SHELLEXECUTEINFOW sei{ sizeof(sei) }; sei.fMask = SEE_MASK_NOCLOSEPROCESS; sei.lpFile = L"PowerToys.WorkspacesEditor.exe"; sei.nShow = SW_SHOWNORMAL; - //sei.lpParameters = executable_args.data(); + sei.lpParameters = executable_args.data(); if (ShellExecuteExW(&sei)) { Logger::trace("Successfully started the Workspaces Editor");