diff --git a/alethzero/DappHost.cpp b/alethzero/DappHost.cpp index fd73c1b17..3b0661ad1 100644 --- a/alethzero/DappHost.cpp +++ b/alethzero/DappHost.cpp @@ -28,7 +28,11 @@ using namespace dev; DappHost::DappHost(int _port, int _threads): - m_port(_port), m_threads(_threads), m_running(false), m_daemon(nullptr) + m_port(_port), + m_url(QString("http://localhost:%1/").arg(m_port)), + m_threads(_threads), + m_running(false), + m_daemon(nullptr) { startListening(); } @@ -135,5 +139,10 @@ QUrl DappHost::hostDapp(Dapp&& _dapp) for (ManifestEntry const& entry: m_dapp.manifest.entries) m_entriesByPath[QString::fromStdString(entry.path)] = &entry; - return QUrl(QString("http://localhost:%1/").arg(m_port)); + return m_url; +} + +bool DappHost::servesUrl(QUrl const& _url) const +{ + return m_url == _url || m_url.isParentOf(_url); } diff --git a/alethzero/DappHost.h b/alethzero/DappHost.h index 985bd34d9..50dff741d 100644 --- a/alethzero/DappHost.h +++ b/alethzero/DappHost.h @@ -40,6 +40,9 @@ public: /// Load and host a dapp. Previsous dapp in discarded. Synchronous QUrl hostDapp(Dapp&& _dapp); + /// @returns true if the given url is served from this DappHost. + bool servesUrl(QUrl const& _url) const; + private: void startListening(); void stopListening(); @@ -48,7 +51,8 @@ private: void sendResponse(std::string const& _url, MHD_Connection* _connection); static int callback(void* _cls, MHD_Connection* _connection, char const* _url, char const* _method, char const* _version, char const* _uploadData, size_t* _uploadDataSize, void** _conCls); - int m_port; + int const m_port; + QUrl const m_url; int m_threads; bool m_running; MHD_Daemon* m_daemon; diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index dd3d5bbd3..e48b58283 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -232,6 +232,11 @@ Main::Main(QWidget *parent) : { ui->tabWidget->setTabText(0, ui->webView->title()); }); + connect(ui->webView, &QWebEngineView::urlChanged, [=](QUrl const& _url) + { + if (!m_dappHost->servesUrl(_url)) + ui->urlEdit->setText(_url.toString()); + }); m_dappHost.reset(new DappHost(8081)); m_dappLoader = new DappLoader(this, web3(), getNameReg());