43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using Toak.Core.Interfaces;
|
|
|
|
namespace Toak.Core;
|
|
|
|
public class StateTracker : IRecordingStateTracker
|
|
{
|
|
private readonly string StateFilePath = Path.Combine(Path.GetTempPath(), "toak_state.pid");
|
|
|
|
public bool IsRecording()
|
|
{
|
|
return File.Exists(StateFilePath);
|
|
}
|
|
|
|
public void SetRecording(int ffmpegPid)
|
|
{
|
|
Logger.LogDebug($"Setting recording state with PID {ffmpegPid}");
|
|
File.WriteAllText(StateFilePath, ffmpegPid.ToString());
|
|
}
|
|
|
|
public int? GetRecordingPid()
|
|
{
|
|
if (File.Exists(StateFilePath))
|
|
{
|
|
var content = File.ReadAllText(StateFilePath).Trim();
|
|
if (int.TryParse(content, out var pid))
|
|
{
|
|
Logger.LogDebug($"Read recording PID {pid} from state file");
|
|
return pid;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void ClearRecording()
|
|
{
|
|
if (File.Exists(StateFilePath))
|
|
{
|
|
Logger.LogDebug("Clearing recording state file");
|
|
File.Delete(StateFilePath);
|
|
}
|
|
}
|
|
}
|