quac.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <furi.h>
  2. #include <gui/gui.h>
  3. #include <gui/view_dispatcher.h>
  4. #include <gui/scene_manager.h>
  5. #include <gui/modules/button_menu.h>
  6. #include <gui/modules/dialog_ex.h>
  7. #include <storage/storage.h>
  8. #include <notification/notification_messages.h>
  9. #include "item.h"
  10. #include "scenes/scenes.h"
  11. #include "scenes/scene_items.h"
  12. #include "quac.h"
  13. /* generated by fbt from .png files in images folder */
  14. #include <quac_icons.h>
  15. App* app_alloc() {
  16. App* app = malloc(sizeof(App));
  17. app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
  18. app->view_dispatcher = view_dispatcher_alloc();
  19. view_dispatcher_enable_queue(app->view_dispatcher);
  20. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  21. view_dispatcher_set_custom_event_callback(app->view_dispatcher, app_scene_custom_callback);
  22. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, app_back_event_callback);
  23. // Create our UI elements
  24. app->btn_menu = button_menu_alloc();
  25. view_dispatcher_add_view(
  26. app->view_dispatcher, SR_ButtonMenu, button_menu_get_view(app->btn_menu));
  27. app->dialog = dialog_ex_alloc();
  28. view_dispatcher_add_view(app->view_dispatcher, SR_Dialog, dialog_ex_get_view(app->dialog));
  29. // Storage
  30. app->storage = furi_record_open(RECORD_STORAGE);
  31. // Notifications - for LED light access
  32. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  33. // initialize device items list
  34. app->depth = 0;
  35. app->selected_item = -1;
  36. app->items_view = item_get_items_view_from_path(app, NULL);
  37. return app;
  38. }
  39. void app_free(App* app) {
  40. furi_assert(app);
  41. item_items_view_free(app->items_view);
  42. view_dispatcher_remove_view(app->view_dispatcher, SR_ButtonMenu);
  43. button_menu_free(app->btn_menu);
  44. scene_manager_free(app->scene_manager);
  45. view_dispatcher_free(app->view_dispatcher);
  46. furi_record_close(RECORD_STORAGE);
  47. furi_record_close(RECORD_NOTIFICATION);
  48. free(app);
  49. }
  50. // FAP Entry Point
  51. int32_t quac_app(void* p) {
  52. UNUSED(p);
  53. FURI_LOG_I(TAG, "QUAC! QUAC!");
  54. App* app = app_alloc();
  55. Gui* gui = furi_record_open(RECORD_GUI);
  56. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  57. scene_manager_next_scene(app->scene_manager, SR_Scene_Items);
  58. view_dispatcher_run(app->view_dispatcher);
  59. furi_record_close(RECORD_GUI);
  60. app_free(app);
  61. return 0;
  62. }