diff --git a/src/TimeToKill.App/Services/TimerActionService.cs b/src/TimeToKill.App/Services/TimerActionService.cs index b2c5dc2..298c966 100644 --- a/src/TimeToKill.App/Services/TimerActionService.cs +++ b/src/TimeToKill.App/Services/TimerActionService.cs @@ -49,15 +49,15 @@ private ActionResult ExecuteDemotePriority(string processName) } // Launch a process, skipping if already running. Used by TimerManager on start for LaunchAndKill presets. - public ActionResult Launch(string processPath) + public ActionResult Launch(string processPath, string arguments = null) { var exeName = ProcessNameHelper.GetExeName(processPath); if (ProcessTools.IsProcessRunning(exeName)) { return ActionResult.Succeeded(exeName, TimerActionType.LaunchAndKill, 0, "Process already running, skipping launch"); } - var (success, error) = ProcessTools.LaunchProcess(processPath); - + var (success, error) = ProcessTools.LaunchProcess(processPath, arguments); + if (success) return ActionResult.Succeeded(exeName, TimerActionType.LaunchAndKill, 1, "Launched process"); else diff --git a/src/TimeToKill.App/Services/TimerManager.cs b/src/TimeToKill.App/Services/TimerManager.cs index 0c9b5d6..448d979 100644 --- a/src/TimeToKill.App/Services/TimerManager.cs +++ b/src/TimeToKill.App/Services/TimerManager.cs @@ -96,7 +96,7 @@ public ActiveTimer Start(TimerPreset preset) // Launch process outside the lock for LaunchAndKill if (preset.ActionType == TimerActionType.LaunchAndKill) { - _actionService.Launch(preset.ProcessName); + _actionService.Launch(preset.ProcessName, preset.ActionArgs); } return timer; diff --git a/src/TimeToKill.Shared/Tools/ProcessTools.cs b/src/TimeToKill.Shared/Tools/ProcessTools.cs index b1a14be..e43d5f7 100644 --- a/src/TimeToKill.Shared/Tools/ProcessTools.cs +++ b/src/TimeToKill.Shared/Tools/ProcessTools.cs @@ -149,8 +149,8 @@ public static (bool Success, int Count, string Error) DemotePriorityByName(strin : (false, 0, "Failed to demote priority of any processes"); } - // Launch a process by path. - public static (bool Success, string Error) LaunchProcess(string processPath) + // Launch a process by path with optional CLI arguments. + public static (bool Success, string Error) LaunchProcess(string processPath, string arguments = null) { if (string.IsNullOrWhiteSpace(processPath)) { return (false, "Process path cannot be empty"); @@ -161,6 +161,11 @@ public static (bool Success, string Error) LaunchProcess(string processPath) FileName = processPath, UseShellExecute = true }; + + if (!string.IsNullOrWhiteSpace(arguments)) { + startInfo.Arguments = arguments; + } + var proc = Process.Start(startInfo); return proc != null ? (true, (string)null)