gir.core icon indicating copy to clipboard operation
gir.core copied to clipboard

Verify Extension project: Use WebKit to render a Blazor UI

Open badcel opened this issue 2 years ago β€’ 9 comments

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.

badcel avatar Aug 29 '23 07:08 badcel

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 SynchronizationContext to GLib.Internal.MainLoopSynchronizationContext.
  • The GirCore.Blazor.GtkDispatcher then connects WebViewManager.Dispatcher from Microsoft.AspNetCore.Components.WebView to 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.

czirok avatar Apr 21 '25 20:04 czirok

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.

badcel avatar Apr 24 '25 05:04 badcel

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 custom GtkDispatcher, using a GLib-compatible IDispatcher implementation.
  • Removed GTK InputStream workaround; now using Gio.MemoryInputStream.NewFromBytes() directly.
  • WebViewManager now implements IAsyncDisposable, ensuring proper disconnection of ScriptMessageReceivedSignal via DisposeAsyncCore().
  • Added NavigationSignalHandler to redirect external link clicks to the system browser.
  • Introduced central package management via Directory.Packages.props.
  • Microsoft.AspNetCore.Components.Web and Microsoft.AspNetCore.Components.WebView packages are not version-compatible between .NET 8 and 9. These are now handled separately to support both frameworks.

czirok avatar Apr 24 '25 10:04 czirok

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.

JinShil avatar Apr 24 '25 13:04 JinShil

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

Yu-Core avatar Jun 15 '25 05:06 Yu-Core

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.

czirok avatar Jul 14 '25 11:07 czirok

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.

badcel avatar Jul 14 '25 12:07 badcel

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.

czirok avatar Jul 14 '25 12:07 czirok

You can add the nuget packages here: https://github.com/gircore/gir.core/blob/main/docs/docs/ecosystem.md

badcel avatar Jul 15 '25 18:07 badcel