Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Port on new WebKitGTK #535

Open
tim77 opened this issue Oct 5, 2022 · 10 comments
Open

FR: Port on new WebKitGTK #535

tim77 opened this issue Oct 5, 2022 · 10 comments
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@tim77
Copy link
Contributor

tim77 commented Oct 5, 2022

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.

@sharkwouter
Copy link
Owner

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?

@tim77
Copy link
Contributor Author

tim77 commented Oct 6, 2022

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

@sharkwouter
Copy link
Owner

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.

@tim77
Copy link
Contributor Author

tim77 commented Oct 6, 2022

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

@sharkwouter
Copy link
Owner

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.

@tim77
Copy link
Contributor Author

tim77 commented Oct 6, 2022

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: #485 (comment).

@sharkwouter
Copy link
Owner

sharkwouter commented Oct 6, 2022

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

@gasinvein
Copy link

gasinvein commented Oct 7, 2022

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

@sharkwouter
Copy link
Owner

I've found a solution which is not the prettiest, but does work: ec823d4

@tim77
Copy link
Contributor Author

tim77 commented Oct 7, 2022

Works with ec823d4 and new v43 runtime. Awesome. Do you plan made a new minor release or i can backport this patch on Flathub build?

tim77 added a commit to tim77/io.github.sharkwouter.Minigalaxy that referenced this issue Oct 8, 2022
tim77 added a commit to flathub/io.github.sharkwouter.Minigalaxy that referenced this issue Oct 9, 2022
tim77 added a commit to flathub/io.github.sharkwouter.Minigalaxy that referenced this issue Oct 10, 2022
@sharkwouter sharkwouter added this to the 2.0.0 milestone Oct 24, 2022
@sharkwouter sharkwouter added bug Something isn't working enhancement New feature or request labels Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants