|
@ -19,13 +19,15 @@ |
|
|
* @date 2014 |
|
|
* @date 2014 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#define QWEBENGINEINSPECTOR 1 |
|
|
#include <fstream> |
|
|
#include <fstream> |
|
|
#include <QtNetwork/QNetworkReply> |
|
|
#include <QtNetwork/QNetworkReply> |
|
|
#include <QtWidgets/QFileDialog> |
|
|
#include <QtWidgets/QFileDialog> |
|
|
#include <QtWidgets/QMessageBox> |
|
|
#include <QtWidgets/QMessageBox> |
|
|
#include <QtWidgets/QInputDialog> |
|
|
#include <QtWidgets/QInputDialog> |
|
|
#include <QtWebKitWidgets/QWebFrame> |
|
|
#include <QtWebEngine/QtWebEngine> |
|
|
#include <QtWebKit/QWebSettings> |
|
|
#include <QtWebEngineWidgets/QWebEngineView> |
|
|
|
|
|
#include <QtWebEngineWidgets/QWebEngineCallback> |
|
|
#include <QtGui/QClipboard> |
|
|
#include <QtGui/QClipboard> |
|
|
#include <QtCore/QtCore> |
|
|
#include <QtCore/QtCore> |
|
|
#include <boost/algorithm/string.hpp> |
|
|
#include <boost/algorithm/string.hpp> |
|
@ -154,31 +156,24 @@ Main::Main(QWidget *parent) : |
|
|
m_server->setIdentities(keysAsVector(owned())); |
|
|
m_server->setIdentities(keysAsVector(owned())); |
|
|
m_server->StartListening(); |
|
|
m_server->StartListening(); |
|
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::loadStarted, [this]() |
|
|
connect(ui->webView, &QWebEngineView::loadFinished, [this]() |
|
|
{ |
|
|
|
|
|
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); |
|
|
|
|
|
QWebFrame* f = ui->webView->page()->mainFrame(); |
|
|
|
|
|
f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); |
|
|
|
|
|
|
|
|
|
|
|
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [f, this]() |
|
|
|
|
|
{ |
|
|
|
|
|
f->disconnect(); |
|
|
|
|
|
f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); |
|
|
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/bignumber.min.js")); |
|
|
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); |
|
|
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::loadFinished, [=]() |
|
|
|
|
|
{ |
|
|
{ |
|
|
|
|
|
// f->disconnect();
|
|
|
|
|
|
// f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership);
|
|
|
|
|
|
auto f = ui->webView->page(); |
|
|
|
|
|
f->runJavaScript(contentsOfQResource(":/js/bignumber.min.js")); |
|
|
|
|
|
f->runJavaScript(contentsOfQResource(":/js/webthree.js")); |
|
|
|
|
|
f->runJavaScript(contentsOfQResource(":/js/setup.js")); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::titleChanged, [=]() |
|
|
connect(ui->webView, &QWebEngineView::titleChanged, [=]() |
|
|
{ |
|
|
{ |
|
|
ui->tabWidget->setTabText(0, ui->webView->title()); |
|
|
ui->tabWidget->setTabText(0, ui->webView->title()); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ui->webView->page()->settings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, true); |
|
|
|
|
|
// QWebEngineInspector* inspector = new QWebEngineInspector();
|
|
|
|
|
|
// inspector->setPage(page);
|
|
|
readSettings(); |
|
|
readSettings(); |
|
|
installWatches(); |
|
|
installWatches(); |
|
|
startTimer(100); |
|
|
startTimer(100); |
|
@ -361,7 +356,7 @@ QString Main::contents(QString _s) |
|
|
void Main::load(QString _s) |
|
|
void Main::load(QString _s) |
|
|
{ |
|
|
{ |
|
|
QString contents = QString::fromStdString(dev::asString(dev::contents(_s.toStdString()))); |
|
|
QString contents = QString::fromStdString(dev::asString(dev::contents(_s.toStdString()))); |
|
|
ui->webView->page()->currentFrame()->evaluateJavaScript(contents); |
|
|
ui->webView->page()->runJavaScript(contents); |
|
|
/*
|
|
|
/*
|
|
|
QFile fin(_s); |
|
|
QFile fin(_s); |
|
|
if (!fin.open(QFile::ReadOnly)) |
|
|
if (!fin.open(QFile::ReadOnly)) |
|
@ -420,35 +415,35 @@ void Main::on_jsInput_returnPressed() |
|
|
ui->jsInput->setText(""); |
|
|
ui->jsInput->setText(""); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QVariant Main::evalRaw(QString const& _js) |
|
|
|
|
|
{ |
|
|
|
|
|
return ui->webView->page()->currentFrame()->evaluateJavaScript(_js); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Main::eval(QString const& _js) |
|
|
void Main::eval(QString const& _js) |
|
|
{ |
|
|
{ |
|
|
if (_js.trimmed().isEmpty()) |
|
|
if (_js.trimmed().isEmpty()) |
|
|
return; |
|
|
return; |
|
|
QVariant ev = ui->webView->page()->currentFrame()->evaluateJavaScript((_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")")); |
|
|
auto f = [=](QVariant ev) { |
|
|
QVariant jsonEv = ui->webView->page()->currentFrame()->evaluateJavaScript("JSON.stringify(___RET)"); |
|
|
auto f2 = [=](QVariant jsonEv) { |
|
|
QString s; |
|
|
QString s; |
|
|
if (ev.isNull()) |
|
|
if (ev.isNull()) |
|
|
s = "<span style=\"color: #888\">null</span>"; |
|
|
s = "<span style=\"color: #888\">null</span>"; |
|
|
else if (ev.type() == QVariant::String) |
|
|
else if (ev.type() == QVariant::String) |
|
|
s = "<span style=\"color: #444\">\"</span><span style=\"color: #c00\">" + ev.toString().toHtmlEscaped() + "</span><span style=\"color: #444\">\"</span>"; |
|
|
s = "<span style=\"color: #444\">\"</span><span style=\"color: #c00\">" + ev.toString().toHtmlEscaped() + "</span><span style=\"color: #444\">\"</span>"; |
|
|
else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) |
|
|
else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) |
|
|
s = "<span style=\"color: #00c\">" + ev.toString().toHtmlEscaped() + "</span>"; |
|
|
s = "<span style=\"color: #00c\">" + ev.toString().toHtmlEscaped() + "</span>"; |
|
|
else if (jsonEv.type() == QVariant::String) |
|
|
else if (jsonEv.type() == QVariant::String) |
|
|
s = "<span style=\"color: #840\">" + jsonEv.toString().toHtmlEscaped() + "</span>"; |
|
|
s = "<span style=\"color: #840\">" + jsonEv.toString().toHtmlEscaped() + "</span>"; |
|
|
else |
|
|
else |
|
|
s = "<span style=\"color: #888\">unknown type</span>"; |
|
|
s = "<span style=\"color: #888\">unknown type</span>"; |
|
|
m_consoleHistory.push_back(qMakePair(_js, s)); |
|
|
m_consoleHistory.push_back(qMakePair(_js, s)); |
|
|
s = "<html><body style=\"margin: 0;\">" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); |
|
|
s = "<html><body style=\"margin: 0;\">" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); |
|
|
for (auto const& i: m_consoleHistory) |
|
|
for (auto const& i: m_consoleHistory) |
|
|
s += "<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em; color: #888; font-weight: bold\">></span><span style=\"color: #35d\">" + i.first.toHtmlEscaped() + "</span></div>" |
|
|
s += "<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em; color: #888; font-weight: bold\">></span><span style=\"color: #35d\">" + i.first.toHtmlEscaped() + "</span></div>" |
|
|
"<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em\"> </span><span>" + i.second + "</span></div>"; |
|
|
"<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em\"> </span><span>" + i.second + "</span></div>"; |
|
|
s += "</div></body></html>"; |
|
|
s += "</div></body></html>"; |
|
|
ui->jsConsole->setHtml(s); |
|
|
ui->jsConsole->setHtml(s); |
|
|
|
|
|
}; |
|
|
|
|
|
ui->webView->page()->runJavaScript("JSON.stringify(___RET)", f2); |
|
|
|
|
|
}; |
|
|
|
|
|
auto c = (_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")"); |
|
|
|
|
|
ui->webView->page()->runJavaScript(c, f); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static Public stringToPublic(QString const& _a) |
|
|
static Public stringToPublic(QString const& _a) |
|
|