From e5e10354efccb1270c29f8f4dca9da8cfbf177c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 14 May 2025 14:19:38 +0200 Subject: [PATCH 1/3] webview-lib: extend to support setting icons on Linux --- pkgs/webview-lib/default.nix | 15 +++++----- pkgs/webview-lib/fixes.patch | 54 ------------------------------------ 2 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 pkgs/webview-lib/fixes.patch diff --git a/pkgs/webview-lib/default.nix b/pkgs/webview-lib/default.nix index a891e7da4..8aa44d3f0 100644 --- a/pkgs/webview-lib/default.nix +++ b/pkgs/webview-lib/default.nix @@ -4,17 +4,16 @@ pkgs.clangStdenv.mkDerivation { pname = "webview"; version = "nightly"; - src = pkgs.fetchFromGitHub { - owner = "webview"; - repo = "webview"; - rev = "f1a9d6b6fb8bcc2e266057224887a3d628f30f90"; - sha256 = "sha256-sK7GXDbb2zEntWH5ylC2B39zW+gXvqQ1l843gvziDZo="; - }; - # We add the function id to the promise to be able to cancel it through the UI # We disallow remote connections from the UI on Linux # TODO: Disallow remote connections on MacOS - patches = [ ./fixes.patch ]; + + src = pkgs.fetchFromGitHub { + owner = "clan-lol"; + repo = "webview"; + rev = "33374e1030c5e243dac491e6c0e84d32e895c2e5"; + sha256 = "sha256-8BgfQL0V3f2n5lq5MDwJCJo6MkVSYvJkwpKCj2tBRz8="; + }; outputs = [ "out" diff --git a/pkgs/webview-lib/fixes.patch b/pkgs/webview-lib/fixes.patch deleted file mode 100644 index 01f8a5b9f..000000000 --- a/pkgs/webview-lib/fixes.patch +++ /dev/null @@ -1,54 +0,0 @@ -diff --git a/core/include/webview/detail/backends/gtk_webkitgtk.hh b/core/include/webview/detail/backends/gtk_webkitgtk.hh -index f44db8f..b5657ca 100644 ---- a/core/include/webview/detail/backends/gtk_webkitgtk.hh -+++ b/core/include/webview/detail/backends/gtk_webkitgtk.hh -@@ -303,6 +303,37 @@ private: - add_init_script("function(message) {\n\ - return window.webkit.messageHandlers.__webview__.postMessage(message);\n\ - }"); -+ -+ -+ //===================MY CHANGES========================= -+ // TODO: Would be nice to have this configurable from the API. -+ auto on_decide_policy = +[] (WebKitWebView *, -+ WebKitPolicyDecision *decision, -+ WebKitPolicyDecisionType decision_type, gpointer) -> gboolean { -+ if (decision_type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { -+ return FALSE; // Continue with the default handler -+ } -+ -+ WebKitNavigationPolicyDecision * navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); -+ WebKitNavigationAction * navigation_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision); -+ WebKitURIRequest * request = webkit_navigation_action_get_request (navigation_action); -+ const char * uri = webkit_uri_request_get_uri (request); -+ -+ if (g_str_has_prefix(uri, "file://") || -+ g_str_has_prefix(uri, "http://localhost") || -+ g_str_has_prefix(uri, "http://127.0.0.1") || -+ g_str_has_prefix(uri, "http://[::1]")) { -+ printf("Allowing %s URI\n", uri); -+ return FALSE; // Continue with the default handler -+ } else { -+ printf("Blocking %s URI at %s:%d\n", uri, __FILE__, __LINE__); -+ webkit_policy_decision_ignore(decision); -+ return TRUE; // Stop the default handler -+ } -+ }; -+ g_signal_connect(GTK_WIDGET(m_webview), "decide-policy", -+ G_CALLBACK(on_decide_policy), this); -+ //============END========= - } - - void window_settings(bool debug) { -diff --git a/core/include/webview/detail/engine_base.hh b/core/include/webview/detail/engine_base.hh -index 01c8d29..8ea5622 100644 ---- a/core/include/webview/detail/engine_base.hh -+++ b/core/include/webview/detail/engine_base.hh -@@ -232,6 +232,7 @@ protected: - var promise = new Promise(function(resolve, reject) {\n\ - _promises[_id] = { resolve, reject };\n\ - });\n\ -+ promise._webviewMessageId = _id;\n\ - this.post(JSON.stringify({\n\ - id: _id,\n\ - method: method,\n\ From 2f2ebdb41f3b3981a6dd5270556335cc791ae709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 14 May 2025 15:24:16 +0200 Subject: [PATCH 2/3] clan-app: set title --- pkgs/clan-app/clan_app/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/clan-app/clan_app/app.py b/pkgs/clan-app/clan_app/app.py index 4446f14d7..2e6e9db4b 100644 --- a/pkgs/clan-app/clan_app/app.py +++ b/pkgs/clan-app/clan_app/app.py @@ -38,6 +38,7 @@ def app_run(app_opts: ClanAppOptions) -> int: content_uri = f"file://{site_index}" webview = Webview(debug=app_opts.debug) + webview.title = "Clan App" def cancel_task( task_id: str, *, op_key: str From 30ff0a622ac1528e855e7c6ccfdf891776a12c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 14 May 2025 15:24:24 +0200 Subject: [PATCH 3/3] clan-app: prepare icon support on linux For some reason the icon is not shown when using the gtk backend but at least the API calls look correct. --- pkgs/clan-app/clan_app/app.py | 2 ++ pkgs/clan-app/clan_app/deps/webview/_webview_ffi.py | 3 +++ pkgs/clan-app/clan_app/deps/webview/webview.py | 9 +++++++++ pkgs/webview-lib/default.nix | 10 ++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-app/clan_app/app.py b/pkgs/clan-app/clan_app/app.py index 2e6e9db4b..6fd3db2de 100644 --- a/pkgs/clan-app/clan_app/app.py +++ b/pkgs/clan-app/clan_app/app.py @@ -39,6 +39,8 @@ def app_run(app_opts: ClanAppOptions) -> int: webview = Webview(debug=app_opts.debug) webview.title = "Clan App" + # This seems to call the gtk api correctly but and gtk also seems to our icon, but somehow the icon is not loaded. + webview.icon = "clan-white" def cancel_task( task_id: str, *, op_key: str diff --git a/pkgs/clan-app/clan_app/deps/webview/_webview_ffi.py b/pkgs/clan-app/clan_app/deps/webview/_webview_ffi.py index 714400081..d5640fc89 100644 --- a/pkgs/clan-app/clan_app/deps/webview/_webview_ffi.py +++ b/pkgs/clan-app/clan_app/deps/webview/_webview_ffi.py @@ -88,6 +88,9 @@ class _WebviewLibrary: self.webview_set_title = self.lib.webview_set_title self.webview_set_title.argtypes = [c_void_p, c_char_p] + self.webview_set_icon = self.lib.webview_set_icon + self.webview_set_icon.argtypes = [c_void_p, c_char_p] + self.webview_set_size = self.lib.webview_set_size self.webview_set_size.argtypes = [c_void_p, c_int, c_int, c_int] diff --git a/pkgs/clan-app/clan_app/deps/webview/webview.py b/pkgs/clan-app/clan_app/deps/webview/webview.py index f47207c13..af8deab32 100644 --- a/pkgs/clan-app/clan_app/deps/webview/webview.py +++ b/pkgs/clan-app/clan_app/deps/webview/webview.py @@ -84,6 +84,15 @@ class Webview: _webview_lib.webview_set_title(self._handle, _encode_c_string(value)) self._title = value + @property + def icon(self) -> str: + return self._icon + + @icon.setter + def icon(self, value: str) -> None: + _webview_lib.webview_set_icon(self._handle, _encode_c_string(value)) + self._icon = value + def destroy(self) -> None: for name in list(self._callbacks.keys()): self.unbind(name) diff --git a/pkgs/webview-lib/default.nix b/pkgs/webview-lib/default.nix index 8aa44d3f0..afe166031 100644 --- a/pkgs/webview-lib/default.nix +++ b/pkgs/webview-lib/default.nix @@ -11,8 +11,8 @@ pkgs.clangStdenv.mkDerivation { src = pkgs.fetchFromGitHub { owner = "clan-lol"; repo = "webview"; - rev = "33374e1030c5e243dac491e6c0e84d32e895c2e5"; - sha256 = "sha256-8BgfQL0V3f2n5lq5MDwJCJo6MkVSYvJkwpKCj2tBRz8="; + rev = "7d24f0192765b7e08f2d712fae90c046d08f318e"; + hash = "sha256-yokVI9tFiEEU5M/S2xAeJOghqqiCvTelLo8WLKQZsSY="; }; outputs = [ @@ -20,6 +20,12 @@ pkgs.clangStdenv.mkDerivation { "dev" ]; + enableParallelBuilding = true; + + cmakeFlags = [ + "-DWEBVIEW_BUILD_TESTS=OFF" + ]; + # Dependencies used during the build process, if any nativeBuildInputs = with pkgs; [ gnumake