Skip to content

Commit 328027a

Browse files
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 <kjerk@users.noreply.github.com>
1 parent b4150e6 commit 328027a

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/TimeToKill.App/Services/TimerActionService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ private ActionResult ExecuteDemotePriority(string processName)
4949
}
5050

5151
// Launch a process, skipping if already running. Used by TimerManager on start for LaunchAndKill presets.
52-
public ActionResult Launch(string processPath)
52+
public ActionResult Launch(string processPath, string arguments = null)
5353
{
5454
var exeName = ProcessNameHelper.GetExeName(processPath);
5555
if (ProcessTools.IsProcessRunning(exeName)) {
5656
return ActionResult.Succeeded(exeName, TimerActionType.LaunchAndKill, 0, "Process already running, skipping launch");
5757
}
5858

59-
var (success, error) = ProcessTools.LaunchProcess(processPath);
60-
59+
var (success, error) = ProcessTools.LaunchProcess(processPath, arguments);
60+
6161
if (success)
6262
return ActionResult.Succeeded(exeName, TimerActionType.LaunchAndKill, 1, "Launched process");
6363
else

src/TimeToKill.App/Services/TimerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ActiveTimer Start(TimerPreset preset)
9696

9797
// Launch process outside the lock for LaunchAndKill
9898
if (preset.ActionType == TimerActionType.LaunchAndKill) {
99-
_actionService.Launch(preset.ProcessName);
99+
_actionService.Launch(preset.ProcessName, preset.ActionArgs);
100100
}
101101

102102
return timer;

src/TimeToKill.Shared/Tools/ProcessTools.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public static (bool Success, int Count, string Error) DemotePriorityByName(strin
149149
: (false, 0, "Failed to demote priority of any processes");
150150
}
151151

152-
// Launch a process by path.
153-
public static (bool Success, string Error) LaunchProcess(string processPath)
152+
// Launch a process by path with optional CLI arguments.
153+
public static (bool Success, string Error) LaunchProcess(string processPath, string arguments = null)
154154
{
155155
if (string.IsNullOrWhiteSpace(processPath)) {
156156
return (false, "Process path cannot be empty");
@@ -161,6 +161,11 @@ public static (bool Success, string Error) LaunchProcess(string processPath)
161161
FileName = processPath,
162162
UseShellExecute = true
163163
};
164+
165+
if (!string.IsNullOrWhiteSpace(arguments)) {
166+
startInfo.Arguments = arguments;
167+
}
168+
164169
var proc = Process.Start(startInfo);
165170
return proc != null
166171
? (true, (string)null)

0 commit comments

Comments
 (0)