From 435d958956a43b4fb7bc208202608661cd7cc861 Mon Sep 17 00:00:00 2001 From: Tim Mulholland Date: Mon, 26 Feb 2024 21:40:37 -0800 Subject: [PATCH 1/5] Untrack DialogReference when dialog is closed --- .../Components/Layout/MainLayout.razor.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index c6a19ef9ea..c4123bed58 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -101,7 +101,8 @@ private async Task LaunchHelpAsync() Alignment = HorizontalAlignment.Center, Width = "700px", Height = "auto", - Id = HelpDialogId + Id = HelpDialogId, + OnDialogResult = EventCallback.Factory.Create(this, HandleDialogResult) }; if (_openPageDialog is not null) @@ -117,6 +118,11 @@ private async Task LaunchHelpAsync() _openPageDialog = await DialogService.ShowDialogAsync(parameters).ConfigureAwait(true); } + private void HandleDialogResult(DialogResult dialogResult) + { + _openPageDialog = null; + } + public async Task LaunchSettingsAsync() { DialogParameters parameters = new() @@ -130,7 +136,8 @@ public async Task LaunchSettingsAsync() Alignment = HorizontalAlignment.Right, Width = "300px", Height = "auto", - Id = SettingsDialogId + Id = SettingsDialogId, + OnDialogResult = EventCallback.Factory.Create(this, HandleDialogResult) }; if (_openPageDialog is not null) From f2cb39e67cc037e3f58b0d7e050e06e43bc4de27 Mon Sep 17 00:00:00 2001 From: Tim Mulholland Date: Mon, 26 Feb 2024 22:20:33 -0800 Subject: [PATCH 2/5] Fix keyboard shortcuts and url casing --- .../Components/Controls/SummaryDetailsView.razor.cs | 2 +- .../Components/Layout/MainLayout.razor.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs index f2035d686e..8ed55c2b53 100644 --- a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs +++ b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs @@ -184,7 +184,7 @@ private void SetPanelSizes(float panel1Fraction) public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (_splitterRef is null || !args.ShiftKey) + if (_splitterRef is null || !args.ShiftKey || args.AltKey || args.CtrlKey) { return; } diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index c6a19ef9ea..873cab691a 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -148,7 +148,7 @@ public async Task LaunchSettingsAsync() public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (args.ShiftKey) + if (args.ShiftKey && !args.CtrlKey && !args.AltKey) { if (args.Key is "?") { @@ -159,15 +159,15 @@ public async Task OnPageKeyDownAsync(KeyboardEventArgs args) await LaunchSettingsAsync(); } } - else + else if (!args.ShiftKey && !args.CtrlKey && !args.AltKey) { var url = args.Key.ToLower() switch { "r" => "/", - "c" => "/ConsoleLogs", - "s" => "/StructuredLogs", - "t" => "/Traces", - "m" => "/Metrics", + "c" => "/consolelogs", + "s" => "/structuredlogs", + "t" => "/traces", + "m" => "/metrics", _ => null }; From eae03aab05eadc63f1828c40d50a129c7be8aee2 Mon Sep 17 00:00:00 2001 From: Tim Mulholland Date: Mon, 26 Feb 2024 22:27:47 -0800 Subject: [PATCH 3/5] Suppress JSDisconnectedException --- .../Components/Layout/MainLayout.razor.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index 873cab691a..47938eda97 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -187,6 +187,14 @@ public void Dispose() public async ValueTask DisposeAsync() { - await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers); + try + { + await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers); + } + catch (JSDisconnectedException) + { + // Per https://learn.microsoft.com/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-7.0#javascript-interop-calls-without-a-circuit + // this is one of the calls that will fail if the circuit is disconnected, and we just need to catch the exception so it doesn't pollute the logs + } } } From 3ca097673a7466896b4b13f49ac62c4bb22b6567 Mon Sep 17 00:00:00 2001 From: Tim Mulholland Date: Mon, 26 Feb 2024 23:41:19 -0800 Subject: [PATCH 4/5] Check MetaKey and refactor modifier key checks --- .../Controls/SummaryDetailsView.razor.cs | 3 ++- .../Components/Layout/MainLayout.razor.cs | 5 +++-- .../Extensions/KeyboardEventArgsExtensions.cs | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs diff --git a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs index 8ed55c2b53..1882d33bdf 100644 --- a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs +++ b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs @@ -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.Utils; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; @@ -184,7 +185,7 @@ private void SetPanelSizes(float panel1Fraction) public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (_splitterRef is null || !args.ShiftKey || args.AltKey || args.CtrlKey) + if (_splitterRef is null || !args.OnlyShiftPressed()) { return; } diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index 47938eda97..d7b6e22f95 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -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; @@ -148,7 +149,7 @@ public async Task LaunchSettingsAsync() public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (args.ShiftKey && !args.CtrlKey && !args.AltKey) + if (args.OnlyShiftPressed()) { if (args.Key is "?") { @@ -159,7 +160,7 @@ public async Task OnPageKeyDownAsync(KeyboardEventArgs args) await LaunchSettingsAsync(); } } - else if (!args.ShiftKey && !args.CtrlKey && !args.AltKey) + else if (args.NoModifiersPressed()) { var url = args.Key.ToLower() switch { diff --git a/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs b/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs new file mode 100644 index 0000000000..37de21e8bb --- /dev/null +++ b/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs @@ -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; + } +} From 2f3491ff87320a8fd16fcd2c122fac8d5a2cfc3d Mon Sep 17 00:00:00 2001 From: "Ratzman, Adam Mortimer" Date: Tue, 27 Feb 2024 10:52:32 -0500 Subject: [PATCH 5/5] removed redundant extra OnDialogCloseRequested call --- .../Components/Layout/MainLayout.razor.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index 038e122602..efc7eb8bae 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -83,14 +83,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender) _shortcutManagerReference = DotNetObjectReference.Create(ShortcutManager); _keyboardHandlers = await JS.InvokeAsync("window.registerGlobalKeydownListener", _shortcutManagerReference); ShortcutManager.AddGlobalKeydownListener(this); - - DialogService.OnDialogCloseRequested += (reference, _) => - { - if (reference.Id is HelpDialogId or SettingsDialogId) - { - _openPageDialog = null; - } - }; } } @@ -197,7 +189,7 @@ public async ValueTask DisposeAsync() _themeChangedSubscription?.Dispose(); _locationChangingRegistration?.Dispose(); ShortcutManager.RemoveGlobalKeydownListener(this); - + try { await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers);