Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public interface IPublicAPI
/// </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>
Expand Down
28 changes: 25 additions & 3 deletions Flow.Launcher.Plugin/SharedCommands/ShellCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -60,17 +60,39 @@ private static string GetWindowTitle(IntPtr hwnd)
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);
}
}
}
11 changes: 10 additions & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand All @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -106,6 +107,14 @@ public void OpenSettingDialog()
});
}

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;
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void Execute(Func<ProcessStartInfo, Process> startProcess, ProcessStartI
{
try
{
startProcess(info);
ShellCommand.Execute(startProcess, info);
}
catch (FileNotFoundException e)
{
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Shell/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "Shell",
"Description": "Provide executing commands from Flow Launcher",
"Author": "qianlifeng",
"Version": "1.4.5",
"Version": "1.4.6",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Flow.Launcher.Plugin.Sys/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ private List<Result> Commands()
var info = ShellCommand.SetProcessStartInfo("shutdown", arguments:"/h");
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
Process.Start(info);

ShellCommand.Execute(info);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Sys/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down