mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-30 19:33:42 +08:00
Update UI fixes/improvements (#21089)
* Show latest update time * utc * make work more than once * cleanup * whitespace * only while offroad
This commit is contained in:
@@ -43,6 +43,10 @@ public:
|
|||||||
return get(key.c_str(), block);
|
return get(key.c_str(), block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string getParamsPath() {
|
||||||
|
return params_path;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::optional<T> get(const char *key, bool block = false) {
|
std::optional<T> get(const char *key, bool block = false) {
|
||||||
std::istringstream iss(get(key, block));
|
std::istringstream iss(get(key, block));
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) {
|
|||||||
|
|
||||||
DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||||
QVBoxLayout *device_layout = new QVBoxLayout;
|
QVBoxLayout *device_layout = new QVBoxLayout;
|
||||||
|
|
||||||
Params params = Params();
|
Params params = Params();
|
||||||
|
|
||||||
QString dongle = QString::fromStdString(params.get("DongleId", false));
|
QString dongle = QString::fromStdString(params.get("DongleId", false));
|
||||||
@@ -209,30 +208,49 @@ DeveloperPanel::DeveloperPanel(QWidget* parent) : QFrame(parent) {
|
|||||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
setLayout(main_layout);
|
setLayout(main_layout);
|
||||||
setStyleSheet(R"(QLabel {font-size: 50px;})");
|
setStyleSheet(R"(QLabel {font-size: 50px;})");
|
||||||
|
|
||||||
|
fs_watch = new QFileSystemWatcher(this);
|
||||||
|
QObject::connect(fs_watch, &QFileSystemWatcher::fileChanged, [=](const QString path) {
|
||||||
|
updateLabels();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeveloperPanel::showEvent(QShowEvent *event) {
|
void DeveloperPanel::showEvent(QShowEvent *event) {
|
||||||
|
updateLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeveloperPanel::updateLabels() {
|
||||||
Params params = Params();
|
Params params = Params();
|
||||||
std::string brand = params.getBool("Passive") ? "dashcam" : "openpilot";
|
std::string brand = params.getBool("Passive") ? "dashcam" : "openpilot";
|
||||||
QList<QPair<QString, std::string>> dev_params = {
|
QList<QPair<QString, std::string>> dev_params = {
|
||||||
{"Git Branch", params.get("GitBranch", false)},
|
{"Git Branch", params.get("GitBranch")},
|
||||||
{"Git Commit", params.get("GitCommit", false).substr(0, 10)},
|
{"Git Commit", params.get("GitCommit").substr(0, 10)},
|
||||||
{"Panda Firmware", params.get("PandaFirmwareHex", false)},
|
{"Panda Firmware", params.get("PandaFirmwareHex")},
|
||||||
{"OS Version", Hardware::get_os_version()},
|
{"OS Version", Hardware::get_os_version()},
|
||||||
};
|
};
|
||||||
|
|
||||||
QString version = QString::fromStdString(brand + " v" + params.get("Version", false).substr(0, 14)).trimmed();
|
QString version = QString::fromStdString(brand + " v" + params.get("Version").substr(0, 14)).trimmed();
|
||||||
QDateTime lastUpdateDate = QDateTime::fromString(QString::fromStdString(params.get("LastUpdateTime", false)), Qt::ISODate);
|
QString lastUpdateTime = "";
|
||||||
QString lastUpdateTime = timeAgo(lastUpdateDate);
|
|
||||||
|
std::string last_update_param = params.get("LastUpdateTime");
|
||||||
|
if (!last_update_param.empty()){
|
||||||
|
QDateTime lastUpdateDate = QDateTime::fromString(QString::fromStdString(last_update_param + "Z"), Qt::ISODate);
|
||||||
|
lastUpdateTime = timeAgo(lastUpdateDate);
|
||||||
|
}
|
||||||
|
|
||||||
if (labels.size() < dev_params.size()) {
|
if (labels.size() < dev_params.size()) {
|
||||||
versionLbl = new LabelControl("Version", version, QString::fromStdString(params.get("ReleaseNotes", false)).trimmed());
|
versionLbl = new LabelControl("Version", version, QString::fromStdString(params.get("ReleaseNotes")).trimmed());
|
||||||
layout()->addWidget(versionLbl);
|
layout()->addWidget(versionLbl);
|
||||||
layout()->addWidget(horizontal_line());
|
layout()->addWidget(horizontal_line());
|
||||||
|
|
||||||
lastUpdateTimeLbl = new LabelControl("Last Update Check", lastUpdateTime, "The last time openpilot checked for an update.");
|
lastUpdateTimeLbl = new LabelControl("Last Update Check", lastUpdateTime, "The last time openpilot checked for an update. Updates are only checked while off-road.");
|
||||||
connect(lastUpdateTimeLbl, &LabelControl::showDescription, [=]() {
|
connect(lastUpdateTimeLbl, &LabelControl::showDescription, [=]() {
|
||||||
std::system("pkill -1 -f selfdrive.updated");
|
Params params = Params();
|
||||||
|
if (params.getBool("IsOffroad")) {
|
||||||
|
fs_watch->addPath(QString::fromStdString(params.getParamsPath()) + "/d/LastUpdateTime");
|
||||||
|
lastUpdateTimeLbl->setText("checking...");
|
||||||
|
std::system("pkill -1 -f selfdrive.updated");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
layout()->addWidget(lastUpdateTimeLbl);
|
layout()->addWidget(lastUpdateTimeLbl);
|
||||||
layout()->addWidget(horizontal_line());
|
layout()->addWidget(horizontal_line());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
|
||||||
#include "selfdrive/ui/qt/widgets/controls.h"
|
#include "selfdrive/ui/qt/widgets/controls.h"
|
||||||
|
|
||||||
// ********** settings window + top-level panels **********
|
// ********** settings window + top-level panels **********
|
||||||
@@ -39,6 +41,9 @@ private:
|
|||||||
QList<LabelControl *> labels;
|
QList<LabelControl *> labels;
|
||||||
LabelControl *versionLbl;
|
LabelControl *versionLbl;
|
||||||
LabelControl *lastUpdateTimeLbl;
|
LabelControl *lastUpdateTimeLbl;
|
||||||
|
void updateLabels();
|
||||||
|
|
||||||
|
QFileSystemWatcher *fs_watch;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SettingsWindow : public QFrame {
|
class SettingsWindow : public QFrame {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ inline void clearLayout(QLayout* layout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline QString timeAgo(const QDateTime &date) {
|
inline QString timeAgo(const QDateTime &date) {
|
||||||
int diff = date.secsTo(QDateTime::currentDateTime());
|
int diff = date.secsTo(QDateTime::currentDateTimeUtc());
|
||||||
|
|
||||||
QString s;
|
QString s;
|
||||||
if (diff < 60) {
|
if (diff < 60) {
|
||||||
|
|||||||
Reference in New Issue
Block a user