Fix Back being trapped on the connecting popup (all three connect flows)
BT Inspector, BLE HID Host and Sensor Dashboard showed a "Connecting..." / "Discovering..." popup whose Back handler ignored the key, so if a connect or service discovery ran long the user was stuck until it timed out. Back on that popup now sets a cancel flag and returns to the scan list immediately; the worker thread notices the flag when its current operation finishes, drops the half-made connection and resumes scanning, and the completion handler ignores the cancelled result instead of jumping into the device/readings view. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LEaD4ZeAfvWLBUxXp8G11r
This commit is contained in:
@@ -84,6 +84,7 @@ typedef struct {
|
||||
Sub subs[SUBS_MAX];
|
||||
int sub_count;
|
||||
bool connected_ok;
|
||||
volatile bool cancel;
|
||||
char setup_msg[48];
|
||||
} App;
|
||||
|
||||
@@ -95,6 +96,8 @@ typedef struct {
|
||||
|
||||
// ---- logging ----------------------------------------------------------------
|
||||
|
||||
static App* s_app; // popup Back callback (popup view ctx isn't the App)
|
||||
|
||||
static void app_log(App* app, const char* fmt, ...) {
|
||||
if(!app->log) return;
|
||||
DateTime dt;
|
||||
@@ -240,7 +243,13 @@ static int32_t worker_thread(void* ctx) {
|
||||
while(furi_message_queue_get(app->jobs, &job, FuriWaitForever) == FuriStatusOk) {
|
||||
if(job == JobQuit) break;
|
||||
if(job == JobConnect) {
|
||||
app->connected_ok = bc_connect(app->bc, &app->dev, 8000) && hid_setup(app);
|
||||
bool ok = bc_connect(app->bc, &app->dev, 8000) && hid_setup(app);
|
||||
if(app->cancel) {
|
||||
if(bc_is_connected(app->bc)) bc_disconnect(app->bc);
|
||||
bc_scan_start(app->bc);
|
||||
ok = false;
|
||||
}
|
||||
app->connected_ok = ok;
|
||||
} else if(job == JobDisconnect) {
|
||||
bc_disconnect(app->bc);
|
||||
bc_scan_start(app->bc);
|
||||
@@ -442,9 +451,11 @@ static uint32_t nav_mon_back(void* ctx) {
|
||||
return ViewScan;
|
||||
}
|
||||
|
||||
static uint32_t nav_stay_popup(void* ctx) {
|
||||
static uint32_t nav_connecting_back(void* ctx) {
|
||||
UNUSED(ctx);
|
||||
return ViewPopup;
|
||||
s_app->cancel = true;
|
||||
s_app->cur_view = ViewScan;
|
||||
return ViewScan;
|
||||
}
|
||||
|
||||
// ---- events -----------------------------------------------------------------
|
||||
@@ -508,12 +519,17 @@ static bool custom_event_cb(void* ctx, uint32_t event) {
|
||||
false);
|
||||
if(have) {
|
||||
app_log(app, "CONNECTING %s", dev_label(&app->dev));
|
||||
app->cancel = false;
|
||||
show_popup(app, "Connecting...", dev_label(&app->dev), false);
|
||||
furi_message_queue_put(app->jobs, &(JobType){JobConnect}, 0);
|
||||
}
|
||||
} break;
|
||||
case EvtNotify: on_notify(app); break;
|
||||
case EvtJobDone:
|
||||
if(app->cancel) {
|
||||
app->cancel = false;
|
||||
break;
|
||||
}
|
||||
if(app->connected_ok) {
|
||||
char hdr[40];
|
||||
snprintf(hdr, sizeof(hdr), "%s", dev_label(&app->dev));
|
||||
@@ -554,6 +570,7 @@ int32_t ble_hid_host_app(void* p) {
|
||||
UNUSED(p);
|
||||
App* app = malloc(sizeof(App));
|
||||
memset(app, 0, sizeof(App));
|
||||
s_app = app;
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->storage = furi_record_open(RECORD_STORAGE);
|
||||
app->jobs = furi_message_queue_alloc(8, sizeof(JobType));
|
||||
@@ -582,7 +599,7 @@ int32_t ble_hid_host_app(void* p) {
|
||||
view_dispatcher_add_view(app->vd, ViewMonitor, app->mon_view);
|
||||
|
||||
app->popup = popup_alloc();
|
||||
view_set_previous_callback(popup_get_view(app->popup), nav_stay_popup);
|
||||
view_set_previous_callback(popup_get_view(app->popup), nav_connecting_back);
|
||||
view_dispatcher_add_view(app->vd, ViewPopup, popup_get_view(app->popup));
|
||||
|
||||
app->timer = furi_timer_alloc(timer_cb, FuriTimerTypePeriodic, app);
|
||||
|
||||
Reference in New Issue
Block a user