mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-24 05:32:10 +08:00
navd: Auto detect custom Mapbox token (#285)
* navd: Auto detect custom Mapbox token * cleanup
This commit is contained in:
@@ -224,7 +224,6 @@ std::unordered_map<std::string, uint32_t> keys = {
|
||||
{"CarModelText", PERSISTENT},
|
||||
{"ChevronInfo", PERSISTENT},
|
||||
{"CustomBootScreen", PERSISTENT},
|
||||
{"CustomMapbox", PERSISTENT},
|
||||
{"CustomMapboxTokenPk", PERSISTENT},
|
||||
{"CustomMapboxTokenSk", PERSISTENT},
|
||||
{"CustomOffsets", PERSISTENT},
|
||||
|
||||
@@ -48,8 +48,8 @@ class RouteEngine:
|
||||
|
||||
self.reroute_counter = 0
|
||||
|
||||
if self.params.get_bool("CustomMapbox") or "MAPBOX_TOKEN" in os.environ:
|
||||
self.mapbox_token = self.params.get("CustomMapboxTokenSk") if self.params.get_bool("CustomMapbox") else os.environ["MAPBOX_TOKEN"]
|
||||
if self.params.get("CustomMapboxTokenSk") is not None or "MAPBOX_TOKEN" in os.environ:
|
||||
self.mapbox_token = self.params.get("CustomMapboxTokenSk") if self.params.get("CustomMapboxTokenSk") is not None else os.environ["MAPBOX_TOKEN"]
|
||||
self.mapbox_host = "https://api.mapbox.com"
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -172,15 +172,15 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) {
|
||||
#else
|
||||
left_widget->addWidget(new DriveStats);
|
||||
#endif
|
||||
custom_mapbox = params.getBool("CustomMapbox") && QString::fromStdString(params.get("CustomMapboxTokenSk")) != "";
|
||||
custom_mapbox = QString::fromStdString(params.get("CustomMapboxTokenSk")) != "";
|
||||
if (!custom_mapbox) {
|
||||
left_widget->addWidget(new PrimeAdWidget);
|
||||
}
|
||||
left_widget->setStyleSheet("border-radius: 10px;");
|
||||
|
||||
left_widget->setCurrentIndex(!custom_mapbox ? uiState()->hasPrime() ? 0 : 1 : 0);
|
||||
connect(uiState(), &UIState::primeChanged, [=](int prime) {
|
||||
left_widget->setCurrentIndex(!custom_mapbox ? prime ? 0 : 1 : 0);
|
||||
left_widget->setCurrentIndex((uiState()->hasPrime() || custom_mapbox) ? 0 : 1);
|
||||
connect(uiState(), &UIState::primeChanged, [=](bool prime) {
|
||||
left_widget->setCurrentIndex((prime || custom_mapbox) ? 0 : 1);
|
||||
});
|
||||
|
||||
home_layout->addWidget(left_widget, 1);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "cereal/messaging/messaging.h"
|
||||
#include "common/params.h"
|
||||
|
||||
const QString MAPBOX_TOKEN = Params().getBool("CustomMapbox") ? QString::fromStdString(Params().get("CustomMapboxTokenSk")) : util::getenv("MAPBOX_TOKEN").c_str();
|
||||
const QString MAPBOX_TOKEN = QString::fromStdString(Params().get("CustomMapboxTokenSk")) != "" ? QString::fromStdString(Params().get("CustomMapboxTokenSk")) : util::getenv("MAPBOX_TOKEN").c_str();
|
||||
const QString MAPS_HOST = util::getenv("MAPS_HOST", MAPBOX_TOKEN.isEmpty() ? "https://maps.comma.ai" : "https://api.mapbox.com").c_str();
|
||||
const QString MAPS_CACHE_PATH = "/data/mbgl-cache-navd.db";
|
||||
|
||||
|
||||
@@ -635,19 +635,6 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : ListWidget(parent) {
|
||||
tr("OSM: Show UI elements that aid debugging."),
|
||||
"../assets/offroad/icon_calibration.png",
|
||||
},
|
||||
{
|
||||
"CustomMapbox",
|
||||
tr("Enable Mapbox Navigation*"),
|
||||
QString("%1<br>"
|
||||
"%2<br>"
|
||||
"%3<br>"
|
||||
"<h4>%4</h4>")
|
||||
.arg(tr("Enable built-in navigation on sunnypilot, powered by Mapbox."))
|
||||
.arg(tr("Access via the web interface: \"http://<device_ip>:8082\""))
|
||||
.arg(tr("If you do not have comma Prime, you will need to provide your own Mapbox token at https://mapbox.com/. Reach out to sunnyhaibin#0865 on Discord for more information."))
|
||||
.arg(tr("Huge thanks to the dragonpilot team for making this possible!")),
|
||||
"../assets/img_map.png",
|
||||
},
|
||||
{
|
||||
"TrueVEgoUi",
|
||||
tr("Speedometer: Display True Speed"),
|
||||
@@ -701,14 +688,6 @@ SPVisualsPanel::SPVisualsPanel(QWidget *parent) : ListWidget(parent) {
|
||||
|
||||
// trigger offroadTransition when going onroad/offroad
|
||||
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
||||
toggles["CustomMapbox"]->setEnabled(offroad);
|
||||
});
|
||||
|
||||
// trigger hardwrae reboot if user confirms the selection
|
||||
connect(toggles["CustomMapbox"], &ToggleControl::toggleFlipped, [=](bool state) {
|
||||
if (ConfirmationDialog::confirm(tr("\"Enable Mapbox Navigation\"\nYou must restart your car or your device to apply these changes.\nReboot now?"), "Reboot", parent)) {
|
||||
Hardware::reboot();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -235,8 +235,7 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
|
||||
void OnroadWindow::offroadTransition(bool offroad) {
|
||||
if (!offroad) {
|
||||
#ifdef ENABLE_MAPS
|
||||
bool custom_mapbox = params.getBool("CustomMapbox") && QString::fromStdString(params.get("CustomMapboxTokenSk")) != "";
|
||||
if (map == nullptr && (uiState()->hasPrime() || !MAPBOX_TOKEN.isEmpty() || custom_mapbox)) {
|
||||
if (map == nullptr && (uiState()->hasPrime() || !MAPBOX_TOKEN.isEmpty())) {
|
||||
auto m = new MapPanel(get_mapbox_settings());
|
||||
map = m;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user