From 0d1358fdc314fe8560eb0bc45eedf6e81c0c5716 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 12 Jun 2025 15:32:34 +0800 Subject: [PATCH] Add return value for start process api function --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 3 ++- Flow.Launcher/PublicAPIInstance.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 9e3d279ab..8c02151be 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -591,7 +591,8 @@ namespace Flow.Launcher.Plugin /// Working directory. If not specified, the current directory will be used /// Optional arguments to pass to the process. If not specified, no arguments will be passed /// Whether to run the process as administrator - public void StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false); + /// Whether process is started successfully + public bool StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false); /// /// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application. diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 6a4a4493d..d02b718d0 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -577,7 +577,7 @@ namespace Flow.Launcher public Task StopwatchLogInfoAsync(string className, string message, Func 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; } }