Merge pull request 'clan-app: set title and icon' (#3658) from clan-app-title into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3658
This commit is contained in:
@@ -38,6 +38,9 @@ def app_run(app_opts: ClanAppOptions) -> int:
|
||||
content_uri = f"file://{site_index}"
|
||||
|
||||
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
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -149,6 +149,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)
|
||||
|
||||
@@ -4,23 +4,28 @@ 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 = "7d24f0192765b7e08f2d712fae90c046d08f318e";
|
||||
hash = "sha256-yokVI9tFiEEU5M/S2xAeJOghqqiCvTelLo8WLKQZsSY=";
|
||||
};
|
||||
|
||||
outputs = [
|
||||
"out"
|
||||
"dev"
|
||||
];
|
||||
|
||||
enableParallelBuilding = true;
|
||||
|
||||
cmakeFlags = [
|
||||
"-DWEBVIEW_BUILD_TESTS=OFF"
|
||||
];
|
||||
|
||||
# Dependencies used during the build process, if any
|
||||
nativeBuildInputs = with pkgs; [
|
||||
gnumake
|
||||
|
||||
@@ -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\
|
||||
Reference in New Issue
Block a user