Skip to content

Commit 6e71362

Browse files
committed
Merge branch 'main' of github.com:vicliu624/trail-mate
2 parents 3b7355f + 8c6fa6e commit 6e71362

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/app/app_config.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,25 @@ struct AppConfig
252252
meshcore_config.meshcore_channel_name[sizeof(meshcore_config.meshcore_channel_name) - 1] = '\0';
253253
prefs.getBytes("mc_ch_key", meshcore_config.secondary_key, sizeof(meshcore_config.secondary_key));
254254

255-
mesh_protocol = static_cast<chat::MeshProtocol>(
256-
prefs.getUChar("mesh_protocol", static_cast<uint8_t>(chat::MeshProtocol::Meshtastic)));
255+
uint8_t mesh_protocol_raw = prefs.getUChar("mesh_protocol", 0xFF);
256+
if (mesh_protocol_raw == static_cast<uint8_t>(chat::MeshProtocol::Meshtastic) ||
257+
mesh_protocol_raw == static_cast<uint8_t>(chat::MeshProtocol::MeshCore))
258+
{
259+
mesh_protocol = static_cast<chat::MeshProtocol>(mesh_protocol_raw);
260+
}
261+
else
262+
{
263+
int legacy_protocol = prefs.getInt("mesh_protocol",
264+
static_cast<int>(chat::MeshProtocol::Meshtastic));
265+
if (legacy_protocol == static_cast<int>(chat::MeshProtocol::MeshCore))
266+
{
267+
mesh_protocol = chat::MeshProtocol::MeshCore;
268+
}
269+
else
270+
{
271+
mesh_protocol = chat::MeshProtocol::Meshtastic;
272+
}
273+
}
257274

258275
// Load device name
259276
size_t len = prefs.getBytes("node_name", node_name, sizeof(node_name) - 1);
@@ -402,6 +419,8 @@ struct AppConfig
402419
prefs.putBool("mc_tx_en", meshcore_config.tx_enabled);
403420
prefs.putString("mc_ch_name", meshcore_config.meshcore_channel_name);
404421
prefs.putBytes("mc_ch_key", meshcore_config.secondary_key, sizeof(meshcore_config.secondary_key));
422+
// Remove first so legacy key type mismatches cannot block updating this value.
423+
prefs.remove("mesh_protocol");
405424
prefs.putUChar("mesh_protocol", static_cast<uint8_t>(mesh_protocol));
406425

407426
// Save device name

src/ui/screens/settings/settings_page_components.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,20 @@ static void on_option_clicked(lv_event_t* e)
892892
if (payload->item->pref_key && strcmp(payload->item->pref_key, "mesh_protocol") == 0)
893893
{
894894
app::AppContext& app_ctx = app::AppContext::getInstance();
895-
app_ctx.getConfig().mesh_protocol = static_cast<chat::MeshProtocol>(payload->value);
896-
app_ctx.saveConfig();
897-
restart_now = true;
895+
chat::MeshProtocol target = static_cast<chat::MeshProtocol>(payload->value);
896+
if (!app_ctx.switchMeshProtocol(target, true))
897+
{
898+
*payload->item->enum_value = previous_value;
899+
prefs_put_int(payload->item->pref_key, previous_value);
900+
update_item_value(*payload->widget);
901+
::ui::SystemNotification::show("Protocol switch failed", 3000);
902+
}
903+
else
904+
{
905+
rebuild_list = true;
906+
::ui::SystemNotification::show("Protocol switched", 2000);
907+
restart_now = true;
908+
}
898909
}
899910
if (payload->item->pref_key && strcmp(payload->item->pref_key, "chat_region") == 0)
900911
{

0 commit comments

Comments
 (0)