feat: Introduce explicit start, stop, and status commands, including minimum recording duration.
This commit is contained in:
46
Commands/StopCommand.cs
Normal file
46
Commands/StopCommand.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console;
|
||||
using Toak.Core;
|
||||
|
||||
namespace Toak.Commands;
|
||||
|
||||
public static class StopCommand
|
||||
{
|
||||
public static async Task ExecuteAsync(bool pipeToStdout, bool copyToClipboard, bool verbose)
|
||||
{
|
||||
Logger.Verbose = verbose;
|
||||
var socketPath = DaemonService.GetSocketPath();
|
||||
try
|
||||
{
|
||||
using var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
|
||||
var endPoint = new UnixDomainSocketEndPoint(socketPath);
|
||||
await socket.ConnectAsync(endPoint);
|
||||
|
||||
var msg = new byte[] { 2, (byte)(pipeToStdout ? 1 : 0), (byte)(copyToClipboard ? 1 : 0) };
|
||||
await socket.SendAsync(msg, SocketFlags.None);
|
||||
if (verbose) Console.WriteLine("Sent STOP command to daemon.");
|
||||
|
||||
var responseBuffer = new byte[4096];
|
||||
while (true)
|
||||
{
|
||||
int received = await socket.ReceiveAsync(responseBuffer, SocketFlags.None);
|
||||
if (received == 0) break;
|
||||
if (pipeToStdout)
|
||||
{
|
||||
var text = System.Text.Encoding.UTF8.GetString(responseBuffer, 0, received);
|
||||
Console.Write(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]Failed to connect to Toak daemon.[/]");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user