Proper handling for PID binding

Now Espresso can be connected directly to the PowerToys PID.
This commit is contained in:
Den Delimarsky 2021-05-03 08:04:53 -07:00
parent 31ca8ff2ce
commit 33a81416fc
No known key found for this signature in database
GPG Key ID: E1BE1355085F0BCF
3 changed files with 33 additions and 5 deletions

View File

@ -43,6 +43,10 @@
<PackageReference Include="System.Runtime.Caching" Version="6.0.0-preview.1.21102.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Program.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>

View File

@ -4,6 +4,7 @@
using Espresso.Shell.Core;
using Espresso.Shell.Models;
using ManagedCommon;
using Newtonsoft.Json;
using NLog;
using System;
@ -89,16 +90,30 @@ namespace Espresso.Shell
timeOption.Required = false;
var powerToysPidOption = new Option<int>(
aliases: new[] { "--ptpid", "-p" },
getDefaultValue: () => 0,
description: "Reference to PowerToys PID, when executed under the application context.")
{
Argument = new Argument<int>(() => 0)
{
Arity = ArgumentArity.ZeroOrOne,
},
};
powerToysPidOption.Required = false;
var rootCommand = new RootCommand
{
configOption,
displayOption,
timeOption
timeOption,
powerToysPidOption
};
rootCommand.Description = appName;
rootCommand.Handler = CommandHandler.Create<string, bool, long>(HandleCommandLineArguments);
rootCommand.Handler = CommandHandler.Create<string, bool, long, int>(HandleCommandLineArguments);
return rootCommand.InvokeAsync(args).Result;
}
@ -111,11 +126,12 @@ namespace Espresso.Shell
Environment.Exit(exitCode);
}
private static void HandleCommandLineArguments(string config, bool displayOn, long timeLimit)
private static void HandleCommandLineArguments(string config, bool displayOn, long timeLimit, int ptpid)
{
log.Info($"The value for --config is: {config}");
log.Info($"The value for --display-on is: {displayOn}");
log.Info($"The value for --time-limit is: {timeLimit}");
log.Info($"The value for --ptpid is: {ptpid}");
if (!string.IsNullOrWhiteSpace(config))
{
@ -150,6 +166,14 @@ namespace Espresso.Shell
log.Info(errorString);
log.Debug(errorString);
}
if (ptpid != 0)
{
RunnerHelper.WaitForPowerToysRunner(ptpid, () =>
{
Environment.Exit(0);
});
}
}
else
{

View File

@ -81,8 +81,8 @@ private:
// Get the configuration file that will be passed to the process.
std::wstring espresso_settings_location = PTSettingsHelper::get_module_save_file_location(MODULE_NAME);
std::wstring executable_args = L"--config " + espresso_settings_location;
//executable_args.append(std::to_wstring(powertoys_pid));
std::wstring executable_args = L"--config " + espresso_settings_location + L" --ptpid " + std::to_wstring(powertoys_pid);
Logger::trace(L"Espresso launching with parameters: " + executable_args);
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };