texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Wed, 30 Nov 2022 13:36:37 -0500 (EST)

branch: old/qt-info
commit 4b0cddc3766010cabedff2109c068f33f076466c
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Apr 11 11:59:52 2019 +0100

    add qwebchannel.js as script
---
 js/docbrowser/mainwindow.cpp | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index 17ff185313..8d1e9f5bd8 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -82,16 +82,6 @@ MainWindow::inject_qwebchannel(bool finished_ok)
 
     qDebug() << "injecting into page" << ui->webEngineView->url();
 
-#define QWEBCHANNEL_JS "qwebchannel.js"
-
-    if (qwebchannel_js.isNull()) {
-        QFile file;
-        file.setFileName (QString(this->datadir)
-                          + "/docbrowser/" + QWEBCHANNEL_JS);
-        file.open(QIODevice::ReadOnly);
-        QByteArray b = file.readAll();
-        qwebchannel_js = QString(b);
-    }
 
     auto *page = ui->webEngineView->page();
 
@@ -99,11 +89,9 @@ MainWindow::inject_qwebchannel(bool finished_ok)
        function.  Qt uses an asynchronous callback system for this.  Check if 
        wc_init is defined because this slot is activated even for 
"about:blank",
        the default page. */
-    page->runJavaScript (qwebchannel_js, [this, page](const QVariant&) {
-      page->runJavaScript(
+    page->runJavaScript(
                   "if (typeof wc_init == 'function') { wc_init(); }",
                    0 );
-      });
 }
 
 void
@@ -144,6 +132,17 @@ MainWindow::setup_profile(QWebEngineProfile *profile)
         info_css = QString(b);
     }
 
+#define QWEBCHANNEL_JS "qwebchannel.js"
+
+    if (qwebchannel_js.isNull()) {
+        QFile file;
+        file.setFileName (QString(this->datadir)
+                          + "/docbrowser/" + QWEBCHANNEL_JS);
+        file.open(QIODevice::ReadOnly);
+        QByteArray b = file.readAll();
+        qwebchannel_js = QString(b);
+    }
+
     /* Set up JavaScript to load info.css.  This relies on there being no 
        single quotes or backslashes in info.css.  The simplified() call
        is needed to fit the CSS in a single line of JavaScript. */
@@ -174,6 +173,12 @@ MainWindow::setup_profile(QWebEngineProfile *profile)
     s3.setWorldId(QWebEngineScript::MainWorld);
     profile->scripts()->insert(s3);
 
+    QWebEngineScript s4;
+    s4.setSourceCode(qwebchannel_js);
+    s4.setInjectionPoint(QWebEngineScript::DocumentCreation);
+    s4.setWorldId(QWebEngineScript::MainWorld);
+    profile->scripts()->insert(s4);
+
     /* We need the files to be loaded in a particular order.
        Using QWebEngineProfile appears to work.  Calling runJavaScript
        after the page is loaded doesn't work this is too late for



reply via email to

[Prev in Thread] Current Thread [Next in Thread]