Haltroy / Yorot.Avalonia

A web browser.
MIT License
1 stars 0 forks source link

Desktop Cross-platform Support #21

Open Haltroy opened 1 year ago

Haltroy commented 1 year ago

Yorot.Avalonia, the official Yorot flavor uses CefNet, a wrapper around the Chromium Embedded Framework that is cross-platform. This flavor also uses AvaloniaUI which is cross-platform graphical user interface library with Model-View-View-Model function so developers can dynamically update the UI more easily.

I dualboot endeavourOS (basically Arch but purple) with Windows 11 . Meaning that I can test Yorot with a general installation of Linux and Windows.

Currently, I developed Yorot in Windows 11 with Visual Studio and it works in there. However, neither of the Linux distributions that I tried (Arch, my Fedora, Debian) can't run Yorot for some reason. Here's my attempt.

Current situation is this:

Current ToDo (might change a lot):

UPDATE 23 March 2023

The Cefnet Avalonia Examples are working on Linux and Windows. My main goal is to remove the original "Yorot-Avalonia" C# project and copy everything into the working project.

And I already did move couple of classes and as right now they all work.

Current TODO (might change a lot):

Haltroy commented 1 year ago

Created branch "multithread" for this issue

Haltroy commented 1 year ago

I figured out what is happening.

The multi-thread thing is actually isn't launching CEF but well Yorot.

It launches Yorot with these arguments: --type=utility --utility-sub-type=network.mojom.NetworkService --lang=tr --service-sandbox-type=none --no-sandbox --locales-dir-path=C:\Users\haltroy\.yorot\cef\locales --log-severity=warning --resources-dir-path=C:\Users\haltroy\.yorot\cef --user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.3.18.0 Safari/537.36 Yorot/indev1 --lang=tr --user-data-dir=C:\Users\haltroy\.yorot\user\haltroy\cache --log-file=D:\Source\Yorot\src\Yorot.Avalonia\bin\Debug\net6.0\win-x64\debug.log --mojo-platform-channel-handle=3244 --field-trial-handle=2264,i,3432012375400430736,962543082477696034,131072 --disable-features=BackForwardCache,CalculateNativeWinOcclusion,WinUseBrowserSpellChecker /prefetch:8

[Sarcasm Starts Here] Let's play: What's inside a CEF multi-thread argument?

Remember the GPU process isn't usable. Goodbye. thing? Yeah, that happens because instead of CefNet launching itself, it launches shit ton of Yorot with the arguments listed in up there. It launches Yorot, expecting a GPU process but then crashes cuz simply YOROT IS NOT CHROMIUM and tries 10 times to make sure it launches, fucking fails ((WONDER WHY)) then fucking runs away by saying the most saddestGoobye. I ever seen.

[1111/111324.205856:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.205881:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 1 time(s)
[1111/111324.206963:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.206988:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 2 time(s)
[1111/111324.207687:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.207708:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 3 time(s)
[1111/111324.208492:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.208514:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 4 time(s)
[1111/111324.209309:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.209360:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 5 time(s)
[1111/111324.210042:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.210058:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 6 time(s)
[1111/111324.211039:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.211091:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 7 time(s)
[1111/111324.211812:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.211846:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 8 time(s)
[1111/111324.212792:ERROR:gpu_process_host.cc(959)] GPU process launch failed: error_code=1002
[1111/111324.212856:WARNING:gpu_process_host.cc(1267)] The GPU process has crashed 9 time(s)
[1111/111324.212929:FATAL:gpu_data_manager_impl_private.cc(454)] GPU process isn't usable. Goodbye.

But wait? If it launches the application that uses Chromium instead of idk CHROMIUIM ITSELF why did the AvaloniaApp worked? There's something obvious missing and I have no idea. The code is identical ((most of them are just copy-pasted)) but for no reason, I can't get Yorot working. Some of the code is for UI so I never touched MainWindows or WebView stuff. My priority is the multi-thread thing for now.

[finally, sarcasm ends here]]

Haltroy commented 1 year ago

Really quick updates

Finally found it. It now will partially initialize YorotMain on startup of every process and the main process which will show the window(s) will completely initialize the YorotMain. Also, the locale setting is global now.

Also, got rid of the WolfHook feature for now, need to think about how to talk to other main window from there without accidentally killing other threads.

Now it works on Windows, brb gonna reboot to Arch.

Haltroy commented 1 year ago

Tested on Alpine first, it gave an error saying Can't load libcef.so despite the file is actually there, I simply don't have any idea and gonna check that later.

On Arch, it just didn't launch any window and it seems that it launched some stuff like the GPU process and the network process but that's it.

[20/11/2022 12:43:03:1786603) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:2044077) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:2046665) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:2046846) [ProfileManager] Init done.

DevTools listening on ws://127.0.0.1:9222/devtools/browser/193ff1e3-e288-4217-913f-5fb224c699ce
[20/11/2022 12:43:03:4288498) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:4529282) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:45314) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:4531577) [ProfileManager] Init done.
[1120/124303.593506:WARNING:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process.
[20/11/2022 12:43:03:768754) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:7916992) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:7918559) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:7918694) [ProfileManager] Init done.

So, It loads everything correctly and nothing bad happens but nothing shows up. I simply have no idea why. Avalonia works on here, so i have to dig deeper. I have suspicion on Fluent Avalonia, which is used for TabView only and it's in beta. The devs of that might not planned it to work on other OS than Windows. nvm it works on my test project i just created so its something else.

Haltroy commented 1 year ago

In case someone else tries this and receives an error that looks like this:

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
   at CefNet.NativeMethods.dlopen(String path, Int32 mode)
   at CefNet.CefNetApplication.Initialize(String path, CefSettings settings)

Make sure glibc is installed. (Ex. Arch Linux Package: glibc). And just run this command before usingdotnet run: sudo ln -sf /usr/lib/$(ls /usr/lib/ | grep libdl.so) /usr/lib/libdl.so This is temporary solution until everything else is fixed, then I might add libdl itself to the package for your distro so no need to think about it.

Haltroy commented 1 year ago

Tested on Alpine first, it gave an error saying Can't load libcef.so despite the file is actually there, I simply don't have any idea and gonna check that later.

On Arch, it just didn't launch any window and it seems that it launched some stuff like the GPU process and the network process but that's it.

[20/11/2022 12:43:03:1786603) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:2044077) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:2046665) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:2046846) [ProfileManager] Init done.

DevTools listening on ws://127.0.0.1:9222/devtools/browser/193ff1e3-e288-4217-913f-5fb224c699ce
[20/11/2022 12:43:03:4288498) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:4529282) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:45314) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:4531577) [ProfileManager] Init done.
[1120/124303.593506:WARNING:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process.
[20/11/2022 12:43:03:768754) [Main] Developer mode activated.
 [I] (20/11/2022 12:43:03:7916992) [ProfileManager] Starting Init...
 [W] (20/11/2022 12:43:03:7918559) [ProfileManager] Loaded defaults, configuration file does not exists.
 [I] (20/11/2022 12:43:03:7918694) [ProfileManager] Init done.

So, It loads everything correctly and nothing bad happens but nothing shows up. I simply have no idea why. Avalonia works on here, so i have to dig deeper. ~I have suspicion on Fluent Avalonia, which is used for TabView only and it's in beta. The devs of that might not planned it to work on other OS than Windows.~ nvm it works on my test project i just created so its something else.

Tried the AvaloniaApp with Yorot.Standart with same stuff Yorot.Avalonia has and it still worked.

The problem is with the Yorot.Avalonia but I simply couldn't find it.

Haltroy commented 1 year ago

It only spawns the first renderer process and never creates another one which is the one probably making the actual render. Unlike any other CEF example, which spawns at least 2 renderer processes.

Anyways, I'm moving the WebView part of Yorot to another project file for subprocess stuff. Hopefully we can get it working with that.

Haltroy commented 1 year ago

Update: I moved the WebView part to another project, but it broke lots of stuff. Currently, only the popup window and initializing needs a fix. I hope the subprocess project self-executes itself instead of Yorot. I'll make a commit after ı'm done with those.

Haltroy commented 1 year ago

Tested on Fedora 37 KDE. It didn't spawn the renderer processes at all. GPU process is working without any issues and network utility always shows up without any issues. Still, CEF requires a "first renderer subprocess" and a "renderer process" for each tab.

Also, on Fedora, the libdl fix is: sudo ln -sf /usr/lib64/$(ls /usr/lib64/ | grep libdl.so) /usr/lib64/libdl.so because on Fedora it looks into the /usr/lib64 folder unlike in Arch which looks at /usr/lib folder while searching the library. This bug isn't just in Yorot, it is probably originating in CefNet or .NET.

For anyone catching up late, the libdl.so is a library (lib) for loading dynamic libraries (dl) for linux distros (.so).

Haltroy commented 1 year ago

Here's a list of all subprocesses and their arguments on each scenario I tested with.

Also, gonna upload the example app to GitHub tomorrow. Needs some minor guides. It's the AvaloniaApp project fromCefNet repositories, just replaced the project references with package references and a proper CEF library path.

debug.txt

Haltroy commented 1 year ago

Here's a list of all subprocesses and their arguments on each scenario I tested with. debug.txt

CefNet.Avalonia.Example

Yorot

Yorot (VS Debug)

Fedora 37 KDE

Haltroy commented 1 year ago

Published a new repository for CefNet examples: https://github.com/Haltroy/CefNet.Avalonia.Examples

Haltroy commented 1 year ago

Good news, the example worked with all the code copied. bad news, the code wasn't that much pretty and it crashed. Now it's just fixing them.