refactor: modernize code, improve performance, and clean up various components.
This commit is contained in:
@@ -4,24 +4,24 @@ namespace Toak.Core;
|
||||
|
||||
public class StateTracker : IRecordingStateTracker
|
||||
{
|
||||
private readonly string StateFilePath = Constants.Paths.StateFile;
|
||||
private readonly string _stateFilePath = Constants.Paths.StateFile;
|
||||
|
||||
public bool IsRecording()
|
||||
{
|
||||
return File.Exists(StateFilePath);
|
||||
return File.Exists(_stateFilePath);
|
||||
}
|
||||
|
||||
public void SetRecording(int ffmpegPid)
|
||||
{
|
||||
Logger.LogDebug($"Setting recording state with PID {ffmpegPid}");
|
||||
File.WriteAllText(StateFilePath, $"{ffmpegPid}\n{DateTime.UtcNow.Ticks}");
|
||||
File.WriteAllText(_stateFilePath, $"{ffmpegPid}\n{DateTime.UtcNow.Ticks}");
|
||||
}
|
||||
|
||||
public int? GetRecordingPid()
|
||||
{
|
||||
if (File.Exists(StateFilePath))
|
||||
if (File.Exists(_stateFilePath))
|
||||
{
|
||||
var lines = File.ReadAllLines(StateFilePath);
|
||||
var lines = File.ReadAllLines(_stateFilePath);
|
||||
if (lines.Length > 0 && int.TryParse(lines[0], out var pid))
|
||||
{
|
||||
Logger.LogDebug($"Read recording PID {pid} from state file");
|
||||
@@ -33,9 +33,9 @@ public class StateTracker : IRecordingStateTracker
|
||||
|
||||
public DateTime? GetRecordingStartTime()
|
||||
{
|
||||
if (File.Exists(StateFilePath))
|
||||
if (File.Exists(_stateFilePath))
|
||||
{
|
||||
var lines = File.ReadAllLines(StateFilePath);
|
||||
var lines = File.ReadAllLines(_stateFilePath);
|
||||
if (lines.Length > 1 && long.TryParse(lines[1], out var ticks))
|
||||
{
|
||||
return new DateTime(ticks, DateTimeKind.Utc);
|
||||
@@ -46,10 +46,10 @@ public class StateTracker : IRecordingStateTracker
|
||||
|
||||
public void ClearRecording()
|
||||
{
|
||||
if (File.Exists(StateFilePath))
|
||||
if (File.Exists(_stateFilePath))
|
||||
{
|
||||
Logger.LogDebug("Clearing recording state file");
|
||||
File.Delete(StateFilePath);
|
||||
File.Delete(_stateFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user