initial commit
This commit is contained in:
52
ConfigManager.cs
Normal file
52
ConfigManager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user