#include "DevHooks.h" #include "backend/TextBackend.h" #include #include #include namespace { void installAutotype(TextBackend &backend, const QString &text) { QObject::connect(&backend, &TextBackend::activeChanged, &backend, [&backend, text] { if (backend.isActive()) backend.commitText(text); }); } void installScreenshot(QQuickWindow &window, const QString &path) { constexpr int SettleMs = 500; QTimer::singleShot(SettleMs, &window, [&window, path] { const bool saved = window.grabWindow().save(path); if (!saved) qWarning("Failed to save screenshot to %s", qPrintable(path)); QCoreApplication::exit(saved ? 0 : 1); }); } } // namespace void installDevHooks(TextBackend &backend, QQuickWindow &window) { if (const QString text = qEnvironmentVariable("SLOPOSK_AUTOTYPE"); !text.isEmpty()) installAutotype(backend, text); if (const QString path = qEnvironmentVariable("SLOPOSK_SCREENSHOT"); !path.isEmpty()) installScreenshot(window, path); }