mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-04 13:02:09 +08:00
Qt system reset (#19502)
* qt factory reset * confirmation * better ui old-commit-hash: c4a05ba369a0b8ce5df69727999dd33baf8a0fd0
This commit is contained in:
@@ -4,4 +4,5 @@ moc_*
|
||||
qt/text
|
||||
qt/spinner
|
||||
qt/setup/setup
|
||||
qt/setup/reset
|
||||
qt/setup/installer*
|
||||
|
||||
@@ -74,20 +74,21 @@ else:
|
||||
|
||||
qt_env.Library("qt_widgets",
|
||||
["qt/qt_window.cc", "qt/qt_sound.cc", "qt/widgets/keyboard.cc", "qt/widgets/input_field.cc",
|
||||
"qt/offroad/wifi.cc", "qt/offroad/wifiManager.cc", "qt/widgets/toggle.cc", "qt/widgets/offroad_alerts.cc"],
|
||||
"qt/offroad/wifi.cc", "qt/offroad/wifiManager.cc", "qt/widgets/toggle.cc"],
|
||||
LIBS=qt_libs)
|
||||
qt_libs.append("qt_widgets")
|
||||
|
||||
qt_src = ["qt/ui.cc", "qt/window.cc", "qt/home.cc", "qt/offroad/settings.cc", "qt/offroad/onboarding.cc"] + src
|
||||
qt_src = ["qt/ui.cc", "qt/window.cc", "qt/home.cc", "qt/offroad/settings.cc", "qt/offroad/onboarding.cc", "qt/widgets/offroad_alerts.cc"] + src
|
||||
qt_env.Program("_ui", qt_src, LIBS=qt_libs + libs)
|
||||
|
||||
# spinner and text window
|
||||
qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs + libs)
|
||||
qt_env.Program("qt/spinner", ["qt/spinner.cc"], LIBS=qt_libs + libs)
|
||||
|
||||
# setup and installer
|
||||
# build setup, factory resetter, and installer
|
||||
if "BUILD_SETUP" in os.environ:
|
||||
qt_env.Program("qt/setup/setup", ["qt/setup/setup.cc"], LIBS=qt_libs + ['curl'])
|
||||
qt_env.Program("qt/setup/reset", ["qt/setup/reset.cc"], LIBS=qt_libs)
|
||||
qt_env.Program("qt/setup/setup", ["qt/setup/setup.cc"], LIBS=qt_libs + ['curl', 'common'])
|
||||
|
||||
installers = [
|
||||
("openpilot", "master"),
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
|
||||
#include "qt_window.hpp"
|
||||
|
||||
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
||||
|
||||
|
||||
void do_reset() {
|
||||
std::system("sudo umount " USERDATA);
|
||||
std::system("yes | sudo mkfs.ext4 " USERDATA);
|
||||
std::system("sudo reboot");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
QWidget window;
|
||||
setMainWindow(&window);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(125, 125, 125, 125);
|
||||
|
||||
QLabel *title = new QLabel("System Reset");
|
||||
title->setStyleSheet(R"(
|
||||
font-size: 100px;
|
||||
font-weight: bold;
|
||||
)");
|
||||
layout->addWidget(title, 0, Qt::AlignTop);
|
||||
|
||||
QLabel *body = new QLabel("Factory reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.");
|
||||
body->setWordWrap(true);
|
||||
body->setAlignment(Qt::AlignCenter);
|
||||
body->setStyleSheet(R"(
|
||||
font-size: 65px;
|
||||
)");
|
||||
layout->addWidget(body, 1, Qt::AlignCenter);
|
||||
|
||||
QHBoxLayout *btn_layout = new QHBoxLayout();
|
||||
|
||||
QPushButton *cancel_btn = new QPushButton("Cancel");
|
||||
btn_layout->addWidget(cancel_btn, 0, Qt::AlignLeft);
|
||||
QObject::connect(cancel_btn, SIGNAL(released()), &a, SLOT(quit()));
|
||||
|
||||
QPushButton *confirm_btn = new QPushButton("Confirm");
|
||||
btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight);
|
||||
QObject::connect(confirm_btn, &QPushButton::released, [=]() {
|
||||
QString confirm_txt = "Are you sure you want to reset your device?";
|
||||
if (body->text() != confirm_txt) {
|
||||
body->setText(confirm_txt);
|
||||
} else {
|
||||
body->setText("Resetting device...");
|
||||
cancel_btn->hide();
|
||||
confirm_btn->hide();
|
||||
#ifdef __aarch64__
|
||||
do_reset();
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
layout->addLayout(btn_layout);
|
||||
|
||||
window.setLayout(layout);
|
||||
window.setStyleSheet(R"(
|
||||
* {
|
||||
color: white;
|
||||
background-color: black;
|
||||
}
|
||||
QPushButton {
|
||||
padding: 50px;
|
||||
padding-right: 100px;
|
||||
padding-left: 100px;
|
||||
border: 7px solid white;
|
||||
border-radius: 20px;
|
||||
font-size: 50px;
|
||||
}
|
||||
)");
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user