Skip to content

Commit c4e0a41

Browse files
committed
fix: harden tray speech text selection
1 parent c525e74 commit c4e0a41

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎src/OpenClaw.Tray.WinUI/App.xaml.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@ private void OnGatewayNotificationReceived(object? sender, OpenClawNotification
27472747
// if the user enabled "Read responses aloud".
27482748
if (notification.IsChat && !string.IsNullOrEmpty(notification.Message))
27492749
{
2750-
var speechText = notification.FullMessage ?? notification.Message;
2750+
var speechText = ChatNotificationSpeechText.Resolve(notification);
27512751

27522752
// Suppress TTS/voice overlay when the user has aborted the response.
27532753
if (ChatProvider?.IsResponseSuppressed == true)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using OpenClaw.Shared;
2+
3+
namespace OpenClawTray.Services;
4+
5+
internal static class ChatNotificationSpeechText
6+
{
7+
public static string Resolve(OpenClawNotification notification)
8+
{
9+
ArgumentNullException.ThrowIfNull(notification);
10+
return string.IsNullOrEmpty(notification.FullMessage)
11+
? notification.Message
12+
: notification.FullMessage;
13+
}
14+
}

‎tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\ToastActivationRouter.cs" Link="Services\ToastActivationRouter.cs" />
7474
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\AppNotificationService.cs" Link="Services\AppNotificationService.cs" />
7575
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\AppNotificationMapper.cs" Link="Services\AppNotificationMapper.cs" />
76+
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\ChatNotificationSpeechText.cs" Link="Services\ChatNotificationSpeechText.cs" />
7677
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\AppNotificationPublisher.cs" Link="Services\AppNotificationPublisher.cs" />
7778
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\ConnectionStatusPresenter.cs" Link="Services\ConnectionStatusPresenter.cs" />
7879
<Compile Include="..\..\src\OpenClaw.Tray.WinUI\Services\McpRuntimeStatePolicy.cs" Link="Services\McpRuntimeStatePolicy.cs" />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using OpenClaw.Shared;
2+
using OpenClawTray.Services;
3+
using Xunit;
4+
5+
namespace OpenClaw.Tray.Tests.Services;
6+
7+
public sealed class ChatNotificationSpeechTextTests
8+
{
9+
[Fact]
10+
public void Resolve_UsesFullMessageWhenPreviewWasTruncated()
11+
{
12+
var fullMessage = new string('x', 240);
13+
14+
var resolved = ChatNotificationSpeechText.Resolve(new OpenClawNotification
15+
{
16+
Message = fullMessage[..200] + "…",
17+
FullMessage = fullMessage
18+
});
19+
20+
Assert.Equal(fullMessage, resolved);
21+
}
22+
23+
[Theory]
24+
[InlineData(null)]
25+
[InlineData("")]
26+
public void Resolve_FallsBackToPreviewWhenFullMessageIsUnavailable(string? fullMessage)
27+
{
28+
var resolved = ChatNotificationSpeechText.Resolve(new OpenClawNotification
29+
{
30+
Message = "Preview",
31+
FullMessage = fullMessage
32+
});
33+
34+
Assert.Equal("Preview", resolved);
35+
}
36+
}

0 commit comments

Comments
 (0)