clan-app: Add automatic debug console in debug mode

This commit is contained in:
Qubasa
2024-07-16 21:01:30 +02:00
parent 7e97141687
commit dfb1f18e2d
2 changed files with 11 additions and 8 deletions

View File

@@ -5,7 +5,6 @@ from typing import Any, ClassVar
import gi import gi
from clan_app import assets from clan_app import assets
from clan_app.singletons.toast import InfoToast, ToastOverlay
gi.require_version("Gtk", "4.0") gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1") gi.require_version("Adw", "1")
@@ -90,11 +89,6 @@ class MainApplication(Adw.Application):
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0]) setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
log.debug("Debug logging enabled") log.debug("Debug logging enabled")
if "debug" in options:
ToastOverlay.use().add_toast_unique(
InfoToast("Debug logging enabled").toast, "info.debugging.enabled"
)
if "content-uri" in options: if "content-uri" in options:
self.content_uri = options["content-uri"] self.content_uri = options["content-uri"]
log.debug(f"Setting content uri to {self.content_uri}") log.debug(f"Setting content uri to {self.content_uri}")

View File

@@ -26,9 +26,10 @@ class WebExecutor(GObject.Object):
# settings. # settings.
settings.set_property("enable-developer-extras", True) settings.set_property("enable-developer-extras", True)
self.webview.set_settings(settings) self.webview.set_settings(settings)
# Fixme. This filtering is incomplete, it only triggers if a user clicks a link # FIXME: This filtering is incomplete, it only triggers if a user clicks a link
self.webview.connect("decide-policy", self.on_decide_policy) self.webview.connect("decide-policy", self.on_decide_policy)
# For when the page is fully loaded
self.webview.connect("load-changed", self.on_load_changed)
self.manager: WebKit.UserContentManager = ( self.manager: WebKit.UserContentManager = (
self.webview.get_user_content_manager() self.webview.get_user_content_manager()
) )
@@ -45,6 +46,14 @@ class WebExecutor(GObject.Object):
self.api.overwrite_fn(open_file) self.api.overwrite_fn(open_file)
self.api.check_signature(self.jschema_api.signatures) self.api.check_signature(self.jschema_api.signatures)
def on_load_changed(
self, webview: WebKit.WebView, load_event: WebKit.LoadEvent
) -> None:
if load_event == WebKit.LoadEvent.FINISHED:
if log.isEnabledFor(logging.DEBUG):
inspector = webview.get_inspector()
inspector.show()
def on_decide_policy( def on_decide_policy(
self, self,
webview: WebKit.WebView, webview: WebKit.WebView,