1
0

refactor: centralize common strings, paths, and default values into a new Constants class.

This commit is contained in:
2026-02-28 15:41:40 +01:00
parent 0577640da9
commit 96ccf0ea9a
13 changed files with 80 additions and 38 deletions

48
Core/Constants.cs Normal file
View File

@@ -0,0 +1,48 @@
using System;
using System.IO;
namespace Toak.Core;
public static class Constants
{
public const string AppName = "toak";
public static class Paths
{
public static readonly string AppDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName);
public static readonly string ConfigDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", AppName);
public static readonly string ConfigFile = Path.Combine(ConfigDir, "config.json");
public static readonly string HistoryFile = Path.Combine(AppDataDir, "history.jsonl");
public static readonly string DaemonLockFile = Path.Combine(AppDataDir, "daemon.lock");
public static readonly string StateFile = Path.Combine(Path.GetTempPath(), "toak_state.pid");
public static readonly string RecordingWavFile = Path.Combine(Path.GetTempPath(), "toak_recording.wav");
public static readonly string LatencyTestWavFile = Path.Combine(Path.GetTempPath(), "toak_latency_test.wav");
public static string GetSocketPath()
{
var runtimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
return Path.Combine(string.IsNullOrEmpty(runtimeDir) ? Path.GetTempPath() : runtimeDir, "toak.sock");
}
}
public static class Commands
{
public const string AudioRecord = "pw-record";
public const string AudioFfmpeg = "ffmpeg";
public const string ProcessKill = "kill";
public const string TypeX11 = "xdotool";
public const string TypeWayland = "wtype";
public const string Notify = "notify-send";
public const string PlaySound = "paplay";
public const string ClipboardX11 = "xclip";
public const string ClipboardWayland = "wl-copy";
}
public static class Defaults
{
public const string LlmModel = "openai/gpt-oss-20b";
public const string WhisperModel = "whisper-large-v3-turbo";
}
}

View File

@@ -15,19 +15,14 @@ public static class DaemonService
{
public static string GetSocketPath()
{
var runtimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR");
if (string.IsNullOrEmpty(runtimeDir))
{
runtimeDir = Path.GetTempPath();
}
return Path.Combine(runtimeDir, "toak.sock");
return Constants.Paths.GetSocketPath();
}
private static FileStream? _lockFile;
public static async Task StartAsync(bool verbose)
{
var lockPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "toak", "daemon.lock");
var lockPath = Constants.Paths.DaemonLockFile;
try
{
Directory.CreateDirectory(Path.GetDirectoryName(lockPath)!);

View File

@@ -10,12 +10,11 @@ namespace Toak.Core;
public class HistoryManager : IHistoryManager
{
private readonly string HistoryDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "toak");
private readonly string HistoryFile;
private readonly string HistoryDir = Constants.Paths.AppDataDir;
private readonly string HistoryFile = Constants.Paths.HistoryFile;
public HistoryManager()
{
HistoryFile = Path.Combine(HistoryDir, "history.jsonl");
}
public void SaveEntry(string rawTranscript, string refinedText, string? skillName, long durationMs)

View File

@@ -13,13 +13,13 @@ public interface IConfigProvider
public interface ISpeechClient
{
Task<string> TranscribeAsync(string filePath, string language = "", string model = "whisper-large-v3-turbo");
Task<string> TranscribeAsync(string filePath, string language = "", string model = Toak.Core.Constants.Defaults.WhisperModel);
}
public interface ILlmClient
{
Task<string> RefineTextAsync(string rawTranscript, string systemPrompt, string model = "openai/gpt-oss-20b");
IAsyncEnumerable<string> RefineTextStreamAsync(string rawTranscript, string systemPrompt, string model = "openai/gpt-oss-20b");
Task<string> RefineTextAsync(string rawTranscript, string systemPrompt, string model = Toak.Core.Constants.Defaults.LlmModel);
IAsyncEnumerable<string> RefineTextStreamAsync(string rawTranscript, string systemPrompt, string model = Toak.Core.Constants.Defaults.LlmModel);
}
public interface IAudioRecorder

View File

@@ -4,7 +4,7 @@ namespace Toak.Core;
public class StateTracker : IRecordingStateTracker
{
private readonly string StateFilePath = Path.Combine(Path.GetTempPath(), "toak_state.pid");
private readonly string StateFilePath = Constants.Paths.StateFile;
public bool IsRecording()
{