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

This commit is contained in:
Dean Lee
2022-09-09 07:46:52 +08:00
committed by GitHub
parent 0028e062b8
commit 4974ca03a8
2 changed files with 11 additions and 7 deletions
+9 -7
View File
@@ -18,21 +18,23 @@
using qrcodegen::QrCode;
PairingQRWidget::PairingQRWidget(QWidget* parent) : QWidget(parent) {
QTimer* timer = new QTimer(this);
timer->start(5 * 60 * 1000);
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &PairingQRWidget::refresh);
}
void PairingQRWidget::showEvent(QShowEvent *event) {
refresh();
timer->start(5 * 60 * 1000);
}
void PairingQRWidget::hideEvent(QHideEvent *event) {
timer->stop();
}
void PairingQRWidget::refresh() {
if (isVisible()) {
QString pairToken = CommaApi::create_jwt({{"pair", true}});
QString qrString = "https://connect.comma.ai/?pair=" + pairToken;
this->updateQrCode(qrString);
}
QString pairToken = CommaApi::create_jwt({{"pair", true}});
QString qrString = "https://connect.comma.ai/?pair=" + pairToken;
this->updateQrCode(qrString);
}
void PairingQRWidget::updateQrCode(const QString &text) {
+2
View File
@@ -25,8 +25,10 @@ public:
private:
QPixmap img;
QTimer *timer;
void updateQrCode(const QString &text);
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
private slots:
void refresh();