diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index 8ce48becdb592f..ea34b35e6a79fe 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -107,8 +107,7 @@ void TermsPage::enableAccept(){ } void OnboardingWindow::updateActiveScreen() { - bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; - bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; + updateOnboardingStatus(); if (!accepted_terms) { setCurrentIndex(0); @@ -157,3 +156,13 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { updateActiveScreen(); } + +void OnboardingWindow::updateOnboardingStatus() { + accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; + training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; +} + +bool OnboardingWindow::isOnboardingDone() { + updateOnboardingStatus(); + return accepted_terms && training_done; +} diff --git a/selfdrive/ui/qt/offroad/onboarding.h b/selfdrive/ui/qt/offroad/onboarding.h index 987fad336c9fd2..92a9b971fcaccb 100644 --- a/selfdrive/ui/qt/offroad/onboarding.h +++ b/selfdrive/ui/qt/offroad/onboarding.h @@ -77,11 +77,15 @@ class OnboardingWindow : public QStackedWidget { public: explicit OnboardingWindow(QWidget *parent = 0); + bool isOnboardingDone(); private: Params params; std::string current_terms_version; std::string current_training_version; + bool accepted_terms = false; + bool training_done = false; + void updateOnboardingStatus(); signals: void onboardingDone(); diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 864dabf1586aed..f10fce403a4727 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -22,10 +22,14 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, this, &MainWindow::reviewTrainingGuide); onboardingWindow = new OnboardingWindow(this); + onboardingDone = onboardingWindow->isOnboardingDone(); main_layout->addWidget(onboardingWindow); main_layout->setCurrentWidget(onboardingWindow); - QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, this, &MainWindow::closeSettings); + QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, [=](){ + onboardingDone = true; + closeSettings(); + }); onboardingWindow->updateActiveScreen(); device.setAwake(true, true); @@ -59,10 +63,13 @@ void MainWindow::openSettings() { } void MainWindow::closeSettings() { - main_layout->setCurrentWidget(homeWindow); + if(onboardingDone) { + main_layout->setCurrentWidget(homeWindow); + } } void MainWindow::reviewTrainingGuide() { + onboardingDone = false; main_layout->setCurrentWidget(onboardingWindow); onboardingWindow->updateActiveScreen(); } diff --git a/selfdrive/ui/qt/window.h b/selfdrive/ui/qt/window.h index 9d3a2a8912d77c..5a40e94bb2042b 100644 --- a/selfdrive/ui/qt/window.h +++ b/selfdrive/ui/qt/window.h @@ -25,6 +25,7 @@ class MainWindow : public QWidget { HomeWindow *homeWindow; SettingsWindow *settingsWindow; OnboardingWindow *onboardingWindow; + bool onboardingDone = false; public slots: void offroadTransition(bool offroad);