jsakamoto / Toolbelt.Blazor.HotKeys2

This is a class library that provides configuration-centric keyboard shortcuts for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.HotKeys2/
Mozilla Public License 2.0
87 stars 5 forks source link

Hotkeys2 and MAUI Blazor Hybrid compatibility #17

Open tnglemongrass opened 3 months ago

tnglemongrass commented 3 months ago

I try to use the Hotkeys2 library in a MAUI Blazor Hybrid App with .NET 8, following the instructions from the Hotkeys2 README.

Maybe there is just something missing in the README instructions?

Description:

When using the HotKeys2 library in a Maui Blazor Hybrid App, an error/warning is displayed on startup. However, the app runs fine and hotkeys work as expected.

Steps to Reproduce:

Expected Behavior:

There should be no errors or warnings on startup.

Actual Behavior:

The following error message is displayed on startup:

Toolbelt.Blazor.HotKeys2.HotKeys: Error: Could not find 'Toolbelt.Blazor.getProperty' ('Toolbelt' was undefined).
Error: Could not find 'Toolbelt.Blazor.getProperty' ('Toolbelt' was undefined).

Additional Information:

The app runs fine and hotkeys work as expected, despite the error message.

A minimal reproducible example is here: https://github.com/tnglemongrass/ToolbeltHotkeys2Demo/

jsakamoto commented 3 months ago

@tnglemongrass Thank you for letting me know about the problem. I must have overlooked the Blazor Hybrid scenario. As a workaround for a while, could you try to add one <script> tag in the wwwroot/index.html for the content, "_content/Toolbelt.Blazor.GetProperty.Script/Toolbelt.Blazor.GetProperty.Script.lib.module.js", like the following pull request?

https://github.com/tnglemongrass/ToolbeltHotkeys2Demo/pull/1

Actually, I've never tried that workaround on my side yet because I've been a bit busy these weeks. I'm sorry for that. Anyway, I hope the workaround above works well. (And I'd like to fix this problem someday.)

tnglemongrass commented 3 months ago

@jsakamoto Yes, including that script tag fixes it. Thanks for looking into it and thanks a lot for that workaround!

fingers10 commented 3 months ago

@jsakamoto I was also having the same issue when trying to run ilovedotnet blazor wasm project via blazor hybrid project... Adding the script as mentioned solves the exception.

You can use https://github.com/ILoveDotNet/ilovedotnet/tree/main/MAUI to test.

jsakamoto commented 6 days ago

[FYI] This problem is a bug in the .NET SDK.

See also: https://github.com/dotnet/maui/issues/15234

Fortunately, I've verified the problem went away on the .NET 9 SDK Preview 5. So, please take the workaround of explicitly adding a script loading as below until the release of the .NET 9 SDK.

<!-- wwwroot/index.html -->
<!-- 👇 Add this script tag before the script tag, which loads the "blazor.webview.js" JavaScript file. -->
<script src="_content/Toolbelt.Blazor.GetProperty.Script/Toolbelt.Blazor.GetProperty.Script.lib.module.js" type="module"></script>