Verify Extension project: Use WebKit to render a Blazor UI
There is https://github.com/JinShil/BlazorWebView which allows using a Blazor App inside Webkit.
Consider if there should be something similar for Gir.Core and if it should be part of Gir.Core.
Some work was done to port it to use Gir.Core: https://github.com/czirok/BlazorWebView/tree/gircore4 / https://github.com/badcel/BlazorWebView
Alternatively link to the project on the homepage.
Hi! π
Iβve been working on a more advanced version of the BlazorWebView, beyond what I proposed in this pull request:
π https://github.com/JinShil/BlazorWebView/pull/3
Improvements:
- Support for opening external links.
- Integrated GtkDispatcher support.
About GtkDispatcher:
- The GTK/Adwaita app must be launched via
RunWithSynchronizationContext(). - This sets the current
SynchronizationContexttoGLib.Internal.MainLoopSynchronizationContext. - The
GirCore.Blazor.GtkDispatcherthen connectsWebViewManager.DispatcherfromMicrosoft.AspNetCore.Components.WebViewto the GTK main thread, so the Blazor UI is properly updated on the GTK/Adw main loop.
Folder structure
Currently, the folder structure for GirCore.Blazor looks like this:
gir.core/src/Blazor
βββ Directory.Build.props
βββ Directory.Packages.props
βββ GirCore.Blazor.sln
βββ WebView/ # Library implementation (GtkDispatcher, BlazorWebView)
β βββ BlazorWebView.cs
β βββ Extensions
β βΒ Β βββ AddBlazorWebView.cs
β βΒ Β βββ AddDispatcher.cs
β βββ GirCore.Blazor.csproj
β βββ GtkDispatcher.cs
βββ Sample/ # Minimal example Blazor UI using the library
Β Β βββ Sample.csproj
Iβd like to ask your opinion on how you'd prefer the structure to be. Iβm happy to adjust everything exactly as you'd like it to fit the overall layout and standards of the GirCore repository. Let me know your preferences, Iβll gladly restructure accordingly.
How about bringing your Update to JinShils repository?
I would like to see to have some ecosystem around GirCore. This brings more developers into the C# combined with Linux ecosystem. Each developer can work independently but at the same time contribute to all the others.
If JinShil does not want to continue development we can try bring the code here (separate repo?) and try gather several developers of the other WebView implementations.
I already saw several implementations based on the original code so I think there is some interest in having the possibility to easily bring blazor hybrid apps to Linux.
Letβs bring @JinShil into the conversation and ask for his thoughts on this.
As I'm actively using this BlazorWebView in my own project, I'm also happy to maintain it in a separate repository if thatβs preferred.
I've pushed the latest changes to a new branch:
https://github.com/czirok/BlazorWebView/tree/gircore.blazor
It can be tested directly by following the steps outlined in the README.
Included changes:
Switch to GtkDispatcher; add central package management; support .NET 8 and 9
- Replaced
Dispatcher.CreateDefault()with customGtkDispatcher, using a GLib-compatibleIDispatcherimplementation. - Removed GTK
InputStreamworkaround; now usingGio.MemoryInputStream.NewFromBytes()directly. -
WebViewManagernow implementsIAsyncDisposable, ensuring proper disconnection ofScriptMessageReceivedSignalviaDisposeAsyncCore(). - Added
NavigationSignalHandlerto redirect external link clicks to the system browser. - Introduced central package management via
Directory.Packages.props. -
Microsoft.AspNetCore.Components.WebandMicrosoft.AspNetCore.Components.WebViewpackages are not version-compatible between .NET 8 and 9. These are now handled separately to support both frameworks.
I'm not sure what's being asked of me, but here are my thoughts.
I'm under the impression that Gir.Core exists to provide a C# API for GObject-based libraries. It seems adding BlazorWebView to Gir.Core expands the scope of what Gir.Core is aiming to provide. Perhaps a separate repository, or set of repositories that build on top of Gir.Core is where BlazorWebView belongs.
Perhaps Gir.Core can just add a growing list of "libraries and applications that use Gir.Core" to Gir.Core's README, with BlazorWebView being just one of many in that list.
You're welcome to submit pull requests to BlazorWebView. I'll pull them as long as I can understand them, and they keep the scope to "Blazor WebView/Hybrid on Linux".
You're also welcome to take ownership of BlazorWebView. Feel free to fork it, or copy code from it into your own repository and make it awesome. I'll then archive BlazorWebView and point visitors to new repository. I'm only maintaining BlazorWebView because I'm not aware of a better implementation. As soon as a better implementation exists, my part in this story ends.
In order to port my blazor hybrid application to Linux, I also created a blazorwebview and tried to emulate the Blazorview of WinForm and WPF as much as possible, for example UrlLoading, StartPath, BlazorWebViewInitializing, BlazorWebViewInitialized https://github.com/Yu-Core/BlazorWebView.Gtk Hope it can help you
Update: NuGet package is now available
After years of development and testing, the WebKit Blazor integration for GirCore is ready and published:
WebKit.BlazorWebView.GirCore - Blazor applications as native Linux desktop apps
I will keep the "-preview" in the version number until the 0.7 release.
dotnet add package WebKit.BlazorWebView.GirCore
Special thanks to @JinShil for the original BlazorWebView and @badcel for GirCore!
Additional packages in the ecosystem:
The two most beautiful applications with lots of examples:
Gtk.MauiGraphicsSkia.GirCore - GTK4/Maui Graphics integration SkiaSharp.Views.GirCore - SkiaSharp graphics on Linux
And a little binding:
EasyUIBinding.GirCore - Declarative UI binding for GTK4/Libadwaita
Complete examples and documentation: https://github.com/czirok/apps
@badcel badcel: If you have any objections to the .GirCore suffix at the end of the packages, I will change it. But I thought this way developers can be informed that it is built around GirCore.
It's fine to keep the reference.
If you like to add a an entry onto a "eco system" page on the homepage I could prepare it so that there is one place to list the GirCore surrounding nuget packages.
It's fine to keep the reference.
If you like to add a an entry onto a "eco system" page on the homepage I could prepare it so that there is one place to list the GirCore surrounding nuget packages.
That would be amazing, I'd be happy.
You can add the nuget packages here: https://github.com/gircore/gir.core/blob/main/docs/docs/ecosystem.md