This commit is contained in:
2026-03-03 22:52:22 +01:00
parent 8d00476ed2
commit 8f49007930
11 changed files with 167 additions and 39 deletions

View File

@@ -129,6 +129,31 @@ void WebviewWindow::runJs(const QString &js)
p->runJavaScript(js);
}
void WebviewWindow::callJs(const QString &js, Command *c)
{
QWebEnginePage *p = _view->page();
QString _js = QString("{\n") +
" let f = function() {\n" +
" " + js + "\n" +
" };\n" +
" try {\n" +
" let obj = { oke: true, result: f(), exn: false };\n" +
" obj;\n" +
" } catch(e) {\n" +
" let obj = { oke: false, result: false, exn: e.message };\n" +
" obj;\n" +
" }\n" +
"}";
p->runJavaScript(_js, [c](const QVariant &v) {
c->result = v;
QJsonObject obj = v.toJsonObject();
bool ok = obj["oke"].toBool();
c->js_result_ok = ok;
c->result = QString::fromUtf8(QJsonDocument(obj).toJson(QJsonDocument::JsonFormat::Compact));
c->done = true;
});
}
void WebviewWindow::openDevTools()
{
_devtools = new QMainWindow(this);