Skip to content

Commit

Permalink
[FL-2717] Fix unexpected behaviour when opening a remote from outside…
Browse files Browse the repository at this point in the history
… (#1538)

* Fix unexpected behaviour when opening remote from outside
* Same fix for editing button name
* Exit application correctly if remote was deleted
* Remove duplicate function from ibutton
* Use COUNT_OF macro

Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
gsurkov and skotopes authored Aug 5, 2022
1 parent 55b4ff8 commit d147190
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 32 deletions.
16 changes: 0 additions & 16 deletions applications/ibutton/ibutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,6 @@ void ibutton_text_store_clear(iButton* ibutton) {
memset(ibutton->text_store, 0, IBUTTON_TEXT_STORE_SIZE);
}

void ibutton_switch_to_previous_scene_one_of(
iButton* ibutton,
const uint32_t* scene_ids,
size_t scene_ids_size) {
furi_assert(scene_ids_size);
SceneManager* scene_manager = ibutton->scene_manager;

for(size_t i = 0; i < scene_ids_size; ++i) {
const uint32_t scene_id = scene_ids[i];
if(scene_manager_has_previous_scene(scene_manager, scene_id)) {
scene_manager_search_and_switch_to_previous_scene(scene_manager, scene_id);
return;
}
}
}

void ibutton_notification_message(iButton* ibutton, uint32_t message) {
furi_assert(message < sizeof(ibutton_notification_sequences) / sizeof(NotificationSequence*));
notification_message(ibutton->notifications, ibutton_notification_sequences[message]);
Expand Down
4 changes: 0 additions & 4 deletions applications/ibutton/ibutton_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,4 @@ bool ibutton_save_key(iButton* ibutton, const char* key_name);
bool ibutton_delete_key(iButton* ibutton);
void ibutton_text_store_set(iButton* ibutton, const char* text, ...);
void ibutton_text_store_clear(iButton* ibutton);
void ibutton_switch_to_previous_scene_one_of(
iButton* ibutton,
const uint32_t* scene_ids,
size_t scene_ids_size);
void ibutton_notification_message(iButton* ibutton, uint32_t message);
4 changes: 2 additions & 2 deletions applications/ibutton/scenes/ibutton_scene_save_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
} else {
const uint32_t possible_scenes[] = {
iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType};
ibutton_switch_to_previous_scene_one_of(
ibutton, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
scene_manager_search_and_switch_to_previous_scene_one_of(
ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions applications/ibutton/scenes/ibutton_scene_save_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ bool ibutton_scene_save_success_on_event(void* context, SceneManagerEvent event)
if(event.event == iButtonCustomEventBack) {
const uint32_t possible_scenes[] = {
iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType};
ibutton_switch_to_previous_scene_one_of(
ibutton, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
scene_manager_search_and_switch_to_previous_scene_one_of(
ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes));
}
}

Expand Down
4 changes: 2 additions & 2 deletions applications/ibutton/scenes/ibutton_scene_write_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ bool ibutton_scene_write_success_on_event(void* context, SceneManagerEvent event
consumed = true;
if(event.event == iButtonCustomEventBack) {
const uint32_t possible_scenes[] = {iButtonSceneReadKeyMenu, iButtonSceneStart};
ibutton_switch_to_previous_scene_one_of(
ibutton, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
scene_manager_search_and_switch_to_previous_scene_one_of(
ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes));
}
}

Expand Down
2 changes: 1 addition & 1 deletion applications/infrared/scenes/infrared_scene_edit_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool infrared_scene_edit_delete_on_event(void* context, SceneManagerEvent event)
} else {
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart};
scene_manager_search_and_switch_to_previous_scene_one_of(
scene_manager, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
scene_manager, possible_scenes, COUNT_OF(possible_scenes));
}
consumed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ bool infrared_scene_edit_delete_done_on_event(void* context, SceneManagerEvent e
scene_manager, InfraredSceneRemote);
} else if(edit_target == InfraredEditTargetRemote) {
const uint32_t possible_scenes[] = {InfraredSceneStart, InfraredSceneRemoteList};
scene_manager_search_and_switch_to_previous_scene_one_of(
scene_manager, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
if(!scene_manager_search_and_switch_to_previous_scene_one_of(
scene_manager, possible_scenes, COUNT_OF(possible_scenes))) {
view_dispatcher_stop(infrared->view_dispatcher);
}
} else {
furi_assert(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ bool infrared_scene_edit_rename_done_on_event(void* context, SceneManagerEvent e

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InfraredCustomEventTypePopupClosed) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
if(!scene_manager_search_and_switch_to_previous_scene(
infrared->scene_manager, InfraredSceneRemote)) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
}
consumed = true;
}
}
Expand Down
5 changes: 4 additions & 1 deletion applications/infrared/scenes/infrared_scene_learn_done.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ bool infrared_scene_learn_done_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InfraredCustomEventTypePopupClosed) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
if(!scene_manager_search_and_switch_to_previous_scene(
infrared->scene_manager, InfraredSceneRemote)) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
}
consumed = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion applications/infrared/scenes/infrared_scene_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool infrared_scene_remote_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeBack) {
const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart};
consumed = scene_manager_search_and_switch_to_previous_scene_one_of(
scene_manager, possible_scenes, sizeof(possible_scenes) / sizeof(uint32_t));
scene_manager, possible_scenes, COUNT_OF(possible_scenes));
} else if(event.type == SceneManagerEventTypeCustom) {
const uint16_t custom_type = infrared_custom_event_get_type(event.event);
const int16_t button_index = infrared_custom_event_get_value(event.event);
Expand Down

0 comments on commit d147190

Please sign in to comment.