mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-02 10:16: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:
co-authored by
Claude Sonnet 4.6
parent
9e5c0e79e7
commit
85de0b02be
@@ -13,6 +13,7 @@ class BotScreen : public UIScreen {
|
|||||||
static const int VAL_X = 70;
|
static const int VAL_X = 70;
|
||||||
|
|
||||||
int _sel;
|
int _sel;
|
||||||
|
bool _dirty;
|
||||||
|
|
||||||
// keyboard state (reused for trigger and reply fields)
|
// keyboard state (reused for trigger and reply fields)
|
||||||
int _kb_field; // -1=off, 2=trigger, 3=reply DM, 4=reply Ch
|
int _kb_field; // -1=off, 2=trigger, 3=reply DM, 4=reply Ch
|
||||||
@@ -45,6 +46,7 @@ public:
|
|||||||
void enter() {
|
void enter() {
|
||||||
_sel = 0;
|
_sel = 0;
|
||||||
_kb_field = -1;
|
_kb_field = -1;
|
||||||
|
_dirty = false;
|
||||||
refreshChannels();
|
refreshChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +121,7 @@ public:
|
|||||||
strncpy(_prefs->bot_reply_ch, _kb.buf, sizeof(_prefs->bot_reply_ch) - 1);
|
strncpy(_prefs->bot_reply_ch, _kb.buf, sizeof(_prefs->bot_reply_ch) - 1);
|
||||||
_prefs->bot_reply_ch[sizeof(_prefs->bot_reply_ch) - 1] = '\0';
|
_prefs->bot_reply_ch[sizeof(_prefs->bot_reply_ch) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
_dirty = true;
|
||||||
_kb_field = -1;
|
_kb_field = -1;
|
||||||
} else if (res == KeyboardWidget::CANCELLED) {
|
} else if (res == KeyboardWidget::CANCELLED) {
|
||||||
_kb_field = -1;
|
_kb_field = -1;
|
||||||
@@ -127,7 +130,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
the_mesh.savePrefs();
|
if (_dirty) the_mesh.savePrefs();
|
||||||
_task->gotoToolsScreen();
|
_task->gotoToolsScreen();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -136,6 +139,7 @@ public:
|
|||||||
|
|
||||||
if (_sel == 0 && (enter || left || right)) {
|
if (_sel == 0 && (enter || left || right)) {
|
||||||
_prefs->bot_enabled ^= 1;
|
_prefs->bot_enabled ^= 1;
|
||||||
|
_dirty = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (_sel == 1) {
|
if (_sel == 1) {
|
||||||
@@ -157,6 +161,7 @@ public:
|
|||||||
_prefs->bot_channel_enabled = 1;
|
_prefs->bot_channel_enabled = 1;
|
||||||
_prefs->bot_channel_idx = _channel_indices[idx];
|
_prefs->bot_channel_idx = _channel_indices[idx];
|
||||||
}
|
}
|
||||||
|
_dirty = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,17 +26,19 @@ class DashboardConfigScreen : public UIScreen {
|
|||||||
|
|
||||||
static const char* OPTION_NAMES[DASH_COUNT];
|
static const char* OPTION_NAMES[DASH_COUNT];
|
||||||
|
|
||||||
int _sel;
|
int _sel;
|
||||||
|
bool _dirty;
|
||||||
|
|
||||||
void cycle(int slot, int dir) {
|
void cycle(int slot, int dir) {
|
||||||
uint8_t& f = _prefs->dashboard_fields[slot];
|
uint8_t& f = _prefs->dashboard_fields[slot];
|
||||||
f = (uint8_t)((f + DASH_COUNT + dir) % DASH_COUNT);
|
f = (uint8_t)((f + DASH_COUNT + dir) % DASH_COUNT);
|
||||||
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DashboardConfigScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
|
DashboardConfigScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
|
||||||
|
|
||||||
void enter() { _sel = 0; }
|
void enter() { _sel = 0; _dirty = false; }
|
||||||
|
|
||||||
int render(DisplayDriver& display) override {
|
int render(DisplayDriver& display) override {
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
@@ -67,7 +69,7 @@ public:
|
|||||||
|
|
||||||
bool handleInput(char c) override {
|
bool handleInput(char c) override {
|
||||||
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
|
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
|
||||||
the_mesh.savePrefs();
|
if (_dirty) the_mesh.savePrefs();
|
||||||
_task->gotoHomeScreen();
|
_task->gotoHomeScreen();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user