MCPcopy Create free account
hub / github.com/Blueforcer/awtrix3 / updateAppVector

Method updateAppVector

src/DisplayManager.cpp:1556–1634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1554}
1555
1556void DisplayManager_::updateAppVector(const char *json)
1557{
1558 if (DEBUG_MODE)
1559 DEBUG_PRINTLN(F("New apps vector received"));
1560 if (DEBUG_MODE)
1561 DEBUG_PRINTLN(json);
1562 DynamicJsonDocument doc(2048);
1563 DeserializationError error = deserializeJson(doc, json);
1564 if (error)
1565 {
1566 doc.clear();
1567 if (DEBUG_MODE)
1568 DEBUG_PRINTLN(F("Failed to parse json"));
1569 return;
1570 }
1571
1572 JsonArray appArray;
1573 if (doc.is<JsonObject>())
1574 {
1575 JsonArray tempArray = doc.to<JsonArray>();
1576 tempArray.add(doc.as<JsonObject>());
1577 appArray = tempArray;
1578 }
1579 else if (doc.is<JsonArray>())
1580 {
1581 appArray = doc.as<JsonArray>();
1582 }
1583
1584 for (JsonObject appObj : appArray)
1585 {
1586 String appName = appObj["name"].as<String>();
1587 bool show = appObj["show"].as<bool>();
1588 int position = appObj.containsKey("pos") ? appObj["pos"].as<int>() : Apps.size();
1589
1590 auto appIt = std::find_if(Apps.begin(), Apps.end(), [&appName](const std::pair<String, AppCallback> &app)
1591 { return app.first == appName; });
1592
1593 std::pair<String, AppCallback> nativeApp = getNativeAppByName(appName);
1594
1595 if (!show)
1596 {
1597 if (appIt != Apps.end())
1598 {
1599 Apps.erase(appIt);
1600 }
1601 }
1602 else
1603 {
1604 if (nativeApp.second != nullptr)
1605 {
1606 if (appIt != Apps.end())
1607 {
1608 Apps.erase(appIt);
1609 }
1610 position = position < 0 ? 0 : position >= Apps.size() ? Apps.size()
1611 : position;
1612 Apps.insert(Apps.begin() + position, nativeApp);
1613 }

Callers 2

processMqttMessageFunction · 0.80
addHandlerFunction · 0.80

Calls 7

getNativeAppByNameFunction · 0.85
saveSettingsFunction · 0.85
addMethod · 0.80
eraseMethod · 0.80
setAppsMethod · 0.80
clearMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected