2015-08-12 18:56:33 +00:00
|
|
|
#include "BlockChain.hpp"
|
|
|
|
|
|
2015-08-12 15:10:40 +00:00
|
|
|
#include <fc/thread/thread.hpp>
|
2015-08-12 18:56:33 +00:00
|
|
|
#include <fc/thread/future.hpp>
|
|
|
|
|
#include <fc/network/http/server.hpp>
|
|
|
|
|
#include <fc/network/ip.hpp>
|
2015-08-12 15:10:40 +00:00
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
#include <QQmlApplicationEngine>
|
2015-08-12 18:56:33 +00:00
|
|
|
#include <QQmlContext>
|
2015-08-12 15:10:40 +00:00
|
|
|
#include <QtWebEngine>
|
|
|
|
|
#include <QtQml>
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
fc::thread::current().set_name("main");
|
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
app.setApplicationName("Graphene Client");
|
|
|
|
|
app.setApplicationDisplayName(app.applicationName());
|
|
|
|
|
app.setOrganizationDomain("cryptonomex.org");
|
|
|
|
|
app.setOrganizationName("Cryptonomex, Inc.");
|
|
|
|
|
|
2015-08-12 18:56:33 +00:00
|
|
|
QThread chainThread;
|
|
|
|
|
fc::promise<BlockChain*>::ptr chain = new fc::promise<BlockChain*>;
|
|
|
|
|
QObject::connect(&chainThread, &QThread::started, [&app, &chain] {
|
|
|
|
|
chain->set_value(new BlockChain);
|
|
|
|
|
});
|
|
|
|
|
chainThread.start();
|
|
|
|
|
|
2015-08-12 15:10:40 +00:00
|
|
|
QtWebEngine::initialize();
|
2015-08-12 18:56:33 +00:00
|
|
|
fc::http::server webGuiServer;
|
|
|
|
|
fc::thread serverThread("HTTP server thread");
|
|
|
|
|
serverThread.async([&webGuiServer] {
|
|
|
|
|
webGuiServer.listen(fc::ip::endpoint::from_string("127.0.0.1:8080"));
|
|
|
|
|
webGuiServer.on_request([](const fc::http::request& request, const fc::http::server::response& response) {
|
|
|
|
|
QString path = QStringLiteral("/Users/nathan/graphene-ui/web/bundle") + QString::fromStdString(request.path);
|
|
|
|
|
if (path.endsWith('/'))
|
|
|
|
|
path.append(QStringLiteral("index.html"));
|
|
|
|
|
QFile file(path);
|
|
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
|
auto buffer = file.readAll();
|
|
|
|
|
response.set_status(fc::http::reply::OK);
|
|
|
|
|
response.set_length(buffer.size());
|
|
|
|
|
response.write(buffer.data(), buffer.size());
|
|
|
|
|
} else {
|
|
|
|
|
response.set_status(fc::http::reply::NotFound);
|
|
|
|
|
response.set_length(18);
|
|
|
|
|
response.write("I can't find that.", 18);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-08-12 15:10:40 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2015-08-12 18:56:33 +00:00
|
|
|
auto chainPtr = chain->wait();
|
|
|
|
|
engine.rootContext()->setContextProperty(QStringLiteral("blockChain"), chainPtr);
|
2015-08-12 15:10:40 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
|
|
|
|
|
2015-08-12 18:56:33 +00:00
|
|
|
auto ret = app.exec();
|
|
|
|
|
chainPtr->deleteLater();
|
|
|
|
|
chainThread.exit(ret);
|
|
|
|
|
return ret;
|
2015-08-12 15:10:40 +00:00
|
|
|
}
|