@@ -8,7 +8,7 @@ public sealed class ToastDeckPipeClient
88 private static readonly JsonSerializerOptions JsonOptions = new ( JsonSerializerDefaults . Web )
99 {
1010 PropertyNameCaseInsensitive = true ,
11- WriteIndented = true
11+ WriteIndented = false
1212 } ;
1313
1414 public async Task < ToastDeckPipeResponse > SendAsync (
@@ -34,14 +34,25 @@ public async Task<ToastDeckPipeResponse> SendAsync(
3434 return ToastDeckPipeResponse . Fail ( "ToastDeck is not running or did not respond. Start the ToastDeck app and try again." ) ;
3535 }
3636
37- await using var writer = new StreamWriter ( pipe ) { AutoFlush = true } ;
38- using var reader = new StreamReader ( pipe ) ;
39- await writer . WriteLineAsync ( JsonSerializer . Serialize ( request , JsonOptions ) ) ;
40- var responseJson = await reader . ReadLineAsync ( linked . Token ) ;
37+ try
38+ {
39+ await using var writer = new StreamWriter ( pipe , leaveOpen : true ) { AutoFlush = true } ;
40+ using var reader = new StreamReader ( pipe , leaveOpen : true ) ;
41+ await writer . WriteLineAsync ( JsonSerializer . Serialize ( request , JsonOptions ) ) ;
42+ var responseJson = await reader . ReadLineAsync ( linked . Token ) ;
4143
42- return string . IsNullOrWhiteSpace ( responseJson )
43- ? ToastDeckPipeResponse . Fail ( "ToastDeck returned an empty IPC response." )
44- : JsonSerializer . Deserialize < ToastDeckPipeResponse > ( responseJson , JsonOptions ) ??
45- ToastDeckPipeResponse . Fail ( "ToastDeck returned an invalid IPC response." ) ;
44+ return string . IsNullOrWhiteSpace ( responseJson )
45+ ? ToastDeckPipeResponse . Fail ( "ToastDeck returned an empty IPC response." )
46+ : JsonSerializer . Deserialize < ToastDeckPipeResponse > ( responseJson , JsonOptions ) ??
47+ ToastDeckPipeResponse . Fail ( "ToastDeck returned an invalid IPC response." ) ;
48+ }
49+ catch ( IOException ex )
50+ {
51+ return ToastDeckPipeResponse . Fail ( $ "ToastDeck IPC failed: { ex . Message } ") ;
52+ }
53+ catch ( JsonException ex )
54+ {
55+ return ToastDeckPipeResponse . Fail ( $ "ToastDeck returned invalid IPC JSON: { ex . Message } ") ;
56+ }
4657 }
4758}
0 commit comments