ui: stop timer if PairingQRWidget is hidden (#25671)

pull/25607/head^2
Dean Lee 3 years ago committed by GitHub
parent 0028e062b8
commit 4974ca03a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      selfdrive/ui/qt/widgets/prime.cc
  2. 2
      selfdrive/ui/qt/widgets/prime.h

@ -18,21 +18,23 @@
using qrcodegen::QrCode; using qrcodegen::QrCode;
PairingQRWidget::PairingQRWidget(QWidget* parent) : QWidget(parent) { PairingQRWidget::PairingQRWidget(QWidget* parent) : QWidget(parent) {
QTimer* timer = new QTimer(this); timer = new QTimer(this);
timer->start(5 * 60 * 1000);
connect(timer, &QTimer::timeout, this, &PairingQRWidget::refresh); connect(timer, &QTimer::timeout, this, &PairingQRWidget::refresh);
} }
void PairingQRWidget::showEvent(QShowEvent *event) { void PairingQRWidget::showEvent(QShowEvent *event) {
refresh(); refresh();
timer->start(5 * 60 * 1000);
}
void PairingQRWidget::hideEvent(QHideEvent *event) {
timer->stop();
} }
void PairingQRWidget::refresh() { void PairingQRWidget::refresh() {
if (isVisible()) { QString pairToken = CommaApi::create_jwt({{"pair", true}});
QString pairToken = CommaApi::create_jwt({{"pair", true}}); QString qrString = "https://connect.comma.ai/?pair=" + pairToken;
QString qrString = "https://connect.comma.ai/?pair=" + pairToken; this->updateQrCode(qrString);
this->updateQrCode(qrString);
}
} }
void PairingQRWidget::updateQrCode(const QString &text) { void PairingQRWidget::updateQrCode(const QString &text) {

@ -25,8 +25,10 @@ public:
private: private:
QPixmap img; QPixmap img;
QTimer *timer;
void updateQrCode(const QString &text); void updateQrCode(const QString &text);
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
private slots: private slots:
void refresh(); void refresh();

Loading…
Cancel
Save