53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Toak;
|
|
|
|
public class ToakConfig
|
|
{
|
|
public string GroqApiKey { get; set; } = string.Empty;
|
|
public string TypingBackend { get; set; } = "xdotool"; // wtype or xdotool
|
|
public bool ModulePunctuation { get; set; } = true;
|
|
public bool ModuleTechnicalSanitization { get; set; } = true;
|
|
public string StyleMode { get; set; } = "Professional";
|
|
public bool StructureBulletPoints { get; set; } = false;
|
|
public bool StructureSmartParagraphing { get; set; } = true;
|
|
public string TargetLanguage { get; set; } = string.Empty;
|
|
public string WhisperLanguage { get; set; } = string.Empty;
|
|
}
|
|
|
|
public static class ConfigManager
|
|
{
|
|
private static readonly string ConfigDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "toak");
|
|
private static readonly string ConfigPath = Path.Combine(ConfigDir, "config.json");
|
|
|
|
public static ToakConfig LoadConfig()
|
|
{
|
|
if (!File.Exists(ConfigPath))
|
|
{
|
|
return new ToakConfig();
|
|
}
|
|
|
|
try
|
|
{
|
|
var json = File.ReadAllText(ConfigPath);
|
|
return JsonSerializer.Deserialize<ToakConfig>(json) ?? new ToakConfig();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new ToakConfig();
|
|
}
|
|
}
|
|
|
|
public static void SaveConfig(ToakConfig config)
|
|
{
|
|
if (!Directory.Exists(ConfigDir))
|
|
{
|
|
Directory.CreateDirectory(ConfigDir);
|
|
}
|
|
|
|
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(ConfigPath, json);
|
|
}
|
|
}
|