status-desktop/storybook/main.cpp

71 lines
2.3 KiB
C++
Raw Normal View History

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#ifdef QT_WEBENGINE_LIB
#include <QtWebEngine>
#endif
#include "cachecleaner.h"
#include "directorieswatcher.h"
#include "sectionsdecoratormodel.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#ifdef QT_WEBENGINE_LIB
QtWebEngine::initialize();
#endif
QGuiApplication app(argc, argv);
QGuiApplication::setOrganizationName(QStringLiteral("Status"));
QGuiApplication::setOrganizationDomain(QStringLiteral("status.im"));
QGuiApplication::setApplicationName(QStringLiteral("Status Desktop Storybook"));
qputenv("QT_QUICK_CONTROLS_HOVER_ENABLED", QByteArrayLiteral("1"));
QQmlApplicationEngine engine;
const QStringList additionalImportPaths {
QML_IMPORT_ROOT + QStringLiteral("/../ui/StatusQ/src"),
QML_IMPORT_ROOT + QStringLiteral("/../ui/app"),
QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"),
QML_IMPORT_ROOT + QStringLiteral("/src"),
QML_IMPORT_ROOT + QStringLiteral("/pages"),
QML_IMPORT_ROOT + QStringLiteral("/stubs"),
QML_IMPORT_ROOT + QStringLiteral("/mocks"),
};
for (const auto& path : additionalImportPaths)
engine.addImportPath(path);
qmlRegisterType<SectionsDecoratorModel>("Storybook", 1, 0, "SectionsDecoratorModel");
auto watcherFactory = [additionalImportPaths](QQmlEngine*, QJSEngine*) {
auto watcher = new DirectoriesWatcher();
watcher->addPaths(additionalImportPaths);
return watcher;
};
qmlRegisterSingletonType<DirectoriesWatcher>(
"Storybook", 1, 0, "SourceWatcher", watcherFactory);
auto cleanerFactory = [](QQmlEngine* engine, QJSEngine*) {
return new CacheCleaner(engine);
};
qmlRegisterSingletonType<CacheCleaner>(
"Storybook", 1, 0, "CacheCleaner", cleanerFactory);
const QUrl url(QML_IMPORT_ROOT + QStringLiteral("/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return QGuiApplication::exec();
}