1
0

feat: Introduce explicit start, stop, and status commands, including minimum recording duration.

This commit is contained in:
2026-02-28 18:06:15 +01:00
parent 8ec0629e1a
commit a55e599c4f
13 changed files with 234 additions and 283 deletions

46
Commands/StatusCommand.cs Normal file
View 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 StatusCommand
{
public static async Task ExecuteAsync(bool json, 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[] { 5, (byte)(json ? 1 : 0) };
await socket.SendAsync(msg, SocketFlags.None);
var responseBuffer = new byte[4096];
int received = await socket.ReceiveAsync(responseBuffer, SocketFlags.None);
if (received > 0)
{
var text = System.Text.Encoding.UTF8.GetString(responseBuffer, 0, received);
Console.WriteLine(text);
}
}
catch (SocketException)
{
if (json)
Console.WriteLine("{\"state\": \"Offline\"}");
else
Console.WriteLine("Offline");
}
catch (Exception ex)
{
if (!json) AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message}");
}
}
}