status-desktop/src-cpp/main.cpp

78 lines
2.4 KiB
C++
Raw Normal View History

2022-01-06 19:29:19 +00:00
#include "DOtherSide.h"
#include "app_controller.h"
#include "constants.h"
#include "libstatus.h"
#include "logs.h"
#include "signals.h"
#include "singleton.h"
#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
#include <QQmlApplicationEngine>
#include <QResource>
#include <QScopedPointer>
#include <iostream>
int main(int argc, char* argv[])
{
qInstallMessageHandler(logFormatter);
2022-01-06 19:29:19 +00:00
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
2022-01-06 19:29:19 +00:00
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
2022-01-06 19:29:19 +00:00
#endif
QGuiApplication app(argc, argv);
app.setOrganizationName("Status");
app.setOrganizationDomain("status.im");
app.setApplicationName("Status Desktop");
2022-01-06 19:29:19 +00:00
if(!Constants::ensureDirectories()) return 1;
2022-01-06 19:29:19 +00:00
// Init keystore
const char* initKeystoreResult = InitKeystore(Constants::applicationPath(Constants::Keystore).toUtf8().data());
QJsonObject initKeystoreJson = QJsonDocument::fromJson(initKeystoreResult).object();
if(initKeystoreJson["error"].toString() != "")
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open keystore: " + initKeystoreJson["error"].toString());
msgBox.exec();
return 1;
}
2022-01-06 19:29:19 +00:00
QScopedPointer<Signals::Manager> signalManager(Signals::Manager::instance());
2022-01-06 19:29:19 +00:00
// Registering metatypes
qRegisterMetaType<Signals::Signal>("Signal");
qRegisterMetaType<Signals::NodeSignal>("NodeSignal");
2022-01-06 19:29:19 +00:00
qInfo("starting application controller...");
AppController appController = AppController();
appController.start();
2022-01-06 19:29:19 +00:00
QResource::registerResource("../resources.rcc");
2022-01-06 19:29:19 +00:00
DOtherSide::registerMetaTypes();
2022-01-06 19:29:19 +00:00
Global::Singleton::instance()->engine()->addImportPath("qrc:/./StatusQ/src");
Global::Singleton::instance()->engine()->addImportPath("qrc:/./imports");
2022-01-06 19:29:19 +00:00
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
Global::Singleton::instance()->engine(),
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject* obj, const QUrl& objUrl) {
if(!obj && url == objUrl) QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
2022-01-06 19:29:19 +00:00
Global::Singleton::instance()->engine()->load(url);
2022-01-06 19:29:19 +00:00
qInfo("starting application...");
return app.exec();
2022-01-06 19:29:19 +00:00
}