Skip to content

Commit a465fd5

Browse files
committed
fix: Only show server error when we have one
Leaving the server error box around was confusing users. There's no reason to leave it around if things are working now. Fixes #419
1 parent 63db5df commit a465fd5

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

Buttplug.Apps.ServerGUI/ServerControl.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="Buttplug.Apps.ServerGUI.ServerControl"
1+
<UserControl x:Class="Buttplug.Apps.ServerGUI.ServerControl"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -48,7 +48,7 @@
4848
<Label Name="ConnStatus" Content="(Not Connected)" Grid.Row="2" HorizontalAlignment="Left" Margin="72,4,0,0" VerticalAlignment="Top"/>
4949
<Button Name="DisconnectButton" Height="25" Grid.Row="2" Content="Disconnect" IsEnabled="False" HorizontalAlignment="Right" Margin="0,5,0,0" VerticalAlignment="Top" Width="75" Click="DisconnectButton_Click"/>
5050

51-
<Label Content="Last Error:" Grid.Row="3" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top"/>
51+
<Label Name="LastErrorLabel" Content="Error:" Grid.Row="3" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" Visibility="Hidden"/>
5252
<TextBlock Name="LastError" Text="" Grid.Row="3" HorizontalAlignment="Left" Margin="65,10,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>
5353
</Grid>
5454
</GroupBox>

Buttplug.Apps.ServerGUI/ServerControl.xaml.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public ServerControl(IButtplugServerFactory bpFactory)
8989
_log.OnLogException += ExceptionLogged;
9090
}
9191

92+
private void SetLastError(string aErrorMsg)
93+
{
94+
LastErrorLabel.Visibility = Visibility.Visible;
95+
LastError.Visibility = Visibility.Visible;
96+
LastError.Text = aErrorMsg;
97+
}
98+
99+
private void ClearLastError()
100+
{
101+
LastErrorLabel.Visibility = Visibility.Hidden;
102+
LastError.Visibility = Visibility.Hidden;
103+
LastError.Text = string.Empty;
104+
}
105+
92106
private void WebSocketExceptionHandler(object aObj, [NotNull] UnhandledExceptionEventArgs aEx)
93107
{
94108
_toastTimer.Enabled = true;
@@ -120,6 +134,8 @@ private void WebSocketConnectionAccepted(object aObj, [NotNull] ConnectionEventA
120134
{
121135
ConnStatus.Content = "(Connected) " + aEvent.ClientName;
122136
DisconnectButton.IsEnabled = true;
137+
// We've gotten a connection, clear the last error.
138+
ClearLastError();
123139
});
124140
}
125141

@@ -162,7 +178,7 @@ private void ExceptionLogged(object aObj, [NotNull] LogExceptionEventArgs aEvent
162178
Dispatcher.InvokeAsync(() =>
163179
{
164180
// Show the error message in the app
165-
LastError.Text = aEvent.ErrorMessage;
181+
SetLastError(aEvent.ErrorMessage);
166182
});
167183
_toastTimer.Enabled = true;
168184
}
@@ -203,6 +219,9 @@ public void StartServer()
203219
ConnStatus.Content = "(Not Connected)";
204220
DisconnectButton.IsEnabled = false;
205221
ConnInfo.IsEnabled = true;
222+
223+
// We've brought the server up, clear the error.
224+
ClearLastError();
206225
}
207226
catch (SocketException e)
208227
{

0 commit comments

Comments
 (0)