mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 02:39:22 +08:00
Proper handling for PID binding
Now Espresso can be connected directly to the PowerToys PID.
This commit is contained in:
parent
31ca8ff2ce
commit
33a81416fc
@ -43,6 +43,10 @@
|
|||||||
<PackageReference Include="System.Runtime.Caching" Version="6.0.0-preview.1.21102.12" />
|
<PackageReference Include="System.Runtime.Caching" Version="6.0.0-preview.1.21102.12" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Program.cs">
|
<Compile Update="Program.cs">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using Espresso.Shell.Core;
|
using Espresso.Shell.Core;
|
||||||
using Espresso.Shell.Models;
|
using Espresso.Shell.Models;
|
||||||
|
using ManagedCommon;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
@ -89,16 +90,30 @@ namespace Espresso.Shell
|
|||||||
|
|
||||||
timeOption.Required = false;
|
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
|
var rootCommand = new RootCommand
|
||||||
{
|
{
|
||||||
configOption,
|
configOption,
|
||||||
displayOption,
|
displayOption,
|
||||||
timeOption
|
timeOption,
|
||||||
|
powerToysPidOption
|
||||||
};
|
};
|
||||||
|
|
||||||
rootCommand.Description = appName;
|
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;
|
return rootCommand.InvokeAsync(args).Result;
|
||||||
}
|
}
|
||||||
@ -111,11 +126,12 @@ namespace Espresso.Shell
|
|||||||
Environment.Exit(exitCode);
|
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 --config is: {config}");
|
||||||
log.Info($"The value for --display-on is: {displayOn}");
|
log.Info($"The value for --display-on is: {displayOn}");
|
||||||
log.Info($"The value for --time-limit is: {timeLimit}");
|
log.Info($"The value for --time-limit is: {timeLimit}");
|
||||||
|
log.Info($"The value for --ptpid is: {ptpid}");
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(config))
|
if (!string.IsNullOrWhiteSpace(config))
|
||||||
{
|
{
|
||||||
@ -150,6 +166,14 @@ namespace Espresso.Shell
|
|||||||
log.Info(errorString);
|
log.Info(errorString);
|
||||||
log.Debug(errorString);
|
log.Debug(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptpid != 0)
|
||||||
|
{
|
||||||
|
RunnerHelper.WaitForPowerToysRunner(ptpid, () =>
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -81,8 +81,8 @@ private:
|
|||||||
// Get the configuration file that will be passed to the process.
|
// 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 espresso_settings_location = PTSettingsHelper::get_module_save_file_location(MODULE_NAME);
|
||||||
|
|
||||||
std::wstring executable_args = L"--config " + espresso_settings_location;
|
std::wstring executable_args = L"--config " + espresso_settings_location + L" --ptpid " + std::to_wstring(powertoys_pid);
|
||||||
//executable_args.append(std::to_wstring(powertoys_pid));
|
Logger::trace(L"Espresso launching with parameters: " + executable_args);
|
||||||
|
|
||||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
||||||
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
||||||
|
Loading…
Reference in New Issue
Block a user