forked from clan/clan-core
fix: segfault gtk when using webkit
This commit is contained in:
parent
e25bd69c68
commit
4cfc335e2c
@ -7,7 +7,6 @@ from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
import gi
|
||||
from clan_cli import machines
|
||||
|
||||
gi.require_version("WebKit", "6.0")
|
||||
|
||||
@ -90,6 +89,8 @@ class WebView:
|
||||
handler_fn = self.method_registry[method_name]
|
||||
|
||||
# Start handler_fn in a new thread
|
||||
# GLib.idle_add(handler_fn)
|
||||
|
||||
thread = threading.Thread(
|
||||
target=self.threaded_handler,
|
||||
args=(handler_fn, payload.get("data"), method_name),
|
||||
@ -107,6 +108,8 @@ class WebView:
|
||||
|
||||
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
|
||||
# result = method_fn(data) # takes very long
|
||||
# serialized = result
|
||||
self.webview.evaluate_javascript(
|
||||
f"""
|
||||
window.clan.{method_name}(`{serialized}`);
|
||||
@ -120,11 +123,3 @@ class WebView:
|
||||
|
||||
def get_webview(self) -> WebKit.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 gi
|
||||
from clan_cli import machines
|
||||
from clan_cli.history.list import list_history
|
||||
|
||||
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.list import ClanList
|
||||
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")
|
||||
|
||||
@ -59,6 +60,13 @@ class MainWindow(Adw.ApplicationWindow):
|
||||
stack_view.add_named(ClanList(config), "list")
|
||||
stack_view.add_named(Details(), "details")
|
||||
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.set_visible_child_name(config.initial_view)
|
||||
|
@ -32,17 +32,13 @@ let
|
||||
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
|
||||
externalPythonDeps = [
|
||||
pygobject3
|
||||
pygobject-stubs
|
||||
gtk4
|
||||
libadwaita
|
||||
webkitgtk
|
||||
webkitgtk_6_0
|
||||
gnome.adwaita-icon-theme
|
||||
];
|
||||
|
||||
@ -50,7 +46,9 @@ let
|
||||
allPythonDeps = [ (python3.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps;
|
||||
|
||||
# Runtime binary dependencies required by the application
|
||||
runtimeDependencies = [ ];
|
||||
runtimeDependencies = [
|
||||
|
||||
];
|
||||
|
||||
# Dependencies required for running tests
|
||||
externalTestDeps =
|
||||
@ -87,6 +85,7 @@ python3.pkgs.buildPythonApplication rec {
|
||||
setuptools
|
||||
copyDesktopItems
|
||||
wrapGAppsHook
|
||||
|
||||
gobject-introspection
|
||||
];
|
||||
|
||||
@ -107,6 +106,19 @@ python3.pkgs.buildPythonApplication rec {
|
||||
chmod +w -R ./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
|
||||
${pythonWithTestDeps}/bin/python -m pytest -s -m "not impure" ./tests
|
||||
touch $out
|
||||
@ -142,8 +154,19 @@ python3.pkgs.buildPythonApplication rec {
|
||||
rm $out/nix-support/propagated-build-inputs
|
||||
'';
|
||||
checkPhase = ''
|
||||
# TODO: figure out why the test cannot load the fonts
|
||||
# PYTHONPATH= $out/bin/clan-vm-manager --help
|
||||
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
|
||||
|
||||
PYTHONPATH= $out/bin/clan-vm-manager --help
|
||||
'';
|
||||
desktopItems = [ desktop-file ];
|
||||
}
|
||||
|
@ -1,15 +1,24 @@
|
||||
{ ... }:
|
||||
{
|
||||
perSystem =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
devShells.clan-vm-manager = pkgs.callPackage ./shell.nix {
|
||||
inherit (config.packages) clan-vm-manager webview-ui;
|
||||
};
|
||||
packages.clan-vm-manager = pkgs.python3.pkgs.callPackage ./default.nix {
|
||||
inherit (config.packages) clan-cli webview-ui;
|
||||
};
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
system,
|
||||
...
|
||||
}:
|
||||
if lib.elem system lib.platforms.darwin then
|
||||
{ }
|
||||
else
|
||||
{
|
||||
devShells.clan-vm-manager = pkgs.callPackage ./shell.nix {
|
||||
inherit (config.packages) clan-vm-manager webview-ui;
|
||||
};
|
||||
packages.clan-vm-manager = pkgs.python3.pkgs.callPackage ./default.nix {
|
||||
inherit (config.packages) clan-cli webview-ui;
|
||||
};
|
||||
|
||||
checks = config.packages.clan-vm-manager.tests;
|
||||
};
|
||||
checks = config.packages.clan-vm-manager.tests;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user