[FL-960] View dispatcher: lock gui when the view tree changes (#369)

* View dispatcher: lock gui when the view tree changes

* View dispatcher: include gui interface

* View dispatcher: lock gui also when view added (view_dispatcher_add_view fn)
This commit is contained in:
SG 2021-03-05 23:13:00 +10:00 committed by GitHub
parent 7afdd14a4c
commit 651c5b35ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
#include "view_dispatcher_i.h" #include "view_dispatcher_i.h"
#include "gui_i.h"
ViewDispatcher* view_dispatcher_alloc() { ViewDispatcher* view_dispatcher_alloc() {
ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher)); ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher));
@ -38,19 +39,40 @@ void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id,
furi_assert(view); furi_assert(view);
// Check if view id is not used and resgister view // Check if view id is not used and resgister view
furi_check(ViewDict_get(view_dispatcher->views, view_id) == NULL); furi_check(ViewDict_get(view_dispatcher->views, view_id) == NULL);
// Lock gui
if(view_dispatcher->gui) {
gui_lock(view_dispatcher->gui);
}
ViewDict_set_at(view_dispatcher->views, view_id, view); ViewDict_set_at(view_dispatcher->views, view_id, view);
view_set_dispatcher(view, view_dispatcher); view_set_dispatcher(view, view_dispatcher);
// Unlock gui
if(view_dispatcher->gui) {
gui_unlock(view_dispatcher->gui);
}
} }
void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_id) { void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_id) {
furi_assert(view_dispatcher); furi_assert(view_dispatcher);
// Lock gui
if(view_dispatcher->gui) {
gui_lock(view_dispatcher->gui);
}
// Disable the view if it is active // Disable the view if it is active
if(view_dispatcher->current_view == *ViewDict_get(view_dispatcher->views, view_id)) { if(view_dispatcher->current_view == *ViewDict_get(view_dispatcher->views, view_id)) {
view_dispatcher_set_current_view(view_dispatcher, NULL); view_dispatcher_set_current_view(view_dispatcher, NULL);
} }
// Remove view // Remove view
ViewDict_erase(view_dispatcher->views, view_id); ViewDict_erase(view_dispatcher->views, view_id);
// Unlock gui
if(view_dispatcher->gui) {
gui_unlock(view_dispatcher->gui);
}
} }
void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t view_id) { void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t view_id) {