From 50d0d5577b35460a792f06c79e8117095e6eaacf Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Tue, 6 Oct 2026 14:09:22 +0200 Subject: [PATCH] fix(ui-new): a tool opened from Home's Tools page goes back to Home Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/ui-new/AutoAdvertScreen.h | 2 +- examples/companion_radio/ui-new/BotScreen.h | 2 +- examples/companion_radio/ui-new/CompassScreen.h | 2 +- examples/companion_radio/ui-new/GpioScreen.h | 2 +- examples/companion_radio/ui-new/LiveShareScreen.h | 2 +- examples/companion_radio/ui-new/LocatorScreen.h | 2 +- examples/companion_radio/ui-new/NearbyScreen.h | 4 ++-- examples/companion_radio/ui-new/RepeaterScreen.h | 2 +- examples/companion_radio/ui-new/RingtoneEditorScreen.h | 6 +++--- examples/companion_radio/ui-new/ToolsScreen.h | 6 ++++-- examples/companion_radio/ui-new/TrailScreen.h | 2 +- examples/companion_radio/ui-new/UITask.cpp | 5 +++-- examples/companion_radio/ui-new/UITask.h | 4 ++++ 13 files changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/companion_radio/ui-new/AutoAdvertScreen.h b/examples/companion_radio/ui-new/AutoAdvertScreen.h index 2405b109..d7744a99 100644 --- a/examples/companion_radio/ui-new/AutoAdvertScreen.h +++ b/examples/companion_radio/ui-new/AutoAdvertScreen.h @@ -44,7 +44,7 @@ public: bool handleInput(char c) override { if (c == KEY_CANCEL) { _task->savePrefsIfDirty(_dirty); - _task->gotoToolsScreen(); + _task->leaveTool(); return true; } bool right = keyIsNext(c) || c == KEY_ENTER; diff --git a/examples/companion_radio/ui-new/BotScreen.h b/examples/companion_radio/ui-new/BotScreen.h index d720488e..ce013fae 100644 --- a/examples/companion_radio/ui-new/BotScreen.h +++ b/examples/companion_radio/ui-new/BotScreen.h @@ -174,7 +174,7 @@ public: if (cancel) { _task->savePrefsIfDirty(_dirty); - _task->gotoToolsScreen(); + _task->leaveTool(); return true; } if (keyIsPrev(c)) { _tab = (_tab + botcfg::TAB_COUNT - 1) % botcfg::TAB_COUNT; _sel = _scroll = 0; return true; } diff --git a/examples/companion_radio/ui-new/CompassScreen.h b/examples/companion_radio/ui-new/CompassScreen.h index 8477622a..377f260b 100644 --- a/examples/companion_radio/ui-new/CompassScreen.h +++ b/examples/companion_radio/ui-new/CompassScreen.h @@ -120,7 +120,7 @@ public: } bool handleInput(char c) override { - if (c == KEY_CANCEL) { _task->gotoToolsScreen(); return true; } + if (c == KEY_CANCEL) { _task->leaveTool(); return true; } return true; } }; diff --git a/examples/companion_radio/ui-new/GpioScreen.h b/examples/companion_radio/ui-new/GpioScreen.h index dc64609a..9a0f5b3f 100644 --- a/examples/companion_radio/ui-new/GpioScreen.h +++ b/examples/companion_radio/ui-new/GpioScreen.h @@ -134,7 +134,7 @@ public: } bool handleInput(char c) override { - if (c == KEY_CANCEL) { _task->gotoToolsScreen(); return true; } + if (c == KEY_CANCEL) { _task->leaveTool(); return true; } if (c == KEY_UP) { _sel = (_sel > 0) ? _sel - 1 : _item_count - 1; return true; } if (c == KEY_DOWN) { _sel = (_sel < _item_count - 1) ? _sel + 1 : 0; return true; } if (!_prefs) return false; diff --git a/examples/companion_radio/ui-new/LiveShareScreen.h b/examples/companion_radio/ui-new/LiveShareScreen.h index 33152424..5cb78900 100644 --- a/examples/companion_radio/ui-new/LiveShareScreen.h +++ b/examples/companion_radio/ui-new/LiveShareScreen.h @@ -191,7 +191,7 @@ public: bool handleInput(char c) override { if (c == KEY_CANCEL) { _task->savePrefsIfDirty(_dirty); - _task->gotoToolsScreen(); + _task->leaveTool(); return true; } if (c == KEY_UP) { moveSel(-1); return true; } diff --git a/examples/companion_radio/ui-new/LocatorScreen.h b/examples/companion_radio/ui-new/LocatorScreen.h index 4fb703dc..4d9dfa3f 100644 --- a/examples/companion_radio/ui-new/LocatorScreen.h +++ b/examples/companion_radio/ui-new/LocatorScreen.h @@ -298,7 +298,7 @@ public: } if (c == KEY_CANCEL) { _task->savePrefsIfDirty(_dirty); // engine re-seeded per edit - _task->gotoToolsScreen(); + _task->leaveTool(); return true; } if (c == KEY_UP) { moveSel(-1); return true; } diff --git a/examples/companion_radio/ui-new/NearbyScreen.h b/examples/companion_radio/ui-new/NearbyScreen.h index daf8616c..a0a55b76 100644 --- a/examples/companion_radio/ui-new/NearbyScreen.h +++ b/examples/companion_radio/ui-new/NearbyScreen.h @@ -825,9 +825,9 @@ public: // ── list view ─────────────────────────────────────────────────────────── if (c == KEY_CANCEL) { - if (_pick_admin_target) { _pick_admin_target = false; _task->gotoToolsScreen(); return true; } + if (_pick_admin_target) { _pick_admin_target = false; _task->leaveTool(); return true; } if (_source == SRC_SCAN) leaveScan(); - else _task->gotoToolsScreen(); + else _task->leaveTool(); return true; } if (c == KEY_CONTEXT_MENU) { openActionMenu(); return true; } diff --git a/examples/companion_radio/ui-new/RepeaterScreen.h b/examples/companion_radio/ui-new/RepeaterScreen.h index d7b031e0..ec93d0de 100644 --- a/examples/companion_radio/ui-new/RepeaterScreen.h +++ b/examples/companion_radio/ui-new/RepeaterScreen.h @@ -240,7 +240,7 @@ public: if (c == KEY_CANCEL) { _task->savePrefsIfDirty(_dirty); - _task->gotoToolsScreen(); + _task->leaveTool(); return true; } if (c == KEY_UP) { _sel = (_sel > 0) ? _sel - 1 : _item_count - 1; return true; } diff --git a/examples/companion_radio/ui-new/RingtoneEditorScreen.h b/examples/companion_radio/ui-new/RingtoneEditorScreen.h index 471204b9..ec87d10c 100644 --- a/examples/companion_radio/ui-new/RingtoneEditorScreen.h +++ b/examples/companion_radio/ui-new/RingtoneEditorScreen.h @@ -253,11 +253,11 @@ public: the_mesh.savePrefs(); } _task->stopMelody(); - _task->gotoToolsScreen(); + _task->leaveTool(); break; case MI_DISCARD: _task->stopMelody(); - _task->gotoToolsScreen(); + _task->leaveTool(); break; default: break; } @@ -265,7 +265,7 @@ public: return true; } - if (cancel) { _task->stopMelody(); _task->gotoToolsScreen(); return true; } + if (cancel) { _task->stopMelody(); _task->leaveTool(); return true; } if (menu_key) { openMenu(); return true; } if (left && _cursor > 0) { _cursor--; clampScroll(); return true; } diff --git a/examples/companion_radio/ui-new/ToolsScreen.h b/examples/companion_radio/ui-new/ToolsScreen.h index ac4d3493..d5577611 100644 --- a/examples/companion_radio/ui-new/ToolsScreen.h +++ b/examples/companion_radio/ui-new/ToolsScreen.h @@ -34,8 +34,10 @@ public: return ""; } - // Opens a tool and moves it to the front of the recent list. - static void run(UITask* task, Action a) { + // Opens a tool and moves it to the front of the recent list. from_home: the + // tool's Back returns to Home instead of this list. + static void run(UITask* task, Action a, bool from_home = false) { + task->setToolFromHome(from_home); if (s_recent[0] != a) { s_recent[1] = s_recent[0]; s_recent[0] = a; } switch (a) { case ACT_NEARBY: task->gotoNearbyScreen(); break; diff --git a/examples/companion_radio/ui-new/TrailScreen.h b/examples/companion_radio/ui-new/TrailScreen.h index fc1b4e5e..50040c7e 100644 --- a/examples/companion_radio/ui-new/TrailScreen.h +++ b/examples/companion_radio/ui-new/TrailScreen.h @@ -228,7 +228,7 @@ public: if (c == KEY_CANCEL) { _task->savePrefsIfDirty(_cfg_dirty); if (_return_home) _task->gotoHomeScreen(); - else _task->gotoToolsScreen(); + else _task->leaveTool(); return true; } if (c == KEY_CONTEXT_MENU) { openActionMenu(); return true; } diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 3b2c5fcf..25c8e7c6 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -605,7 +605,7 @@ class HomeScreen : public UIScreen { if (the_mesh.advert()) _advert_sent_ms = millis(); // the row says so else _task->showAlert("Advert failed", 1000); break; - case QA_TOOL: ToolsScreen::run(_task, (ToolsScreen::Action)r.n); break; + case QA_TOOL: ToolsScreen::run(_task, (ToolsScreen::Action)r.n, true); break; case QA_LOCK: _task->lockScreen(); break; case QA_HIBERNATE: _shutdown_init = true; break; // waits for the button to be released case QA_GPS: _task->toggleGPS(false); break; @@ -2022,7 +2022,8 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no // onShow() is invoked by setCurrScreen(), so most navigators are just that. void UITask::gotoSettingsScreen() { setCurrScreen(settings); } -void UITask::gotoToolsScreen() { setCurrScreen(tools_screen); } +void UITask::gotoToolsScreen() { _tool_from_home = false; setCurrScreen(tools_screen); } +void UITask::leaveTool() { if (_tool_from_home) gotoHomeScreen(); else gotoToolsScreen(); } void UITask::gotoBotScreen() { setCurrScreen(bot_screen); } void UITask::gotoNearbyScreen() { setCurrScreen(nearby_screen); } diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index 935ea4da..cf14ffda 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -62,6 +62,7 @@ class UITask : public UITaskBase, public UiCoreHost { unsigned long _next_refresh, _auto_off; NodePrefs* _node_prefs; bool _locked; + bool _tool_from_home = false; unsigned long _lock_wake_until; // when to blank screen again after locked wake (5s) int _lock_seq_count; // Enter presses while Back held (lock/unlock sequence) unsigned long _lock_seq_ms; // millis() of last lock-sequence press (for timeout) @@ -282,6 +283,9 @@ public: void pickBotChannelTarget(); // open Messages to choose the auto-reply bot's channel void pickBotRoomTarget(); // open Messages to choose the auto-reply bot's room void gotoToolsScreen(); + // A tool's Back: to Home when Home's Tools page opened it, else to the Tools list. + void leaveTool(); + void setToolFromHome(bool home) { _tool_from_home = home; } void gotoRingtoneEditor(int slot = 0); void gotoBotScreen(); void pickAdminTarget(); // Admin is remote-only: open Nodes to pick a repeater/room