Initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
@using RobotNet10.ScriptEditor.Clients
|
||||
@using Microsoft.JSInterop
|
||||
@inject ConsoleHubClient HubClient
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<div class="console-container">
|
||||
<div class="console-header">
|
||||
<div class="console-header-left">
|
||||
<button class="btn btn-sm btn-outline-secondary btn-toggle" onclick="robotnet.console.toggleCollapse()" title="Toggle Console">
|
||||
<span class="mdi mdi-chevron-down"></span>
|
||||
</button>
|
||||
<span>Console</span>
|
||||
</div>
|
||||
<div class="console-actions">
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="ToggleAutoScroll" title="@(_autoScroll ? "Disable" : "Enable") Auto Scroll">
|
||||
<span class="@(_autoScroll ? "mdi mdi-arrow-down-bold" : "mdi mdi-arrow-down-bold-outline")"></span>
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="ClearLogs" title="Clear Console">
|
||||
<span class="mdi mdi-delete"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="console-content" id="console-content">
|
||||
<!-- Messages will be added via JavaScript -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool _autoScroll = true;
|
||||
private DotNetObjectReference<Console>? _objRef;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Đăng ký events từ HubClient
|
||||
HubClient.ErrorReceived += OnErrorReceived;
|
||||
HubClient.InfoReceived += OnInfoReceived;
|
||||
HubClient.WarningReceived += OnWarningReceived;
|
||||
|
||||
// Kết nối đến hub nếu chưa connected
|
||||
if (!HubClient.IsConnected)
|
||||
{
|
||||
await HubClient.StartAsync();
|
||||
}
|
||||
|
||||
// Đảm bảo đã connected trước khi đăng ký
|
||||
if (HubClient.IsConnected)
|
||||
{
|
||||
// Đăng ký nhận tất cả console messages
|
||||
await HubClient.RegisterAllAsync();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
_objRef = DotNetObjectReference.Create(this);
|
||||
await JSRuntime.InvokeVoidAsync("robotnet.console.init", _objRef);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnErrorReceived(string message)
|
||||
{
|
||||
_ = JSRuntime.InvokeVoidAsync("robotnet.console.addMessage", "ERROR", message, _autoScroll);
|
||||
}
|
||||
|
||||
private void OnInfoReceived(string message)
|
||||
{
|
||||
_ = JSRuntime.InvokeVoidAsync("robotnet.console.addMessage", "INFO", message, _autoScroll);
|
||||
}
|
||||
|
||||
private void OnWarningReceived(string message)
|
||||
{
|
||||
_ = JSRuntime.InvokeVoidAsync("robotnet.console.addMessage", "WARN", message, _autoScroll);
|
||||
}
|
||||
|
||||
private async Task ClearLogs()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("robotnet.console.clear");
|
||||
}
|
||||
|
||||
private void ToggleAutoScroll()
|
||||
{
|
||||
_autoScroll = !_autoScroll;
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
HubClient.ErrorReceived -= OnErrorReceived;
|
||||
HubClient.InfoReceived -= OnInfoReceived;
|
||||
HubClient.WarningReceived -= OnWarningReceived;
|
||||
|
||||
_objRef?.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user