chore(color): use standard window lifecycle logic for the audio recorder (#7714)

This commit is contained in:
philmoz
2026-08-27 09:18:01 +10:00
committed by GitHub
parent 3562502265
commit 2b9b8fd479
3 changed files with 10 additions and 37 deletions
+1 -1
View File
@@ -211,8 +211,8 @@ LabelDialog::LabelDialog(const char *label, int length, const char* title,
}); });
new TextButton(box, rect_t{0, 0, 96, 0}, STR_SAVE, [=]() { new TextButton(box, rect_t{0, 0, 96, 0}, STR_SAVE, [=]() {
if (saveHandler != nullptr) saveHandler(this->label);
deleteLater(); deleteLater();
if (saveHandler != nullptr) saveHandler(this->label);
return 0; return 0;
}); });
} }
@@ -396,21 +396,15 @@ RadioMicRecorder::RadioMicRecorder() :
enterIdle(); enterIdle();
} }
RadioMicRecorder::~RadioMicRecorder() void RadioMicRecorder::deleteLater()
{ {
// An async call scheduled from the LabelDialog confirm path may still be if (!deleted()) {
// pending when the page is closed (e.g. user long-presses EXIT while the if (recorder.isRecording()) recorder.stop();
// dialog is being dismissed). Cancelling ensures the callback never fires if (isPlayingTake()) audioQueue.stopAll();
// on a destroyed instance. pdmStop();
lv_async_call_cancel(&RadioMicRecorder::asyncProcessPendingRename, this);
if (recorder.isRecording()) recorder.stop();
if (isPlayingTake()) audioQueue.stopAll();
pdmStop();
}
void RadioMicRecorder::asyncProcessPendingRename(void* ctx) Page::deleteLater();
{ }
static_cast<RadioMicRecorder*>(ctx)->processPendingRename();
} }
void RadioMicRecorder::buildHeader(Window* window) void RadioMicRecorder::buildHeader(Window* window)
@@ -643,16 +637,6 @@ void RadioMicRecorder::discardTake()
if (!takeSaved && filename[0]) f_unlink(filename); if (!takeSaved && filename[0]) f_unlink(filename);
} }
void RadioMicRecorder::onEvent(event_t event)
{
if (event == EVT_KEY_LONG(KEY_EXIT)) {
killEvents(event);
if (recorder.isRecording()) recorder.stop();
if (isPlayingTake()) audioQueue.stopAll();
onCancel();
}
}
void RadioMicRecorder::onActionPressed() void RadioMicRecorder::onActionPressed()
{ {
switch (state) { switch (state) {
@@ -758,13 +742,7 @@ void RadioMicRecorder::askSaveAs()
strncpy(dir + SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); strncpy(dir + SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
snprintf(pendingRename, sizeof(pendingRename), "%s%s.wav", dir, newName.c_str()); snprintf(pendingRename, sizeof(pendingRename), "%s%s.wav", dir, newName.c_str());
if (strcmp(pendingRename, filename) == 0) { takeSaved = true; refreshUI(); return; } if (strcmp(pendingRename, filename) == 0) { takeSaved = true; refreshUI(); return; }
processPendingRename();
// Defer the overwrite check until LabelDialog has finished closing —
// creating a modal now would leave us stacked on top of LabelDialog,
// which corrupts the lv_group chain when LabelDialog deletes itself.
// The page dtor cancels this async call if the user bails out before
// it fires (see ~RadioMicRecorder).
lv_async_call(&RadioMicRecorder::asyncProcessPendingRename, this);
}); });
} }
@@ -35,7 +35,6 @@ class RadioMicRecorder : public Page
{ {
public: public:
RadioMicRecorder(); RadioMicRecorder();
~RadioMicRecorder() override;
protected: protected:
enum class State : uint8_t { IDLE, COUNTDOWN, RECORDING, REVIEW }; enum class State : uint8_t { IDLE, COUNTDOWN, RECORDING, REVIEW };
@@ -76,7 +75,7 @@ class RadioMicRecorder : public Page
void buildHeader(Window* window); void buildHeader(Window* window);
void buildBody(Window* window); void buildBody(Window* window);
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override; void deleteLater() override;
void onActionPressed(); void onActionPressed();
void onPlayPressed(); void onPlayPressed();
@@ -100,10 +99,6 @@ class RadioMicRecorder : public Page
void applyRename(); void applyRename();
void refreshUI(); void refreshUI();
void pickNextFilename(); void pickNextFilename();
// Stable callback address so the dtor can cancel a pending lv_async call
// scheduled from the LabelDialog confirm path.
static void asyncProcessPendingRename(void* ctx);
}; };
#endif // PDM_CLOCK #endif // PDM_CLOCK