desktop_scene_main.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "../desktop_i.h"
  2. #include "../views/desktop_main.h"
  3. #include "applications.h"
  4. #include "assets_icons.h"
  5. #include "dolphin/dolphin.h"
  6. #include "furi/pubsub.h"
  7. #include "furi/record.h"
  8. #include "storage/storage-glue.h"
  9. #include <loader/loader.h>
  10. #include <m-list.h>
  11. #define MAIN_VIEW_DEFAULT (0UL)
  12. static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* flipper_app) {
  13. furi_assert(desktop);
  14. furi_assert(flipper_app);
  15. furi_assert(flipper_app->app);
  16. furi_assert(flipper_app->name);
  17. if(furi_thread_get_state(desktop->scene_thread) != FuriThreadStateStopped) {
  18. FURI_LOG_E("Desktop", "Thread is already running");
  19. return;
  20. }
  21. furi_thread_set_name(desktop->scene_thread, flipper_app->name);
  22. furi_thread_set_stack_size(desktop->scene_thread, flipper_app->stack_size);
  23. furi_thread_set_callback(desktop->scene_thread, flipper_app->app);
  24. furi_thread_start(desktop->scene_thread);
  25. }
  26. void desktop_scene_main_callback(DesktopMainEvent event, void* context) {
  27. Desktop* desktop = (Desktop*)context;
  28. view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
  29. }
  30. static void desktop_scene_main_animation_changed_callback(void* context) {
  31. furi_assert(context);
  32. Desktop* desktop = context;
  33. view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopMainEventUpdateAnimation);
  34. }
  35. void desktop_scene_main_on_enter(void* context) {
  36. Desktop* desktop = (Desktop*)context;
  37. DesktopMainView* main_view = desktop->main_view;
  38. desktop_main_set_callback(main_view, desktop_scene_main_callback, desktop);
  39. view_port_enabled_set(desktop->lock_viewport, false);
  40. if(scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneMain) ==
  41. DesktopMainEventUnlocked) {
  42. desktop_main_unlocked(desktop->main_view);
  43. }
  44. desktop_animation_activate(desktop->animation);
  45. desktop_animation_set_animation_changed_callback(
  46. desktop->animation, desktop_scene_main_animation_changed_callback, desktop);
  47. bool status_bar_background_black = false;
  48. const Icon* icon =
  49. desktop_animation_get_animation(desktop->animation, &status_bar_background_black);
  50. desktop_main_switch_dolphin_animation(desktop->main_view, icon, status_bar_background_black);
  51. view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewMain);
  52. }
  53. bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
  54. Desktop* desktop = (Desktop*)context;
  55. bool consumed = false;
  56. if(event.type == SceneManagerEventTypeCustom) {
  57. switch(event.event) {
  58. case DesktopMainEventOpenMenu:
  59. loader_show_menu();
  60. consumed = true;
  61. break;
  62. case DesktopMainEventOpenLockMenu:
  63. scene_manager_next_scene(desktop->scene_manager, DesktopSceneLockMenu);
  64. consumed = true;
  65. break;
  66. case DesktopMainEventOpenDebug:
  67. scene_manager_next_scene(desktop->scene_manager, DesktopSceneDebug);
  68. consumed = true;
  69. break;
  70. case DesktopMainEventOpenArchive:
  71. desktop_switch_to_app(desktop, &FLIPPER_ARCHIVE);
  72. consumed = true;
  73. break;
  74. case DesktopMainEventOpenFavorite:
  75. LOAD_DESKTOP_SETTINGS(&desktop->settings);
  76. desktop_switch_to_app(desktop, &FLIPPER_APPS[desktop->settings.favorite]);
  77. consumed = true;
  78. break;
  79. case DesktopMainEventUpdateAnimation: {
  80. bool status_bar_background_black = false;
  81. const Icon* icon =
  82. desktop_animation_get_animation(desktop->animation, &status_bar_background_black);
  83. desktop_main_switch_dolphin_animation(
  84. desktop->main_view, icon, status_bar_background_black);
  85. consumed = true;
  86. break;
  87. }
  88. case DesktopMainEventRightShort: {
  89. DesktopAnimationState state = desktop_animation_handle_right(desktop->animation);
  90. if(state == DesktopAnimationStateLevelUpIsPending) {
  91. scene_manager_next_scene(desktop->scene_manager, DesktopSceneLevelUp);
  92. }
  93. break;
  94. }
  95. default:
  96. break;
  97. }
  98. if(event.event != DesktopMainEventUpdateAnimation) {
  99. desktop_animation_activate(desktop->animation);
  100. }
  101. } else if(event.type != SceneManagerEventTypeTick) {
  102. desktop_animation_activate(desktop->animation);
  103. }
  104. return consumed;
  105. }
  106. void desktop_scene_main_on_exit(void* context) {
  107. Desktop* desktop = (Desktop*)context;
  108. desktop_animation_set_animation_changed_callback(desktop->animation, NULL, NULL);
  109. scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneMain, MAIN_VIEW_DEFAULT);
  110. desktop_main_reset_hint(desktop->main_view);
  111. }