From feca1093d3794c3bda565b0f71c9b460f44ca2a7 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Fri, 6 Feb 2026 02:30:36 +0000 Subject: [PATCH] feat: Add CLI arguments support for LaunchAndKill action - Add optional arguments parameter to ProcessTools.LaunchProcess - Pass ActionArgs through TimerActionService.Launch - Wire up ActionArgs in TimerManager.Start for LaunchAndKill presets This allows users to specify CLI arguments when launching processes. Example: /path/to/app.exe with args "--arg1 xyz --arg2 abc" Fixes #3 Co-authored-by: kjerk --- src/TimeToKill.App/Services/TimerActionService.cs | 6 +++--- src/TimeToKill.App/Services/TimerManager.cs | 2 +- src/TimeToKill.Shared/Tools/ProcessTools.cs | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) 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)