Files
desktop/WirelessTextSyncer.Windows/Models/SyncActionJsonConverter.cs
Misaka 30da1680f2 Add system mute control via setMute action
Introduce a setMute protocol action and an NAudio-backed
AudioControlService so the Android client can toggle the Windows
render endpoint mute state over WebSocket.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-17 22:12:13 +08:00

46 lines
1.3 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace WirelessTextSyncer.Windows.Models;
public sealed class SyncActionJsonConverter : JsonConverter<SyncAction>
{
public override SyncAction Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
var value = reader.GetString();
return value switch
{
"insertText" => SyncAction.InsertText,
"replaceAll" => SyncAction.ReplaceAll,
"backspace" => SyncAction.Backspace,
"enter" => SyncAction.Enter,
"ping" => SyncAction.Ping,
"setMute" => SyncAction.SetMute,
_ => throw new JsonException($"Unsupported sync action: {value}")
};
}
public override void Write(
Utf8JsonWriter writer,
SyncAction value,
JsonSerializerOptions options)
{
var action = value switch
{
SyncAction.InsertText => "insertText",
SyncAction.ReplaceAll => "replaceAll",
SyncAction.Backspace => "backspace",
SyncAction.Enter => "enter",
SyncAction.Ping => "ping",
SyncAction.SetMute => "setMute",
_ => throw new JsonException($"Unsupported sync action: {value}")
};
writer.WriteStringValue(action);
}
}