Implement CloseShellAfterPress (no logic)

Signed-off-by: Florian Grabmeier <flo.grabmeier@gmail.com>
This commit is contained in:
Florian Grabmeier 2023-11-01 17:35:00 +01:00
parent 026e5f5b09
commit 4c5eae895b
6 changed files with 32 additions and 2 deletions

View file

@ -2,6 +2,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="flowlauncher_plugin_cmd_relace_winr">Ersetzt Win+R</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_close_cmd_after_press">Schließe die Kommandozeilte nachdem eine Taste gedrückt wurde</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Schließe die Kommandozeilte nicht nachdem der Befehl ausgeführt wurde</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Immer als Administrator ausführen</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Als anderer Benutzer ausführen</system:String>

View file

@ -3,6 +3,7 @@
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="flowlauncher_plugin_cmd_relace_winr">Replace Win+R</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_close_cmd_after_press">Close Command Prompt after pressing any key</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Do not close Command Prompt after command execution</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Always run as administrator</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Run as different user</system:String>

View file

@ -187,7 +187,7 @@ namespace Flow.Launcher.Plugin.Shell
return history.ToList();
}
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false)
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false) //TODO: implement logic for CloseCMDAfterPress
{
command = command.Trim();
command = Environment.ExpandEnvironmentVariables(command);
@ -203,7 +203,7 @@ namespace Flow.Launcher.Plugin.Shell
case Shell.Cmd:
{
info.FileName = "cmd.exe";
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}";
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? "& pause" : "")}";
//// Use info.Arguments instead of info.ArgumentList to enable users better control over the arguments they are writing.
//// Previous code using ArgumentList, commands needed to be separated correctly:
@ -233,6 +233,10 @@ namespace Flow.Launcher.Plugin.Shell
{
info.ArgumentList.Add("-Command");
info.ArgumentList.Add(command);
if (_settings.CloseShellAfterPress)
{
info.ArgumentList.Add("; pause");
}
}
break;
}
@ -246,6 +250,10 @@ namespace Flow.Launcher.Plugin.Shell
}
info.ArgumentList.Add("-Command");
info.ArgumentList.Add(command);
if (_settings.CloseShellAfterPress)
{
info.ArgumentList.Add("; pause");
}
break;
}

View file

@ -7,6 +7,8 @@ namespace Flow.Launcher.Plugin.Shell
public Shell Shell { get; set; } = Shell.Cmd;
public bool ReplaceWinR { get; set; } = false;
public bool CloseShellAfterPress { get; set; } = false;
public bool LeaveShellOpen { get; set; }

View file

@ -22,6 +22,12 @@
Margin="10,10,5,5"
HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_cmd_relace_winr}" />
<CheckBox
x:Name="CloseShellAfterPress"
Grid.Row="1"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_cmd_close_cmd_after_press}" />
<CheckBox
x:Name="LeaveShellOpen"
Grid.Row="1"

View file

@ -17,6 +17,8 @@ namespace Flow.Launcher.Plugin.Shell
private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
{
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
CloseShellAfterPress.IsChecked = _settings.CloseShellAfterPress;
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
@ -38,6 +40,16 @@ namespace Flow.Launcher.Plugin.Shell
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
}
CloseShellAfterPress.Checked += (o, e) =>
{
_settings.CloseShellAfterPress = true;
};
CloseShellAfterPress.Unchecked += (o, e) =>
{
_settings.CloseShellAfterPress = false;
};
LeaveShellOpen.Checked += (o, e) =>
{
_settings.LeaveShellOpen = true;