-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
State part rework, error handling on blazor exceptions
- Loading branch information
Showing
16 changed files
with
222 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,55 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using OpenShock.SDK.CSharp.Live; | ||
using OpenShock.SDK.CSharp.Live.LiveControlModels; | ||
using Color = MudBlazor.Color; | ||
|
||
namespace OpenShock.ShockOsc.Ui.Components.Parts; | ||
|
||
public partial class StatePart : ComponentBase | ||
public partial class StatePart : ComponentBase, IDisposable | ||
{ | ||
[Parameter] | ||
public required Color IconColor { get; set; } | ||
public required IOpenShockLiveControlClient Client { get; set; } | ||
|
||
[Parameter] | ||
public required string Icon { get; set; } | ||
public required string Text { get; set; } | ||
|
||
|
||
[Parameter] | ||
public required string Tooltip { get; set; } | ||
private Task StateOnValueChanged(WebsocketConnectionState state) | ||
{ | ||
return InvokeAsync(StateHasChanged); | ||
} | ||
|
||
[Parameter] | ||
public required string Text { get; set; } | ||
private Color GetConnectionStateColor() => | ||
Client.State.Value switch | ||
{ | ||
WebsocketConnectionState.Connected => Color.Success, | ||
WebsocketConnectionState.Reconnecting => Color.Warning, | ||
WebsocketConnectionState.Connecting => Color.Warning, | ||
WebsocketConnectionState.Disconnected => Color.Error, | ||
_ => Color.Error | ||
}; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Client.State.OnValueChanged += StateOnValueChanged; | ||
Client.Latency.OnValueChanged += LatencyOnValueChanged; | ||
} | ||
|
||
private Task LatencyOnValueChanged(ulong arg) | ||
{ | ||
return InvokeAsync(StateHasChanged); | ||
} | ||
|
||
private bool _disposed = false; | ||
|
||
public void Dispose() | ||
{ | ||
if (_disposed) return; | ||
_disposed = true; | ||
|
||
Client.State.OnValueChanged -= StateOnValueChanged; | ||
Client.Latency.OnValueChanged -= LatencyOnValueChanged; | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
<h3>DashboardTab</h3> | ||
|
||
<MudButton OnClick="() => throw new Exception()">Yes</MudButton> | ||
|
||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@inject ISnackbar Snackbar | ||
|
||
<MudPaper Class="rounded-lg mud-paper-padding ex-code-block" Outlined="true"> | ||
<pre class="code"> | ||
@Value | ||
</pre> | ||
<MudIconButton Icon="@Icons.Material.Outlined.FileCopy" Size="Size.Small" Class="copy-code-button" | ||
@onclick="CopyTextToClipboard"/> | ||
</MudPaper> | ||
|
||
<style> | ||
.ex-code-block { | ||
position: relative; | ||
background-color: #2a2a2a; | ||
width: 100%; | ||
} | ||
.ex-code-block .code { | ||
outline: 0; | ||
background-color: #2a2a2a; | ||
color: var(--mud-palette-text-primary); | ||
border-radius: 5px; | ||
text-align: left; | ||
overflow: auto; | ||
} | ||
.ex-code-block .copy-code-button { | ||
position: absolute; | ||
right: 10px; | ||
bottom: 10px; | ||
background: var(--mud-palette-surface); | ||
} | ||
</style> | ||
|
||
@code { | ||
[Parameter] public string Value { get; set; } | ||
|
||
private async Task CopyTextToClipboard() | ||
{ | ||
await Clipboard.SetTextAsync(Value); | ||
Snackbar.Add("Copied to clipboard", Severity.Success); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
ShockOsc/Ui/ErrorHandling/ContainerWithExceptionHandling.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div @attributes="Attributes"> | ||
<ErrorBoundary @ref="_boundary"> | ||
<ChildContent> | ||
@ChildContent | ||
</ChildContent> | ||
<ErrorContent Context="ex"> | ||
<ExceptionView Exception="ex" OnResume="() => _boundary.Recover()"></ExceptionView> | ||
</ErrorContent> | ||
</ErrorBoundary> | ||
</div> | ||
|
||
@code { | ||
|
||
[Parameter(CaptureUnmatchedValues = true)] | ||
public Dictionary<string, object> Attributes { get; set; } | ||
|
||
[Parameter] public RenderFragment ChildContent { get; set; } | ||
|
||
private ErrorBoundary _boundary = null!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@using System.Diagnostics | ||
|
||
<MudContainer Class="align-content-center" MaxWidth="MaxWidth.Medium" Style="padding-top: 30px"> | ||
<MudPaper Class="rounded-lg" Elevation="0" Style="padding: 40px 20px; text-align: center;" Outlined="true"> | ||
<MudText Typo="Typo.h3">An unknown error occurred</MudText> | ||
<br/> | ||
<MudText Typo="Typo.h6">Please report this to us on GitHub</MudText> | ||
|
||
<CodeBlock Value="@Exception.ToString()"></CodeBlock> | ||
<br/> | ||
|
||
<MudButton IconClass="@Icons.Material.Filled.Link" OnClick="OpenGithub" Variant="Variant.Filled" | ||
Color="Color.Primary"> | ||
Open Github | ||
</MudButton> | ||
<MudButton OnClick="() => OnResume.InvokeAsync()" Variant="Variant.Filled" Color="Color.Primary"> | ||
Resume | ||
</MudButton> | ||
|
||
</MudPaper> | ||
</MudContainer> | ||
|
||
@code { | ||
|
||
/// <summary> | ||
/// Resume button click event | ||
/// </summary> | ||
[Parameter] | ||
public EventCallback<MouseEventArgs> OnResume { get; set; } | ||
|
||
/// <summary> | ||
/// Exception to display | ||
/// </summary> | ||
[Parameter] | ||
public Exception Exception { get; set; } | ||
|
||
private void OpenGithub() | ||
{ | ||
Process.Start(new ProcessStartInfo("https://github.com/OpenShock/ShockOsc/issues/new/choose") { UseShellExecute = true }); | ||
} | ||
} |
Oops, something went wrong.