Add return value for start process api function

This commit is contained in:
Jack251970 2025-06-12 15:32:34 +08:00
parent 21e8d92aa2
commit 0d1358fdc3
2 changed files with 8 additions and 3 deletions

View file

@ -591,7 +591,8 @@ namespace Flow.Launcher.Plugin
/// <param name="workingDirectory">Working directory. If not specified, the current directory will be used</param>
/// <param name="arguments">Optional arguments to pass to the process. If not specified, no arguments will be passed</param>
/// <param name="runAsAdmin">Whether to run the process as administrator</param>
public void StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false);
/// <returns>Whether process is started successfully</returns>
public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false);
/// <summary>
/// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application.

View file

@ -577,7 +577,7 @@ namespace Flow.Launcher
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
Stopwatch.InfoAsync(className, message, action, methodName);
public void StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false)
public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false)
{
try
{
@ -590,8 +590,10 @@ namespace Flow.Launcher
if (!string.IsNullOrEmpty(errorInfo))
{
LogError(ClassName, $"Failed to start process {filePath} with error: {errorInfo}");
return false;
}
return;
return true;
}
var info = new ProcessStartInfo
@ -603,10 +605,12 @@ namespace Flow.Launcher
Verb = runAsAdmin ? "runas" : "",
};
Process.Start(info)?.Dispose();
return true;
}
catch (Exception e)
{
LogException(ClassName, $"Failed to start process {filePath} with arguments {arguments} under {workingDirectory}", e);
return false;
}
}