mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #742 from spedrickson/JsonRPCShellRun
add initial ShellRun support for JsonRPC
This commit is contained in:
commit
e7198c6d79
6 changed files with 48 additions and 8 deletions
|
|
@ -29,6 +29,15 @@ namespace Flow.Launcher.Plugin
|
|||
/// </summary>
|
||||
void RestartApp();
|
||||
|
||||
/// <summary>
|
||||
/// Run a shell command
|
||||
/// </summary>
|
||||
/// <param name="cmd">The command or program to run</param>
|
||||
/// <param name="filename">the shell type to run, e.g. powershell.exe</param>
|
||||
/// <exception cref="FileNotFoundException">Thrown when unable to find the file specified in the command </exception>
|
||||
/// <exception cref="Win32Exception">Thrown when error occurs during the execution of the command </exception>
|
||||
void ShellRun(string cmd, string filename = "cmd.exe");
|
||||
|
||||
/// <summary>
|
||||
/// Save everything, all of Flow Launcher and plugins' data and settings
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
|
@ -60,17 +60,39 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static ProcessStartInfo SetProcessStartInfo(this string fileName, string workingDirectory = "", string arguments = "", string verb = "")
|
||||
public static ProcessStartInfo SetProcessStartInfo(this string fileName, string workingDirectory = "", string arguments = "", string verb = "", bool createNoWindow = false)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
WorkingDirectory = workingDirectory,
|
||||
Arguments = arguments,
|
||||
Verb = verb
|
||||
Verb = verb,
|
||||
CreateNoWindow = createNoWindow
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a windows command using the provided ProcessStartInfo
|
||||
/// </summary>
|
||||
/// <exception cref="FileNotFoundException">Thrown when unable to find the file specified in the command </exception>
|
||||
/// <exception cref="Win32Exception">Thrown when error occurs during the execution of the command </exception>
|
||||
public static void Execute(ProcessStartInfo info)
|
||||
{
|
||||
Execute(Process.Start, info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a windows command using the provided ProcessStartInfo using a custom execute command function
|
||||
/// </summary>
|
||||
/// <param name="Func startProcess">allows you to pass in a custom command execution function</param>
|
||||
/// <exception cref="FileNotFoundException">Thrown when unable to find the file specified in the command </exception>
|
||||
/// <exception cref="Win32Exception">Thrown when error occurs during the execution of the command </exception>
|
||||
public static void Execute(Func<ProcessStartInfo, Process> startProcess, ProcessStartInfo info)
|
||||
{
|
||||
startProcess(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
|
@ -14,6 +14,7 @@ using Flow.Launcher.Infrastructure.Image;
|
|||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Flow.Launcher.Plugin.SharedModels;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
|
|
@ -106,6 +107,14 @@ namespace Flow.Launcher
|
|||
});
|
||||
}
|
||||
|
||||
public void ShellRun(string cmd, string filename = "cmd.exe")
|
||||
{
|
||||
var args = filename == "cmd.exe" ? $"/C {cmd}" : $"{cmd}";
|
||||
|
||||
var startInfo = ShellCommand.SetProcessStartInfo(filename, arguments: args, createNoWindow: true);
|
||||
ShellCommand.Execute(startInfo);
|
||||
}
|
||||
|
||||
public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;
|
||||
|
||||
public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
{
|
||||
try
|
||||
{
|
||||
startProcess(info);
|
||||
ShellCommand.Execute(startProcess, info);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -190,8 +190,8 @@ namespace Flow.Launcher.Plugin.Sys
|
|||
var info = ShellCommand.SetProcessStartInfo("shutdown", arguments:"/h");
|
||||
info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
info.UseShellExecute = true;
|
||||
|
||||
Process.Start(info);
|
||||
|
||||
ShellCommand.Execute(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Name": "System Commands",
|
||||
"Description": "Provide System related commands. e.g. shutdown,lock, setting etc.",
|
||||
"Author": "qianlifeng",
|
||||
"Version": "1.5.0",
|
||||
"Version": "1.5.1",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.Sys.dll",
|
||||
|
|
|
|||
Loading…
Reference in a new issue