Skip to content

Commit 77cc257

Browse files
committed
Stabilize dev checks and local IPC
1 parent 3b63ef2 commit 77cc257

8 files changed

Lines changed: 39 additions & 18 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
charset = utf-8
5-
end_of_line = crlf
5+
end_of_line = lf
66
insert_final_newline = true
77
trim_trailing_whitespace = true
88

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto eol=lf
2+

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [main, develop]
66
pull_request:
77

88
jobs:

scripts/run-dev.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ try {
3737

3838
switch ($Mode) {
3939
"app" {
40+
Get-Process -Name "ToastDeck.App" -ErrorAction SilentlyContinue |
41+
Where-Object { $_.Path -like (Join-Path $repoRoot "src\ToastDeck.App\bin\x64\*\ToastDeck.App.exe") } |
42+
Stop-Process -Force
43+
4044
if (-not $NoBuild) {
4145
Invoke-Checked { dotnet build ToastDeck.slnx --configuration $Configuration --no-restore }
4246
}

src/ToastDeck.App/App.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public partial class App : Application
88

99
public App()
1010
{
11+
#if DEBUG
1112
UnhandledException += App_UnhandledException;
13+
#endif
1214
InitializeComponent();
1315
}
1416

@@ -18,6 +20,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
1820
window.Activate();
1921
}
2022

23+
#if DEBUG
2124
private static void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
2225
{
2326
try
@@ -34,4 +37,5 @@ private static void App_UnhandledException(object sender, Microsoft.UI.Xaml.Unha
3437
{
3538
}
3639
}
40+
#endif
3741
}

src/ToastDeck.Core/Integrations/ToastDeckPipeClient.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/ToastDeck.Core/Integrations/ToastDeckPipeServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public sealed class ToastDeckPipeServer
88
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web)
99
{
1010
PropertyNameCaseInsensitive = true,
11-
WriteIndented = true
11+
WriteIndented = false
1212
};
1313

1414
private readonly Func<ToastDeckPipeRequest, CancellationToken, Task<ToastDeckPipeResponse>> handler;
@@ -32,8 +32,8 @@ public async Task RunAsync(CancellationToken cancellationToken)
3232
try
3333
{
3434
await pipe.WaitForConnectionAsync(cancellationToken);
35-
using var reader = new StreamReader(pipe);
36-
await using var writer = new StreamWriter(pipe) { AutoFlush = true };
35+
using var reader = new StreamReader(pipe, leaveOpen: true);
36+
await using var writer = new StreamWriter(pipe, leaveOpen: true) { AutoFlush = true };
3737
var requestJson = await reader.ReadLineAsync(cancellationToken);
3838

3939
var response = await HandleAsync(requestJson, cancellationToken);

tests/ToastDeck.Tests/NotificationStateMachineTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public void MarkRead_ClearsSnoozeAndSetsReadTimestamp()
3232
var now = DateTimeOffset.UtcNow;
3333
var notification = NotificationFactory.Create(new NotificationDraft("Calendar", "Reminder", "Starts soon"))
3434
with
35-
{
36-
State = NotificationState.Snoozed,
37-
SnoozedUntil = now.AddMinutes(15)
38-
};
35+
{
36+
State = NotificationState.Snoozed,
37+
SnoozedUntil = now.AddMinutes(15)
38+
};
3939

4040
var read = NotificationStateMachine.MarkRead(notification, now);
4141

0 commit comments

Comments
 (0)