#pragma once #include "common/NetworkWorker.hpp" #include #include #include #include namespace chatterino { class NetworkTimer { std::unique_ptr timer_; bool started_{}; public: int timeoutMS_ = -1; NetworkTimer() = default; ~NetworkTimer() = default; NetworkTimer(const NetworkTimer &other) = delete; NetworkTimer &operator=(const NetworkTimer &other) = delete; NetworkTimer(NetworkTimer &&other) = default; NetworkTimer &operator=(NetworkTimer &&other) = default; void start() { if (this->timeoutMS_ <= 0) { return; } this->timer_ = std::make_unique(); this->timer_->start(this->timeoutMS_); this->started_ = true; } bool isStarted() const { return this->started_; } void onTimeout(NetworkWorker *worker, std::function cb) const { if (!this->timer_) { return; } QObject::connect(this->timer_.get(), &QTimer::timeout, worker, cb); } }; } // namespace chatterino