#pragma once #include "debug/AssertInGuiThread.hpp" #include #include namespace chatterino { static void postToThread(auto &&f, QObject *obj = QCoreApplication::instance()) { QMetaObject::invokeMethod(obj, std::forward(f)); } static void runInGuiThread(auto &&fun) { if (isGuiThread()) { fun(); } else { postToThread(std::forward(fun)); } } inline void postToGuiThread(auto &&fun) { assert(!isGuiThread() && "postToGuiThread must be called from a non-GUI thread"); postToThread(std::forward(fun)); } } // namespace chatterino