desktop_scene_main.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <furi.h>
  2. #include <furi_hal.h>
  3. #include <applications.h>
  4. #include <assets_icons.h>
  5. #include <loader/loader.h>
  6. #include "../desktop_i.h"
  7. #include "../views/desktop_events.h"
  8. #include "../views/desktop_view_main.h"
  9. #include "desktop_scene.h"
  10. #include "desktop_scene_i.h"
  11. #define TAG "DesktopSrv"
  12. static void desktop_scene_main_new_idle_animation_callback(void* context) {
  13. furi_assert(context);
  14. Desktop* desktop = context;
  15. view_dispatcher_send_custom_event(
  16. desktop->view_dispatcher, DesktopAnimationEventNewIdleAnimation);
  17. }
  18. static void desktop_scene_main_check_animation_callback(void* context) {
  19. furi_assert(context);
  20. Desktop* desktop = context;
  21. view_dispatcher_send_custom_event(
  22. desktop->view_dispatcher, DesktopAnimationEventCheckAnimation);
  23. }
  24. static void desktop_scene_main_interact_animation_callback(void* context) {
  25. furi_assert(context);
  26. Desktop* desktop = context;
  27. view_dispatcher_send_custom_event(
  28. desktop->view_dispatcher, DesktopAnimationEventInteractAnimation);
  29. }
  30. #ifdef APP_ARCHIVE
  31. static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* flipper_app) {
  32. furi_assert(desktop);
  33. furi_assert(flipper_app);
  34. furi_assert(flipper_app->app);
  35. furi_assert(flipper_app->name);
  36. if(furi_thread_get_state(desktop->scene_thread) != FuriThreadStateStopped) {
  37. FURI_LOG_E("Desktop", "Thread is already running");
  38. return;
  39. }
  40. furi_thread_set_name(desktop->scene_thread, flipper_app->name);
  41. furi_thread_set_stack_size(desktop->scene_thread, flipper_app->stack_size);
  42. furi_thread_set_callback(desktop->scene_thread, flipper_app->app);
  43. furi_thread_start(desktop->scene_thread);
  44. }
  45. #endif
  46. void desktop_scene_main_callback(DesktopEvent event, void* context) {
  47. Desktop* desktop = (Desktop*)context;
  48. view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
  49. }
  50. void desktop_scene_main_on_enter(void* context) {
  51. Desktop* desktop = (Desktop*)context;
  52. DesktopMainView* main_view = desktop->main_view;
  53. animation_manager_set_context(desktop->animation_manager, desktop);
  54. animation_manager_set_new_idle_callback(
  55. desktop->animation_manager, desktop_scene_main_new_idle_animation_callback);
  56. animation_manager_set_check_callback(
  57. desktop->animation_manager, desktop_scene_main_check_animation_callback);
  58. animation_manager_set_interact_callback(
  59. desktop->animation_manager, desktop_scene_main_interact_animation_callback);
  60. desktop_main_set_callback(main_view, desktop_scene_main_callback, desktop);
  61. view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdMain);
  62. }
  63. bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
  64. Desktop* desktop = (Desktop*)context;
  65. bool consumed = false;
  66. if(event.type == SceneManagerEventTypeCustom) {
  67. switch(event.event) {
  68. case DesktopMainEventOpenMenu:
  69. loader_show_menu();
  70. consumed = true;
  71. break;
  72. case DesktopMainEventOpenLockMenu:
  73. scene_manager_next_scene(desktop->scene_manager, DesktopSceneLockMenu);
  74. consumed = true;
  75. break;
  76. case DesktopMainEventOpenDebug:
  77. scene_manager_next_scene(desktop->scene_manager, DesktopSceneDebug);
  78. consumed = true;
  79. break;
  80. case DesktopMainEventOpenArchive:
  81. #ifdef APP_ARCHIVE
  82. desktop_switch_to_app(desktop, &FLIPPER_ARCHIVE);
  83. #endif
  84. consumed = true;
  85. break;
  86. case DesktopMainEventOpenFavorite:
  87. LOAD_DESKTOP_SETTINGS(&desktop->settings);
  88. if(desktop->settings.favorite < FLIPPER_APPS_COUNT) {
  89. LoaderStatus status = loader_start(
  90. desktop->loader, FLIPPER_APPS[desktop->settings.favorite].name, NULL);
  91. if(status != LoaderStatusOk) {
  92. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  93. }
  94. } else {
  95. FURI_LOG_E(TAG, "Can't find favorite application");
  96. }
  97. consumed = true;
  98. break;
  99. case DesktopAnimationEventCheckAnimation:
  100. animation_manager_check_blocking_process(desktop->animation_manager);
  101. consumed = true;
  102. break;
  103. case DesktopAnimationEventNewIdleAnimation:
  104. animation_manager_new_idle_process(desktop->animation_manager);
  105. consumed = true;
  106. break;
  107. case DesktopAnimationEventInteractAnimation:
  108. if(!animation_manager_interact_process(desktop->animation_manager)) {
  109. LoaderStatus status = loader_start(desktop->loader, "Passport", NULL);
  110. if(status != LoaderStatusOk) {
  111. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  112. }
  113. }
  114. consumed = true;
  115. break;
  116. case DesktopLockedEventUpdate:
  117. desktop_view_locked_update(desktop->locked_view);
  118. consumed = true;
  119. break;
  120. default:
  121. break;
  122. }
  123. }
  124. return consumed;
  125. }
  126. void desktop_scene_main_on_exit(void* context) {
  127. Desktop* desktop = (Desktop*)context;
  128. animation_manager_set_new_idle_callback(desktop->animation_manager, NULL);
  129. animation_manager_set_check_callback(desktop->animation_manager, NULL);
  130. animation_manager_set_interact_callback(desktop->animation_manager, NULL);
  131. animation_manager_set_context(desktop->animation_manager, desktop);
  132. }