desktop_scene_main.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 DesktopMainEventOpenFavoritePrimary:
  87. LOAD_DESKTOP_SETTINGS(&desktop->settings);
  88. if(desktop->settings.favorite_primary < FLIPPER_APPS_COUNT) {
  89. LoaderStatus status = loader_start(
  90. desktop->loader, FLIPPER_APPS[desktop->settings.favorite_primary].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 primary favorite application");
  96. }
  97. consumed = true;
  98. break;
  99. case DesktopMainEventOpenFavoriteSecondary:
  100. LOAD_DESKTOP_SETTINGS(&desktop->settings);
  101. if(desktop->settings.favorite_secondary < FLIPPER_APPS_COUNT) {
  102. LoaderStatus status = loader_start(
  103. desktop->loader,
  104. FLIPPER_APPS[desktop->settings.favorite_secondary].name,
  105. NULL);
  106. if(status != LoaderStatusOk) {
  107. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  108. }
  109. } else {
  110. FURI_LOG_E(TAG, "Can't find secondary favorite application");
  111. }
  112. consumed = true;
  113. break;
  114. case DesktopAnimationEventCheckAnimation:
  115. animation_manager_check_blocking_process(desktop->animation_manager);
  116. consumed = true;
  117. break;
  118. case DesktopAnimationEventNewIdleAnimation:
  119. animation_manager_new_idle_process(desktop->animation_manager);
  120. consumed = true;
  121. break;
  122. case DesktopAnimationEventInteractAnimation:
  123. if(!animation_manager_interact_process(desktop->animation_manager)) {
  124. LoaderStatus status = loader_start(desktop->loader, "Passport", NULL);
  125. if(status != LoaderStatusOk) {
  126. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  127. }
  128. }
  129. consumed = true;
  130. break;
  131. case DesktopLockedEventUpdate:
  132. desktop_view_locked_update(desktop->locked_view);
  133. consumed = true;
  134. break;
  135. default:
  136. break;
  137. }
  138. }
  139. return consumed;
  140. }
  141. void desktop_scene_main_on_exit(void* context) {
  142. Desktop* desktop = (Desktop*)context;
  143. animation_manager_set_new_idle_callback(desktop->animation_manager, NULL);
  144. animation_manager_set_check_callback(desktop->animation_manager, NULL);
  145. animation_manager_set_interact_callback(desktop->animation_manager, NULL);
  146. animation_manager_set_context(desktop->animation_manager, desktop);
  147. }