Skip to content

Commit 8d4a75f

Browse files
committed
Clean up CoPilot actions
1 parent 45f6f8b commit 8d4a75f

File tree

2 files changed

+28
-62
lines changed

2 files changed

+28
-62
lines changed

src/graphics/draw/MenuHandler.cpp

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,102 +1296,70 @@ void menuHandler::NodePicker()
12961296

12971297
void menuHandler::ManageNodeMenu()
12981298
{
1299-
// If we don't have a node selected yet, prompt for one and then return — the callback will re-enter this menu
1299+
// If we don't have a node selected yet, go fast exit
13001300
auto node = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
13011301
if (!node) {
13021302
return;
13031303
}
1304+
enum optionsNumbers { Back, Favorite, Mute, TraceRoute, KeyVerification, Ignore, enumEnd };
1305+
static const char *optionsArray[enumEnd] = {"Back"};
1306+
static int optionsEnumArray[enumEnd] = {Back};
1307+
int options = 1;
13041308

1305-
// Build dynamic options so labels reflect the node's current state
1306-
enum ManageNodeMenuAction {
1307-
MN_Back = 0,
1308-
MN_Favorite = 1,
1309-
MN_Mute = 2,
1310-
MN_TraceRoute = 3,
1311-
MN_KeyVerification = 4,
1312-
MN_Ignore = 5
1313-
};
1314-
1315-
static std::vector<std::string> labelStrs;
1316-
static std::vector<const char *> labels;
1317-
static std::vector<int> ids;
1318-
labelStrs.clear();
1319-
labels.clear();
1320-
ids.clear();
1321-
1322-
// Back
1323-
labelStrs.emplace_back("Back");
1324-
ids.push_back(MN_Back);
1325-
1326-
// Favorite / Unfavorite
13271309
if (node->is_favorite) {
1328-
labelStrs.emplace_back("Unfavorite");
1310+
optionsArray[options] = "Unfavorite";
13291311
} else {
1330-
labelStrs.emplace_back("Favorite");
1312+
optionsArray[options] = "Favorite";
13311313
}
1332-
ids.push_back(MN_Favorite);
1314+
optionsEnumArray[options++] = Favorite;
13331315

1334-
// Mute / Unmute Notifications
13351316
bool isMuted = (node->bitfield & NODEINFO_BITFIELD_IS_MUTED_MASK) != 0;
13361317
if (isMuted) {
1337-
labelStrs.emplace_back("Unmute Notifications");
1318+
optionsArray[options] = "Unmute Notifications";
13381319
} else {
1339-
labelStrs.emplace_back("Mute Notifications");
1320+
optionsArray[options] = "Mute Notifications";
13401321
}
1341-
ids.push_back(MN_Mute);
1322+
optionsEnumArray[options++] = Mute;
13421323

1343-
// Trace route
1344-
labelStrs.emplace_back("Trace Route");
1345-
ids.push_back(MN_TraceRoute);
1324+
optionsArray[options] = "Trace Route";
1325+
optionsEnumArray[options++] = TraceRoute;
13461326

1347-
// Key verification
1348-
labelStrs.emplace_back("Key Verification");
1349-
ids.push_back(MN_KeyVerification);
1327+
optionsArray[options] = "Key Verification";
1328+
optionsEnumArray[options++] = KeyVerification;
13501329

1351-
// Ignore / Unignore
13521330
if (node->is_ignored) {
1353-
labelStrs.emplace_back("Unignore Node");
1331+
optionsArray[options] = "Unignore Node";
13541332
} else {
1355-
labelStrs.emplace_back("Ignore Node");
1333+
optionsArray[options] = "Ignore Node";
13561334
}
1357-
ids.push_back(MN_Ignore);
1335+
optionsEnumArray[options++] = Ignore;
13581336

1359-
// Move c_str pointers into labels (must keep labelStrs alive while we show the banner)
1360-
labels.reserve(labelStrs.size());
1361-
for (auto &s : labelStrs) {
1362-
labels.push_back(s.c_str());
1363-
}
1337+
BannerOverlayOptions bannerOptions;
13641338

1365-
// Title with node name or node number
13661339
std::string title = "";
13671340
if (node->has_user && node->user.long_name && node->user.long_name[0]) {
1368-
13691341
title += sanitizeString(node->user.long_name).substr(0, 15);
13701342
} else {
13711343
char buf[20];
13721344
snprintf(buf, sizeof(buf), "%08X", (unsigned int)node->num);
13731345
title += buf;
13741346
}
1375-
1376-
BannerOverlayOptions bannerOptions;
13771347
bannerOptions.message = title.c_str();
1378-
bannerOptions.optionsArrayPtr = labels.data();
1379-
bannerOptions.optionsEnumPtr = ids.data();
1380-
bannerOptions.optionsCount = (int)labels.size();
1381-
1348+
bannerOptions.optionsArrayPtr = optionsArray;
1349+
bannerOptions.optionsCount = options;
1350+
bannerOptions.optionsEnumPtr = optionsEnumArray;
13821351
bannerOptions.bannerCallback = [](int selected) -> void {
1383-
if (selected == MN_Back) {
1352+
if (selected == Back) {
13841353
menuQueue = node_base_menu;
13851354
screen->runNow();
13861355
return;
13871356
}
13881357

1389-
if (selected == MN_Favorite) {
1358+
if (selected == Favorite) {
13901359
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
13911360
if (!n) {
13921361
return;
13931362
}
1394-
13951363
if (n->is_favorite) {
13961364
LOG_INFO("Removing node %08X from favorites", menuHandler::pickedNodeNum);
13971365
nodeDB->set_favorite(false, menuHandler::pickedNodeNum);
@@ -1403,7 +1371,7 @@ void menuHandler::ManageNodeMenu()
14031371
return;
14041372
}
14051373

1406-
if (selected == MN_Mute) {
1374+
if (selected == Mute) {
14071375
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
14081376
if (!n) {
14091377
return;
@@ -1421,23 +1389,23 @@ void menuHandler::ManageNodeMenu()
14211389
return;
14221390
}
14231391

1424-
if (selected == MN_TraceRoute) {
1392+
if (selected == TraceRoute) {
14251393
LOG_INFO("Starting traceroute to %08X", menuHandler::pickedNodeNum);
14261394
if (traceRouteModule) {
14271395
traceRouteModule->startTraceRoute(menuHandler::pickedNodeNum);
14281396
}
14291397
return;
14301398
}
14311399

1432-
if (selected == MN_KeyVerification) {
1400+
if (selected == KeyVerification) {
14331401
LOG_INFO("Initiating key verification with %08X", menuHandler::pickedNodeNum);
14341402
if (keyVerificationModule) {
14351403
keyVerificationModule->sendInitialRequest(menuHandler::pickedNodeNum);
14361404
}
14371405
return;
14381406
}
14391407

1440-
if (selected == MN_Ignore) {
1408+
if (selected == Ignore) {
14411409
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
14421410
if (!n) {
14431411
return;
@@ -1455,7 +1423,6 @@ void menuHandler::ManageNodeMenu()
14551423
return;
14561424
}
14571425
};
1458-
14591426
screen->showOverlayBanner(bannerOptions);
14601427
}
14611428

src/graphics/draw/MenuHandler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class menuHandler
3535
shutdown_menu,
3636
NodePicker_menu,
3737
Manage_Node_menu,
38-
add_favorite,
3938
remove_favorite,
4039
test_menu,
4140
number_test,

0 commit comments

Comments
 (0)