* [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 коммит произвёл GitHub
Родитель 6acae53e2c
Коммит 5426759b9c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 68 добавлений и 6 удалений

Просмотреть файл

@ -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();
}
}
}

Просмотреть файл

@ -60,6 +60,15 @@ namespace Microsoft.Plugin.Shell.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Keep shell open.
/// </summary>
public static string wox_leave_shell_open {
get {
return ResourceManager.GetString("wox_leave_shell_open", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to this command has been executed {0} times.
/// </summary>

Просмотреть файл

@ -141,4 +141,7 @@
<data name="wox_plugin_cmd_run_as_user" xml:space="preserve">
<value>Run as different user (Ctrl+Shift+U)</value>
</data>
<data name="wox_leave_shell_open" xml:space="preserve">
<value>Keep shell open</value>
</data>
</root>