quac.c 2.9 KB

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