feat: introduce a background daemon service for persistent operation and inter-process communication.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console;
|
||||
using Toak.Audio;
|
||||
using Toak.Core;
|
||||
using Toak.IO;
|
||||
|
||||
namespace Toak.Commands;
|
||||
|
||||
@@ -13,23 +12,34 @@ public static class DiscardCommand
|
||||
{
|
||||
Logger.Verbose = verbose;
|
||||
|
||||
if (StateTracker.IsRecording())
|
||||
var socketPath = DaemonService.GetSocketPath();
|
||||
|
||||
try
|
||||
{
|
||||
AudioRecorder.StopRecording();
|
||||
var wavPath = AudioRecorder.GetWavPath();
|
||||
if (File.Exists(wavPath)) File.Delete(wavPath);
|
||||
Notifications.Notify("Toak", "Recording discarded");
|
||||
if (!pipeToStdout)
|
||||
using var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
|
||||
var endPoint = new UnixDomainSocketEndPoint(socketPath);
|
||||
await socket.ConnectAsync(endPoint);
|
||||
|
||||
// Send ABORT (cmd == 3)
|
||||
await socket.SendAsync(new byte[] { 3 }, SocketFlags.None);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[yellow]Recording discarded.[/]");
|
||||
Console.WriteLine("Sent ABORT command to daemon.");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (SocketException)
|
||||
{
|
||||
if (!pipeToStdout)
|
||||
if (!pipeToStdout)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[grey]No active recording to discard.[/]");
|
||||
AnsiConsole.MarkupLine("[red]Failed to connect to Toak daemon.[/]");
|
||||
AnsiConsole.MarkupLine("Please ensure the daemon is running in the background:");
|
||||
AnsiConsole.MarkupLine(" [dim]toak daemon[/]");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!pipeToStdout) AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user