2022-10-04 20:25:14 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
2023-09-27 12:09:20 +00:00
|
|
|
#include <QQmlContext>
|
2023-11-15 21:26:12 +00:00
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QDirIterator>
|
2022-11-17 06:17:03 +00:00
|
|
|
|
2023-10-03 15:43:35 +00:00
|
|
|
#include <QtWebView>
|
|
|
|
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2022-11-16 13:40:29 +00:00
|
|
|
#include "cachecleaner.h"
|
|
|
|
#include "directorieswatcher.h"
|
2022-11-25 15:41:50 +00:00
|
|
|
#include "figmalinks.h"
|
2023-07-31 12:21:14 +00:00
|
|
|
#include "pagesmodel.h"
|
2022-11-16 13:40:29 +00:00
|
|
|
#include "sectionsdecoratormodel.h"
|
2023-10-10 13:42:50 +00:00
|
|
|
#include "testsrunner.h"
|
2023-10-03 15:43:35 +00:00
|
|
|
#include "systemutils.h"
|
2022-10-04 20:25:14 +00:00
|
|
|
|
2023-11-15 21:26:12 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2024-10-11 15:14:21 +00:00
|
|
|
#include <StatusQ/typesregistration.h>
|
|
|
|
|
2023-07-31 12:21:14 +00:00
|
|
|
struct PagesModelInitialized : public PagesModel {
|
|
|
|
explicit PagesModelInitialized(QObject *parent = nullptr)
|
|
|
|
: PagesModel(QML_IMPORT_ROOT + QStringLiteral("/pages"), parent) {}
|
|
|
|
};
|
|
|
|
|
2023-11-15 21:26:12 +00:00
|
|
|
void loadContextPropertiesMocks(const char* storybookRoot, QQmlApplicationEngine& engine);
|
|
|
|
|
2022-10-04 20:25:14 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2023-10-03 15:43:35 +00:00
|
|
|
// Required by the WalletConnectSDK view
|
|
|
|
QtWebView::initialize();
|
|
|
|
|
2022-10-04 20:25:14 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
#endif
|
2022-10-25 13:57:04 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
2022-11-25 13:02:48 +00:00
|
|
|
|
2022-10-04 20:25:14 +00:00
|
|
|
QGuiApplication app(argc, argv);
|
2022-10-20 15:12:38 +00:00
|
|
|
QGuiApplication::setOrganizationName(QStringLiteral("Status"));
|
|
|
|
QGuiApplication::setOrganizationDomain(QStringLiteral("status.im"));
|
|
|
|
QGuiApplication::setApplicationName(QStringLiteral("Status Desktop Storybook"));
|
|
|
|
|
|
|
|
qputenv("QT_QUICK_CONTROLS_HOVER_ENABLED", QByteArrayLiteral("1"));
|
2024-10-04 15:12:07 +00:00
|
|
|
auto chromiumFlags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
|
|
|
|
if(!chromiumFlags.contains("--disable-seccomp-filter-sandbox")) {
|
|
|
|
chromiumFlags +=" --disable-seccomp-filter-sandbox";
|
|
|
|
}
|
|
|
|
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromiumFlags);
|
2022-10-04 20:25:14 +00:00
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
|
2022-10-19 19:51:39 +00:00
|
|
|
const QStringList additionalImportPaths {
|
2023-04-14 08:18:56 +00:00
|
|
|
STATUSQ_MODULE_IMPORT_PATH,
|
2022-11-17 06:17:03 +00:00
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/../ui/app"),
|
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"),
|
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/src"),
|
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/pages"),
|
2023-09-28 08:11:47 +00:00
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/stubs")
|
2022-10-18 18:47:41 +00:00
|
|
|
};
|
2022-10-04 20:25:14 +00:00
|
|
|
|
2022-10-20 15:12:38 +00:00
|
|
|
for (const auto& path : additionalImportPaths)
|
2022-10-18 18:47:41 +00:00
|
|
|
engine.addImportPath(path);
|
|
|
|
|
2023-09-27 12:09:20 +00:00
|
|
|
engine.rootContext()->setContextProperty(
|
|
|
|
"pagesFolder", QML_IMPORT_ROOT + QStringLiteral("/pages"));
|
|
|
|
|
2023-07-31 12:21:14 +00:00
|
|
|
qmlRegisterType<PagesModelInitialized>("Storybook", 1, 0, "PagesModel");
|
|
|
|
qmlRegisterType<SectionsDecoratorModel>("Storybook", 1, 0, "SectionsDecoratorModel");
|
2023-02-28 14:54:10 +00:00
|
|
|
qmlRegisterUncreatableType<FigmaLinks>("Storybook", 1, 0, "FigmaLinks", {});
|
2022-11-16 13:40:29 +00:00
|
|
|
|
2022-10-18 18:47:41 +00:00
|
|
|
auto watcherFactory = [additionalImportPaths](QQmlEngine*, QJSEngine*) {
|
|
|
|
auto watcher = new DirectoriesWatcher();
|
|
|
|
watcher->addPaths(additionalImportPaths);
|
2023-10-11 07:58:15 +00:00
|
|
|
|
|
|
|
// Test path added here as a temporary solution. Ideally, tests should
|
|
|
|
// be observed separately.
|
|
|
|
watcher->addPaths({ QML_IMPORT_ROOT + QStringLiteral("/qmlTests/tests") });
|
2022-10-18 18:47:41 +00:00
|
|
|
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);
|
|
|
|
|
2023-10-10 13:42:50 +00:00
|
|
|
auto runnerFactory = [](QQmlEngine* engine, QJSEngine*) {
|
|
|
|
return new TestsRunner(
|
|
|
|
QCoreApplication::applicationDirPath() + QStringLiteral("/QmlTests"),
|
|
|
|
QML_IMPORT_ROOT + QStringLiteral("/qmlTests/tests"));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
qmlRegisterSingletonType<TestsRunner>(
|
|
|
|
"Storybook", 1, 0, "TestsRunner", runnerFactory);
|
|
|
|
|
2023-10-03 15:43:35 +00:00
|
|
|
qmlRegisterSingletonType<SystemUtils>(
|
|
|
|
"Storybook", 1, 0, "SystemUtils", [](QQmlEngine*, QJSEngine*) {
|
|
|
|
return new SystemUtils;
|
|
|
|
});
|
|
|
|
|
2024-10-11 15:14:21 +00:00
|
|
|
registerStatusQTypes();
|
|
|
|
|
2023-11-15 21:26:12 +00:00
|
|
|
loadContextPropertiesMocks(QML_IMPORT_ROOT, engine);
|
2023-05-19 09:51:47 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
const QUrl url(QUrl::fromLocalFile(QML_IMPORT_ROOT + QStringLiteral("/main.qml")));
|
|
|
|
#else
|
2022-11-17 06:17:03 +00:00
|
|
|
const QUrl url(QML_IMPORT_ROOT + QStringLiteral("/main.qml"));
|
2023-05-19 09:51:47 +00:00
|
|
|
#endif
|
2022-10-04 20:25:14 +00:00
|
|
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
|
|
|
&app, [url](QObject *obj, const QUrl &objUrl) {
|
|
|
|
if (!obj && url == objUrl)
|
|
|
|
QCoreApplication::exit(-1);
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
engine.load(url);
|
|
|
|
|
2022-10-13 14:32:20 +00:00
|
|
|
return QGuiApplication::exec();
|
2022-10-04 20:25:14 +00:00
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
|
|
|
void loadContextPropertiesMocks(const char* storybookRoot, QQmlApplicationEngine& engine) {
|
|
|
|
QDirIterator it(QML_IMPORT_ROOT + QStringLiteral("/stubs/nim/sectionmocks"), QDirIterator::Subdirectories);
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (it.fileInfo().isFile() && it.fileInfo().suffix() == QStringLiteral("qml")) {
|
|
|
|
auto component = std::make_unique<QQmlComponent>(&engine, QUrl::fromLocalFile(it.filePath()));
|
|
|
|
if (component->status() != QQmlComponent::Ready) {
|
|
|
|
qWarning() << "Failed to load mock for" << it.filePath() << component->errorString();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto objPtr = std::unique_ptr<QObject>(component->create());
|
|
|
|
if(!objPtr) {
|
|
|
|
qWarning() << "Failed to create mock for" << it.filePath();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!objPtr->property("contextPropertyName").isValid()) {
|
|
|
|
qInfo() << "Not a mock, missing property name \"contextPropertyName\"";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto contextPropertyName = objPtr->property("contextPropertyName").toString();
|
|
|
|
auto obj = objPtr.release();
|
|
|
|
obj->setParent(&engine);
|
|
|
|
engine.rootContext()->setContextProperty(contextPropertyName, obj);
|
|
|
|
}
|
|
|
|
}
|
2024-10-11 15:14:21 +00:00
|
|
|
}
|