jsuarezruiz / maui-linux

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://devblogs.microsoft.com/dotnet/introducing-net-multi-platform-app-ui/
MIT License
834 stars 35 forks source link

[Enhancement] BlazorWebView #28

Open CommonLoon102 opened 2 years ago

CommonLoon102 commented 2 years ago

Summary

To enable MAUI Blazor apps, a BlazorWebView will be needed. Related discussion: https://github.com/dotnet/maui/discussions/1521

API Changes

New BlazorWebView component. Since there is no Edge WebView2 for Linux so far, maybe libwebkit2gtk could be used? Related issue for WebView on Linux: https://github.com/MicrosoftEdge/WebView2Feedback/issues/645

Intended Use Case

Create MAUI Blazor apps. This way developers can write the UI in HTML (razor), CSS and C# via (re)using Blazor components.

CommonLoon102 commented 2 years ago

Maybe it doesn't worth to wait for WebView2 because it is quite frowned on by the free software community due to its vague user data collection habits: https://github.com/MicrosoftEdge/WebView2Feedback/issues/916

CommonLoon102 commented 2 years ago

Related: https://github.com/lytico/maui/issues/9 https://github.com/lytico/maui/issues/1

CommonLoon102 commented 2 years ago

I found a sample in Pascal, how to run javascript and get the results via WebKit: https://github.com/eugenekryukov/crosswebview/blob/7848d3803abe04c61c1f5901a9cdbb1d4cecccf9/CVcl.WebView.Linux.pas#L323

This is basically the only thing needed for BlazorWebView. Of course we need to use async/await instead of busy wait.

This is the MAUI implementation for WebKit on Android: https://github.com/dotnet/maui/blob/main/src/BlazorWebView/src/Maui/Android/WebKitWebViewClient.cs

PostWebMessage: https://github.com/dotnet/maui/blob/96886c3a02a11ef2d8aebad60e3e923047f99b3b/src/BlazorWebView/src/Maui/Android/AndroidWebKitWebViewManager.cs#L49 is just this: https://developer.android.com/reference/android/webkit/WebView#postWebMessage(android.webkit.WebMessage,%20android.net.Uri) https://html.spec.whatwg.org/multipage/web-messaging.html#posting-messages https://developer.android.com/reference/android/webkit/WebMessage https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/webkit/WebView.java?q=postwebmessage&ss=android%2Fplatform%2Fsuperproject

Maybe using the iOS implementation would be easier because the Android WebView has CreateWebMessageChannel() and WebKit WebView doesn't have it. https://github.com/dotnet/maui/blob/96886c3a02a11ef2d8aebad60e3e923047f99b3b/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs#L25 But it needs the user scripts api (webkit_user_content_manager_add_script and webkit_user_content_manager_register_script_message_handler, webkit_settings_set_enable_developer_extras).

https://raw.githubusercontent.com/gircore/gir-files/master/WebKit2-4.0.gir

lytico commented 2 years ago

GtkSharp-Webkit support is done, see: https://github.com/GtkSharp/GtkSharp/pull/271

the current problem is the lack of support of js-engine in GtkSharp see: https://github.com/GtkSharp/GtkSharp/pull/274

pha3z commented 2 years ago

Is there any movement on this? I want to be all-in on a project that uses BlazorWebView for full xplat development, but my project must support ios, android, windows, macos and most definitely linux.

CommonLoon102 commented 1 year ago

https://github.com/JinShil/BlazorWebView

lytico commented 1 year ago

i try to adopt it, and get nearer to gktsharp: https://github.com/lytico/GtkSharp.BlazorWebView/tree/lytico/ongoing

the good thing is, it don't use JavaScriptCore-Lib, so https://github.com/GtkSharp/GtkSharp/pull/274 is not needed

CommonLoon102 commented 1 year ago

Something is happening: https://github.com/lytico/GtkSharp.BlazorWebView/compare/lytico/ongoing...JinShil:BlazorWebView:main

@czirok maybe it would be a good idea to join forces.

lytico commented 1 year ago

@CommonLoon102 even more is happening: https://github.com/jsuarezruiz/maui-linux/pull/62

lytico commented 1 year ago

current state: Peek 2023-09-14 03-51

CommonLoon102 commented 12 months ago

Very impressive. So this would be part of MAUI for Linux, right? What else do we need/have to have a minimal usable thing? You have GTK Window and Tab Control as I can see on the video. What would be still needed is Gnome notification integration, and menubar (at the top of the app/window). What else?

Actually, the top menu bar could be just replaced by HTML as well.

What about OS notifications? If WebKit could do it via JavaScript, that could be triggered by the app itself as well.

charleypeng commented 11 months ago

current state: Peek 2023-09-14 03-51

this is awesome ! Is it possible to port to avalonia? I am going to take a look at this code.

lytico commented 5 months ago

merged into/implemented in: https://github.com/jsuarezruiz/maui-linux/pull/66