- Add NozJsonContext / NozJsonContextPretty source generator contexts - Replace all reflection-based JSON with source-generated overloads - Add NotesCacheFile record for persistent note cache - Add date field to NoteInfo, CancellationToken to all API methods - LocalConfig uses source-generated serialization (compact + indented)
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System.Text.Json;
|
|
using NozCli.Core.Serialization;
|
|
|
|
namespace NozCli.Core.Config;
|
|
|
|
public class LocalConfig
|
|
{
|
|
public string ServerUrl { get; set; } = string.Empty;
|
|
public string Token { get; set; } = string.Empty;
|
|
/// Default editor (nano, vim, vi, notepad …) — used by 'edit' and 'new'
|
|
public string? Editor { get; set; } = null;
|
|
/// Editor for the -c flag (code, zed, kate …) — used by 'edit -c' and 'new -c'
|
|
public string? CodeEditor { get; set; } = null;
|
|
|
|
private static readonly string ConfigPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
".config", "noz", "config.json"
|
|
);
|
|
|
|
public static LocalConfig? Load()
|
|
{
|
|
if (!File.Exists(ConfigPath)) return null;
|
|
var json = File.ReadAllText(ConfigPath);
|
|
return JsonSerializer.Deserialize(json, NozJsonContext.Default.LocalConfig);
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath)!);
|
|
var json = JsonSerializer.Serialize(this, NozJsonContextPretty.Default.LocalConfig);
|
|
File.WriteAllText(ConfigPath, json);
|
|
if (!OperatingSystem.IsWindows())
|
|
File.SetUnixFileMode(ConfigPath, UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
|
}
|
|
|
|
public static bool Exists() => File.Exists(ConfigPath);
|
|
}
|