fix: segfault gtk when using webkit
This commit is contained in:
committed by
hsjobeki
parent
bd34807055
commit
59b3981582
@@ -7,7 +7,6 @@ from pathlib import Path
|
|||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
from clan_cli import machines
|
|
||||||
|
|
||||||
gi.require_version("WebKit", "6.0")
|
gi.require_version("WebKit", "6.0")
|
||||||
|
|
||||||
@@ -90,6 +89,8 @@ class WebView:
|
|||||||
handler_fn = self.method_registry[method_name]
|
handler_fn = self.method_registry[method_name]
|
||||||
|
|
||||||
# Start handler_fn in a new thread
|
# Start handler_fn in a new thread
|
||||||
|
# GLib.idle_add(handler_fn)
|
||||||
|
|
||||||
thread = threading.Thread(
|
thread = threading.Thread(
|
||||||
target=self.threaded_handler,
|
target=self.threaded_handler,
|
||||||
args=(handler_fn, payload.get("data"), method_name),
|
args=(handler_fn, payload.get("data"), method_name),
|
||||||
@@ -107,6 +108,8 @@ class WebView:
|
|||||||
|
|
||||||
def call_js(self, method_name: str, serialized: str) -> bool:
|
def call_js(self, method_name: str, serialized: str) -> bool:
|
||||||
# This function must be run on the main GTK thread to interact with the webview
|
# This function must be run on the main GTK thread to interact with the webview
|
||||||
|
# result = method_fn(data) # takes very long
|
||||||
|
# serialized = result
|
||||||
self.webview.evaluate_javascript(
|
self.webview.evaluate_javascript(
|
||||||
f"""
|
f"""
|
||||||
window.clan.{method_name}(`{serialized}`);
|
window.clan.{method_name}(`{serialized}`);
|
||||||
@@ -120,11 +123,3 @@ class WebView:
|
|||||||
|
|
||||||
def get_webview(self) -> WebKit.WebView:
|
def get_webview(self) -> WebKit.WebView:
|
||||||
return self.webview
|
return self.webview
|
||||||
|
|
||||||
|
|
||||||
webview = WebView()
|
|
||||||
|
|
||||||
|
|
||||||
@webview.method
|
|
||||||
def list_machines(data: None) -> list[str]:
|
|
||||||
return machines.list.list_machines(".")
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
from clan_cli import machines
|
||||||
from clan_cli.history.list import list_history
|
from clan_cli.history.list import list_history
|
||||||
|
|
||||||
from clan_vm_manager.components.interfaces import ClanConfig
|
from clan_vm_manager.components.interfaces import ClanConfig
|
||||||
@@ -11,7 +12,7 @@ from clan_vm_manager.singletons.use_vms import ClanStore
|
|||||||
from clan_vm_manager.views.details import Details
|
from clan_vm_manager.views.details import Details
|
||||||
from clan_vm_manager.views.list import ClanList
|
from clan_vm_manager.views.list import ClanList
|
||||||
from clan_vm_manager.views.logs import Logs
|
from clan_vm_manager.views.logs import Logs
|
||||||
from clan_vm_manager.views.webview import webview
|
from clan_vm_manager.views.webview import WebView
|
||||||
|
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
|
|
||||||
@@ -59,6 +60,13 @@ class MainWindow(Adw.ApplicationWindow):
|
|||||||
stack_view.add_named(ClanList(config), "list")
|
stack_view.add_named(ClanList(config), "list")
|
||||||
stack_view.add_named(Details(), "details")
|
stack_view.add_named(Details(), "details")
|
||||||
stack_view.add_named(Logs(), "logs")
|
stack_view.add_named(Logs(), "logs")
|
||||||
|
|
||||||
|
webview = WebView()
|
||||||
|
|
||||||
|
@webview.method
|
||||||
|
def list_machines(data: None) -> list[str]:
|
||||||
|
return machines.list.list_machines(".")
|
||||||
|
|
||||||
stack_view.add_named(webview.get_webview(), "webview")
|
stack_view.add_named(webview.get_webview(), "webview")
|
||||||
|
|
||||||
stack_view.set_visible_child_name(config.initial_view)
|
stack_view.set_visible_child_name(config.initial_view)
|
||||||
|
|||||||
@@ -32,17 +32,13 @@ let
|
|||||||
mimeTypes = [ "x-scheme-handler/clan" ];
|
mimeTypes = [ "x-scheme-handler/clan" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
webkitgtk = webkitgtk_6_0.overrideAttrs (_: {
|
|
||||||
meta.broken = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
# Dependencies that are directly used in the project but nor from internal python packages
|
# Dependencies that are directly used in the project but nor from internal python packages
|
||||||
externalPythonDeps = [
|
externalPythonDeps = [
|
||||||
pygobject3
|
pygobject3
|
||||||
pygobject-stubs
|
pygobject-stubs
|
||||||
gtk4
|
gtk4
|
||||||
libadwaita
|
libadwaita
|
||||||
webkitgtk
|
webkitgtk_6_0
|
||||||
gnome.adwaita-icon-theme
|
gnome.adwaita-icon-theme
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -50,7 +46,9 @@ let
|
|||||||
allPythonDeps = [ (python3.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps;
|
allPythonDeps = [ (python3.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps;
|
||||||
|
|
||||||
# Runtime binary dependencies required by the application
|
# Runtime binary dependencies required by the application
|
||||||
runtimeDependencies = [ ];
|
runtimeDependencies = [
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
# Dependencies required for running tests
|
# Dependencies required for running tests
|
||||||
externalTestDeps =
|
externalTestDeps =
|
||||||
@@ -87,6 +85,7 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
setuptools
|
setuptools
|
||||||
copyDesktopItems
|
copyDesktopItems
|
||||||
wrapGAppsHook
|
wrapGAppsHook
|
||||||
|
|
||||||
gobject-introspection
|
gobject-introspection
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -107,6 +106,19 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
chmod +w -R ./src
|
chmod +w -R ./src
|
||||||
cd ./src
|
cd ./src
|
||||||
|
|
||||||
|
export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf
|
||||||
|
export FONTCONFIG_PATH=${fontconfig.out}/etc/fonts
|
||||||
|
|
||||||
|
mkdir -p .home/.local/share/fonts
|
||||||
|
export HOME=.home
|
||||||
|
|
||||||
|
fc-cache --verbose
|
||||||
|
# > fc-cache succeded
|
||||||
|
|
||||||
|
echo "Loaded the following fonts ..."
|
||||||
|
fc-list
|
||||||
|
|
||||||
|
echo "STARTING ..."
|
||||||
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
||||||
${pythonWithTestDeps}/bin/python -m pytest -s -m "not impure" ./tests
|
${pythonWithTestDeps}/bin/python -m pytest -s -m "not impure" ./tests
|
||||||
touch $out
|
touch $out
|
||||||
@@ -142,8 +154,19 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
rm $out/nix-support/propagated-build-inputs
|
rm $out/nix-support/propagated-build-inputs
|
||||||
'';
|
'';
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
# TODO: figure out why the test cannot load the fonts
|
export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf
|
||||||
# PYTHONPATH= $out/bin/clan-vm-manager --help
|
export FONTCONFIG_PATH=${fontconfig.out}/etc/fonts
|
||||||
|
|
||||||
|
mkdir -p .home/.local/share/fonts
|
||||||
|
export HOME=.home
|
||||||
|
|
||||||
|
fc-cache --verbose
|
||||||
|
# > fc-cache succeded
|
||||||
|
|
||||||
|
echo "Loaded the following fonts ..."
|
||||||
|
fc-list
|
||||||
|
|
||||||
|
PYTHONPATH= $out/bin/clan-vm-manager --help
|
||||||
'';
|
'';
|
||||||
desktopItems = [ desktop-file ];
|
desktopItems = [ desktop-file ];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{ config, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
if lib.elem system lib.platforms.darwin then
|
||||||
|
{ }
|
||||||
|
else
|
||||||
{
|
{
|
||||||
devShells.clan-vm-manager = pkgs.callPackage ./shell.nix {
|
devShells.clan-vm-manager = pkgs.callPackage ./shell.nix {
|
||||||
inherit (config.packages) clan-vm-manager webview-ui;
|
inherit (config.packages) clan-vm-manager webview-ui;
|
||||||
|
|||||||
Reference in New Issue
Block a user