mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-25 07:52:03 +08:00
ui: stop timer if PairingQRWidget is hidden (#25671)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user