Pt run] keep shell open (#28041)

* [PTRun] LeaveShellOpen condition added to run command

* [PTRun] Keep shell open added to shell plugin settings.

* [PTRun] Unnecessary variable deleted. Formatting.

* [PTRun] Variable name changed.
This commit is contained in:
gokcekantarci
2023-08-22 18:16:42 +03:00
committed by GitHub
parent 6acae53e2c
commit 5426759b9c
3 changed files with 68 additions and 6 deletions

View File

@@ -13,6 +13,8 @@ using System.Linq;
using System.Reflection;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.Plugin.Shell.Properties;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Wox.Plugin.Common;
@@ -21,7 +23,7 @@ using Control = System.Windows.Controls.Control;
namespace Microsoft.Plugin.Shell
{
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable
public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, ISavable
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IPath Path = FileSystem.Path;
@@ -37,6 +39,16 @@ namespace Microsoft.Plugin.Shell
public string Description => Properties.Resources.wox_plugin_cmd_plugin_description;
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
new PluginAdditionalOption()
{
Key = "LeaveShellOpen",
DisplayLabel = Resources.wox_leave_shell_open,
Value = _settings.LeaveShellOpen,
},
};
private PluginInitContext _context;
public Main()
@@ -220,17 +232,41 @@ namespace Microsoft.Plugin.Shell
if (ExistInPath(filename))
{
var arguments = parts[1];
info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsVerbArg);
if (_settings.LeaveShellOpen)
{
// Wrap the command in a cmd.exe process
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{filename} {arguments}\"", runAsVerbArg);
}
else
{
info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsVerbArg);
}
}
else
{
if (_settings.LeaveShellOpen)
{
// Wrap the command in a cmd.exe process
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{command}\"", runAsVerbArg);
}
else
{
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
}
}
}
else
{
if (_settings.LeaveShellOpen)
{
// Wrap the command in a cmd.exe process
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{command}\"", runAsVerbArg);
}
else
{
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
}
}
else
{
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
}
}
}
else
@@ -378,5 +414,19 @@ namespace Microsoft.Plugin.Shell
return resultlist;
}
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
var leaveShellOpen = false;
if (settings != null && settings.AdditionalOptions != null)
{
var optionLeaveShellOpen = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "LeaveShellOpen");
leaveShellOpen = optionLeaveShellOpen?.Value ?? leaveShellOpen;
_settings.LeaveShellOpen = leaveShellOpen;
}
Save();
}
}
}