Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/TimeToKill.App/Services/TimerActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/TimeToKill.App/Services/TimerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/TimeToKill.Shared/Tools/ProcessTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand Down