Add CW keying, function key messages and the documentation
The function keys send through cwdaemon or a WinKeyer, with N1MM's message macros. Escape stops sending. Settings are read with the reflection serializer rather than a generated one: the generated one hands back null for every property the file leaves out instead of the value the property is declared with, which crashed the program the first time a new setting was added. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Nonemm.Core;
|
||||
|
||||
namespace Nonemm.App.Configuration;
|
||||
@@ -35,6 +34,27 @@ public sealed record Settings
|
||||
|
||||
public IReadOnlyList<string> NetworkPeers { get; init; } = [];
|
||||
|
||||
/// `none`, `cwdaemon` or `winkeyer`.
|
||||
public string KeyerKind { get; init; } = "none";
|
||||
|
||||
public string KeyerHost { get; init; } = "127.0.0.1";
|
||||
|
||||
public int KeyerPort { get; init; } = 6789;
|
||||
|
||||
public string KeyerSerialPort { get; init; } = "";
|
||||
|
||||
public int KeyerSpeed { get; init; } = 28;
|
||||
|
||||
/// The twelve function key messages, keyed F1 to F12.
|
||||
public IReadOnlyList<string> CwMessages { get; init; } = [];
|
||||
|
||||
public IReadOnlyList<string> PhoneMessages { get; init; } = [];
|
||||
|
||||
/// Reflection rather than a generated serializer: the generated one hands
|
||||
/// back null for every property the file leaves out instead of the value
|
||||
/// the property is declared with.
|
||||
private static readonly JsonSerializerOptions Json = new() { WriteIndented = true };
|
||||
|
||||
public static Settings Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
@@ -43,8 +63,7 @@ public sealed record Settings
|
||||
}
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize(File.ReadAllText(path), SettingsJson.Default.Settings)
|
||||
?? new Settings();
|
||||
return JsonSerializer.Deserialize<Settings>(File.ReadAllText(path), Json) ?? new Settings();
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@@ -55,7 +74,7 @@ public sealed record Settings
|
||||
}
|
||||
|
||||
public void Save(string path) =>
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(this, SettingsJson.Default.Settings));
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(this, Json));
|
||||
}
|
||||
|
||||
/// The operator's station as it is stored, kept separate from `StationInfo` so
|
||||
@@ -111,7 +130,3 @@ public sealed record StoredStation
|
||||
Precedence = Precedence,
|
||||
};
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(Settings))]
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
internal sealed partial class SettingsJson : JsonSerializerContext;
|
||||
|
||||
Reference in New Issue
Block a user