minigalaxy icon indicating copy to clipboard operation
minigalaxy copied to clipboard

FR: Port on new WebKitGTK

Open tim77 opened this issue 2 years ago • 10 comments

Consider port on latest WebKitGTK version https://webkitgtk.org/2022/09/16/webkitgtk2.38.0-released.html.

Rationale: latest GNOME v43 runtime contains 2.38 version so currently not possible to upgrade runtime on Flathub build without bundling old WebKitGTK version which is not optimal. New runtime is always nice to have for project like Minigalaxy since they are contain latest Mesa versions and other cool stuff which useful for games.

tim77 avatar Oct 05 '22 21:10 tim77

I would like to do this, but do you know what I'd have to change to get this to work? You got any error message when using the new one?

sharkwouter avatar Oct 06 '22 06:10 sharkwouter

With new v43 runtime:

Traceback (most recent call last):
  File "/app/bin/minigalaxy", line 50, in <module>
    main()
  File "/app/bin/minigalaxy", line 40, in main
    from minigalaxy.ui.gtk import Gtk
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/__init__.py", line 3, in <module>
    from minigalaxy.ui.window import Window             # noqa: F401
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/window.py", line 4, in <module>
    from minigalaxy.ui.login import Login
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/login.py", line 6, in <module>
    from minigalaxy.ui.webkit import WebKit2
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/webkit.py", line 3, in <module>
    gi.require_version('WebKit2', '4.0')
  File "/usr/lib/python3.10/site-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available for version %s' %
ValueError: Namespace WebKit2 not available for version 4.0

tim77 avatar Oct 06 '22 06:10 tim77

What does it say if you remove line 3 from minigalaxy/ui/webkit.py? Python should give a warning. On my system it looks like this:

/home/wouter/Personal/minigalaxy/minigalaxy/ui/webkit.py:3: PyGIWarning: WebKit2 was imported without specifying a version first. Use gi.require_version('WebKit2', '4.0') before import to ensure that the right version gets loaded.
  from gi.repository import WebKit2  # noqa: E402,F401

Maybe there is some way to check available versions before importing or to silence this error. I don't know if the newer version works without further changes, though.

sharkwouter avatar Oct 06 '22 09:10 sharkwouter

Without 3rd line in minigalaxy/ui/webkit.py:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/gi/importer.py", line 142, in load_module
    introspection_module = get_introspection_module(namespace)
  File "/usr/lib/python3.10/site-packages/gi/module.py", line 257, in get_introspection_module
    module = IntrospectionModule(namespace, version)
  File "/usr/lib/python3.10/site-packages/gi/module.py", line 109, in __init__
    repository.require(namespace, version)
gi.RepositoryError: Requiring namespace 'Gtk' version '4.0', but '3.0' is already loaded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/bin/minigalaxy", line 64, in <module>
    main()
  File "/app/bin/minigalaxy", line 46, in main
    from minigalaxy.ui.gtk import Gtk
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/__init__.py", line 3, in <module>
    from minigalaxy.ui.window import Window             # noqa: F401
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/window.py", line 5, in <module>
    from minigalaxy.ui.login import Login
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/login.py", line 6, in <module>
    from minigalaxy.ui.webkit import WebKit2
  File "/app/lib/python3.10/site-packages/minigalaxy/ui/webkit.py", line 3, in <module>
    from gi.repository import WebKit2  # noqa: E402,F401
  File "/usr/lib/python3.10/site-packages/gi/importer.py", line 144, in load_module
    raise ImportError(e)
ImportError: Requiring namespace 'Gtk' version '4.0', but '3.0' is already loaded

tim77 avatar Oct 06 '22 20:10 tim77

Does it work if you just set it to require 3.0? If it does, I'll try to find a method to detect what is loaded.

sharkwouter avatar Oct 06 '22 20:10 sharkwouter

So, according to webkit2gtk-5.0.pc file there is dependency on gtk4:

prefix=/usr
exec_prefix=${prefix}
libdir=/usr/lib64
includedir=${prefix}/include
revision=tarball

Name: WebKitGTK web process extensions
Description: Web content engine for GTK - web process extensions
URL: https://webkitgtk.org
Version: 2.38.0
Requires: glib-2.0 gtk4 libsoup-3.0 javascriptcoregtk-5.0
Libs: -L${libdir} -lwebkit2gtk-5.0
Cflags: -I${includedir}/webkitgtk-5.0

Porting on new WebKitGTK probably require porting on new gtk4 which is not trivial. I'll try to dig this and provide more tips/information. In any case this is not something critical which we must to do right now, but nice to have in long term.

💫 Somewhat related: https://github.com/sharkwouter/minigalaxy/issues/485#issuecomment-1127884293.

tim77 avatar Oct 06 '22 21:10 tim77

Agreed, I think GTK4 would also provide us with some nice looking new widgets. Please keep the comments coming :D

sharkwouter avatar Oct 06 '22 21:10 sharkwouter

In the GNOME 43 SDK, there are two WebKit2 bindings - 5.0 and 4.1. I guess the Gtk 3.0/4.0 collision happens when WebKit2 5.0 is imported (and it's probably imported by default if you don't specify a version in gi.require_version(). I've tried specifying the 4.1 version and it seems to work, although I'm not familiar with the app and didn't test it extensively, only checked that it's able to show the login web page on launch. Here is the only change I've made to the app:

diff --git a/minigalaxy/ui/webkit.py b/minigalaxy/ui/webkit.py
index c71a7ff..4b36a52 100644
--- a/minigalaxy/ui/webkit.py
+++ b/minigalaxy/ui/webkit.py
@@ -1,4 +1,7 @@
 import gi
 
-gi.require_version('WebKit2', '4.0')
+try:
+    gi.require_version('WebKit2', '4.0')
+except gi.RepositoryError:
+    gi.require_version('WebKit2', '4.1')
 from gi.repository import WebKit2  # noqa: E402,F401

gasinvein avatar Oct 07 '22 10:10 gasinvein

I've found a solution which is not the prettiest, but does work: https://github.com/sharkwouter/minigalaxy/commit/ec823d4148fe9182c92c6e748228a527e45f0dcf

sharkwouter avatar Oct 07 '22 11:10 sharkwouter

Works with https://github.com/sharkwouter/minigalaxy/commit/ec823d4148fe9182c92c6e748228a527e45f0dcf and new v43 runtime. Awesome. Do you plan made a new minor release or i can backport this patch on Flathub build?

tim77 avatar Oct 07 '22 13:10 tim77