Dont make request every time menu is visited
This commit is contained in:
@ -25,6 +25,7 @@ namespace {
|
||||
bool request_running = false;
|
||||
uint16_t request_failed = false;
|
||||
bool parsing_finished = false;
|
||||
static bool redownload = true;
|
||||
cpputils::DelayedConstruction<AsyncHttpRequest> request;
|
||||
|
||||
std::string get_ota_url_from_index(uint16_t index)
|
||||
@ -95,9 +96,9 @@ namespace {
|
||||
}
|
||||
|
||||
JsonObject availableVersionsObject = doc["availableVersions"];
|
||||
static auto index = 0;
|
||||
for (JsonPair kv : availableVersionsObject)
|
||||
{
|
||||
static auto index = 0;
|
||||
auto hash = kv.key().c_str();
|
||||
if (index > availableVersions.size())
|
||||
{
|
||||
@ -107,9 +108,12 @@ namespace {
|
||||
index++;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
|
||||
url_for_latest = fix_url(fmt::format("{}{}", stringSettings.otaServerUrl, doc["latest"].as<std::string>()));
|
||||
url_for_hashes = fix_url(fmt::format("{}{}", stringSettings.otaServerUrl, doc["url"].as<std::string>()));
|
||||
parsing_finished = true;
|
||||
redownload = false;
|
||||
}
|
||||
|
||||
void setup_request()
|
||||
@ -120,6 +124,11 @@ namespace {
|
||||
|
||||
void start_descriptor_request(std::string server_base_url)
|
||||
{
|
||||
if (!redownload)
|
||||
{
|
||||
parsing_finished = true;
|
||||
return;
|
||||
}
|
||||
if (!request.constructed())
|
||||
{
|
||||
ESP_LOGW("BOBBY", "request is im oarsch");
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
// local includes
|
||||
#include "menudisplay.h"
|
||||
#include "actioninterface.h"
|
||||
#include "utils.h"
|
||||
#include "actions/dummyaction.h"
|
||||
#include "icons/back.h"
|
||||
#include "icons/update.h"
|
||||
#include "icons/presets.h"
|
||||
#include "texts.h"
|
||||
#include "buildserver.h"
|
||||
|
||||
|
||||
// forward declares
|
||||
@ -22,6 +24,13 @@ using namespace espgui;
|
||||
|
||||
namespace {
|
||||
|
||||
class RedownloadJsonAction : public virtual ActionInterface {
|
||||
public:
|
||||
void triggered() override {
|
||||
redownload = true;
|
||||
}
|
||||
};
|
||||
|
||||
class OtaMenu :
|
||||
public MenuDisplay,
|
||||
public StaticText<TEXT_UPDATE>,
|
||||
@ -33,6 +42,7 @@ public:
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTBUILD>, SwitchScreenAction<SelectBuildMenu>, StaticMenuItemIcon<&bobbyicons::presets>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UPDATENOW>, SwitchScreenAction<UpdateDisplay>, StaticMenuItemIcon<&bobbyicons::update>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTBUILDSERVERMENU>, SwitchScreenAction<SelectBuildServerMenu>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_REDOWNLOAD>, RedownloadJsonAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
};
|
||||
|
@ -482,6 +482,7 @@ constexpr char TEXT_OTA_NOBUILDSERVERAVAILABLE[] = "E:No server saved.";
|
||||
constexpr char TEXT_OTA_NOBUILDSERVERSELECTED[] = "E:No server selected.";
|
||||
constexpr char TEXT_OTA_NOCONNECTION[] = "E:No internet.";
|
||||
constexpr char TEXT_OTA_WAITFORRESPONSE[] = "Wait for response...";
|
||||
constexpr char TEXT_REDOWNLOAD[] = "Reload list";
|
||||
|
||||
#ifdef FEATURE_CAN
|
||||
constexpr char TEXT_POWERSUPPLY[] = "Powersupply";
|
||||
|
Reference in New Issue
Block a user