diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.cc b/selfdrive/ui/qt/widgets/offroad_alerts.cc index 26a2f7e5a9..4135b24077 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.cc +++ b/selfdrive/ui/qt/widgets/offroad_alerts.cc @@ -59,6 +59,13 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) { } )"); main_layout->setMargin(50); + + QFile inFile("../controls/lib/alerts_offroad.json"); + bool ret = inFile.open(QIODevice::ReadOnly | QIODevice::Text); + assert(ret); + QJsonDocument doc = QJsonDocument::fromJson(inFile.readAll()); + assert(!doc.isNull()); + alert_keys = doc.object().keys(); } void OffroadAlert::refresh() { @@ -109,20 +116,7 @@ void OffroadAlert::refresh() { void OffroadAlert::parse_alerts() { alerts.clear(); - - // TODO: only read this once - QFile inFile("../controls/lib/alerts_offroad.json"); - inFile.open(QIODevice::ReadOnly | QIODevice::Text); - QByteArray data = inFile.readAll(); - inFile.close(); - - QJsonDocument doc = QJsonDocument::fromJson(data); - if (doc.isNull()) { - qDebug() << "Parse failed"; - } - - QJsonObject json = doc.object(); - for (const QString &key : json.keys()) { + for (const QString &key : alert_keys) { std::vector bytes = Params().read_db_bytes(key.toStdString().c_str()); if (bytes.size()) { diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.hpp b/selfdrive/ui/qt/widgets/offroad_alerts.hpp index edd37dd898..ec48f89c7e 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.hpp +++ b/selfdrive/ui/qt/widgets/offroad_alerts.hpp @@ -3,6 +3,7 @@ #include #include #include +#include struct Alert { QString text; @@ -15,6 +16,7 @@ class OffroadAlert : public QFrame { public: explicit OffroadAlert(QWidget *parent = 0); QVector alerts; + QStringList alert_keys; bool updateAvailable; private: