Skip to content

Commit

Permalink
Fix keyboard shortcuts, url casing and JSDisconnectedException (#2466)
Browse files Browse the repository at this point in the history
* Fix keyboard shortcuts and url casing

* Suppress JSDisconnectedException

* Check MetaKey and refactor modifier key checks

---------

Co-authored-by: Adam Ratzman <[email protected]>
  • Loading branch information
tlmii and adamint authored Feb 27, 2024
1 parent 24c33db commit 197c21e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
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;
}
}

0 comments on commit 197c21e

Please sign in to comment.