clan-app: Add cancellable tasks

This commit is contained in:
Qubasa
2025-05-09 17:14:49 +02:00
parent a06bd43a1a
commit 7eac2ce436
17 changed files with 781 additions and 247 deletions

View File

@@ -7,10 +7,15 @@ pkgs.clangStdenv.mkDerivation {
src = pkgs.fetchFromGitHub {
owner = "webview";
repo = "webview";
rev = "83a4b4a5bbcb4b0ba2ca3ee226c2da1414719106";
sha256 = "sha256-5R8kllvP2EBuDANIl07fxv/EcbPpYgeav8Wfz7Kt13c=";
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 ];
outputs = [
"out"
"dev"

View File

@@ -0,0 +1,54 @@
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\