app_state.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "flipper.h"
  2. #include "app_state.h"
  3. #include "scenes/scenes.h"
  4. #include "item.h"
  5. App* app_alloc() {
  6. App* app = malloc(sizeof(App));
  7. app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
  8. app->view_dispatcher = view_dispatcher_alloc();
  9. view_dispatcher_enable_queue(app->view_dispatcher);
  10. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  11. view_dispatcher_set_custom_event_callback(app->view_dispatcher, app_scene_custom_callback);
  12. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, app_back_event_callback);
  13. // Create our UI elements
  14. app->btn_menu = button_menu_alloc();
  15. view_dispatcher_add_view(
  16. app->view_dispatcher, SR_ButtonMenu, button_menu_get_view(app->btn_menu));
  17. // Storage
  18. app->storage = furi_record_open(RECORD_STORAGE);
  19. // Notifications - for LED light access
  20. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  21. // initialize device items list
  22. app->depth = 0;
  23. app->selected_item = -1;
  24. app->items_view = item_get_items_view_from_path(app, NULL);
  25. return app;
  26. }
  27. void app_free(App* app) {
  28. furi_assert(app);
  29. item_items_view_free(app->items_view);
  30. view_dispatcher_remove_view(app->view_dispatcher, SR_ButtonMenu);
  31. button_menu_free(app->btn_menu);
  32. scene_manager_free(app->scene_manager);
  33. view_dispatcher_free(app->view_dispatcher);
  34. furi_record_close(RECORD_STORAGE);
  35. furi_record_close(RECORD_NOTIFICATION);
  36. free(app);
  37. }