mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08:11 +00:00
fix: guard savePrefs with dirty flag in BotScreen and DashboardConfigScreen
BotScreen and DashboardConfigScreen were calling savePrefs() on every exit regardless of whether any setting changed. Add _dirty flag set only on actual value changes (toggle, channel select, keyboard confirm, field cycle), reset on enter(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ class BotScreen : public UIScreen {
|
||||
static const int VAL_X = 70;
|
||||
|
||||
int _sel;
|
||||
bool _dirty;
|
||||
|
||||
// keyboard state (reused for trigger and reply fields)
|
||||
int _kb_field; // -1=off, 2=trigger, 3=reply DM, 4=reply Ch
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
void enter() {
|
||||
_sel = 0;
|
||||
_kb_field = -1;
|
||||
_dirty = false;
|
||||
refreshChannels();
|
||||
}
|
||||
|
||||
@@ -119,6 +121,7 @@ public:
|
||||
strncpy(_prefs->bot_reply_ch, _kb.buf, sizeof(_prefs->bot_reply_ch) - 1);
|
||||
_prefs->bot_reply_ch[sizeof(_prefs->bot_reply_ch) - 1] = '\0';
|
||||
}
|
||||
_dirty = true;
|
||||
_kb_field = -1;
|
||||
} else if (res == KeyboardWidget::CANCELLED) {
|
||||
_kb_field = -1;
|
||||
@@ -127,7 +130,7 @@ public:
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
the_mesh.savePrefs();
|
||||
if (_dirty) the_mesh.savePrefs();
|
||||
_task->gotoToolsScreen();
|
||||
return true;
|
||||
}
|
||||
@@ -136,6 +139,7 @@ public:
|
||||
|
||||
if (_sel == 0 && (enter || left || right)) {
|
||||
_prefs->bot_enabled ^= 1;
|
||||
_dirty = true;
|
||||
return true;
|
||||
}
|
||||
if (_sel == 1) {
|
||||
@@ -157,6 +161,7 @@ public:
|
||||
_prefs->bot_channel_enabled = 1;
|
||||
_prefs->bot_channel_idx = _channel_indices[idx];
|
||||
}
|
||||
_dirty = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,17 +26,19 @@ class DashboardConfigScreen : public UIScreen {
|
||||
|
||||
static const char* OPTION_NAMES[DASH_COUNT];
|
||||
|
||||
int _sel;
|
||||
int _sel;
|
||||
bool _dirty;
|
||||
|
||||
void cycle(int slot, int dir) {
|
||||
uint8_t& f = _prefs->dashboard_fields[slot];
|
||||
f = (uint8_t)((f + DASH_COUNT + dir) % DASH_COUNT);
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public:
|
||||
DashboardConfigScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
|
||||
|
||||
void enter() { _sel = 0; }
|
||||
void enter() { _sel = 0; _dirty = false; }
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
display.setTextSize(1);
|
||||
@@ -67,7 +69,7 @@ public:
|
||||
|
||||
bool handleInput(char c) override {
|
||||
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
|
||||
the_mesh.savePrefs();
|
||||
if (_dirty) the_mesh.savePrefs();
|
||||
_task->gotoHomeScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user