Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyboard shortcuts, url casing and JSDisconnectedException #2466

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using Aspire.Dashboard.Extensions;
using Aspire.Dashboard.Model;
using Aspire.Dashboard.Utils;
using Microsoft.AspNetCore.Components;
Expand Down Expand Up @@ -188,7 +189,7 @@ private void SetPanelSizes(float panel1Fraction)

public async Task OnPageKeyDownAsync(KeyboardEventArgs args)
{
if (_splitterRef is null || !args.ShiftKey)
if (_splitterRef is null || !args.OnlyShiftPressed())
{
return;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Dashboard.Components.Dialogs;
using Aspire.Dashboard.Extensions;
using Aspire.Dashboard.Model;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
Expand Down Expand Up @@ -153,7 +154,7 @@ public async Task LaunchSettingsAsync()

public async Task OnPageKeyDownAsync(KeyboardEventArgs args)
{
if (args.ShiftKey)
if (args.OnlyShiftPressed())
{
if (args.Key is "?")
{
Expand All @@ -164,15 +165,15 @@ public async Task OnPageKeyDownAsync(KeyboardEventArgs args)
await LaunchSettingsAsync();
}
}
else
else if (args.NoModifiersPressed())
{
var url = args.Key.ToLower() switch
{
"r" => "/",
"c" => "/ConsoleLogs",
"s" => "/StructuredLogs",
"t" => "/Traces",
"m" => "/Metrics",
"c" => "/consolelogs",
"s" => "/structuredlogs",
"t" => "/traces",
"m" => "/metrics",
_ => null
};

Expand All @@ -189,7 +190,7 @@ public async ValueTask DisposeAsync()
_themeChangedSubscription?.Dispose();
_locationChangingRegistration?.Dispose();
ShortcutManager.RemoveGlobalKeydownListener(this);

try
{
await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers);
Expand Down
19 changes: 19 additions & 0 deletions src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.Web;

namespace Aspire.Dashboard.Extensions;

internal static class KeyboardEventArgsExtensions
{
public static bool NoModifiersPressed(this KeyboardEventArgs args)
{
return !args.AltKey && !args.CtrlKey && !args.MetaKey && !args.ShiftKey;
}

public static bool OnlyShiftPressed(this KeyboardEventArgs args)
{
return args.ShiftKey && !args.AltKey && !args.CtrlKey && !args.MetaKey;
}
}