desktop_scene_main.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 DesktopMainEventOpenPowerOff: {
  87. LoaderStatus status = loader_start(desktop->loader, "Power", "off");
  88. if(status != LoaderStatusOk) {
  89. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  90. }
  91. consumed = true;
  92. break;
  93. }
  94. case DesktopMainEventOpenFavoritePrimary:
  95. DESKTOP_SETTINGS_LOAD(&desktop->settings);
  96. if(desktop->settings.favorite_primary.is_external) {
  97. LoaderStatus status = loader_start(
  98. desktop->loader,
  99. FAP_LOADER_APP_NAME,
  100. desktop->settings.favorite_primary.name_or_path);
  101. if(status != LoaderStatusOk) {
  102. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  103. }
  104. } else {
  105. LoaderStatus status = loader_start(
  106. desktop->loader, desktop->settings.favorite_primary.name_or_path, NULL);
  107. if(status != LoaderStatusOk) {
  108. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  109. }
  110. }
  111. consumed = true;
  112. break;
  113. case DesktopMainEventOpenFavoriteSecondary:
  114. DESKTOP_SETTINGS_LOAD(&desktop->settings);
  115. if(desktop->settings.favorite_secondary.is_external) {
  116. LoaderStatus status = loader_start(
  117. desktop->loader,
  118. FAP_LOADER_APP_NAME,
  119. desktop->settings.favorite_secondary.name_or_path);
  120. if(status != LoaderStatusOk) {
  121. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  122. }
  123. } else {
  124. LoaderStatus status = loader_start(
  125. desktop->loader, desktop->settings.favorite_secondary.name_or_path, NULL);
  126. if(status != LoaderStatusOk) {
  127. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  128. }
  129. }
  130. consumed = true;
  131. break;
  132. case DesktopAnimationEventCheckAnimation:
  133. animation_manager_check_blocking_process(desktop->animation_manager);
  134. consumed = true;
  135. break;
  136. case DesktopAnimationEventNewIdleAnimation:
  137. animation_manager_new_idle_process(desktop->animation_manager);
  138. consumed = true;
  139. break;
  140. case DesktopAnimationEventInteractAnimation:
  141. if(!animation_manager_interact_process(desktop->animation_manager)) {
  142. LoaderStatus status = loader_start(desktop->loader, "Passport", NULL);
  143. if(status != LoaderStatusOk) {
  144. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  145. }
  146. }
  147. consumed = true;
  148. break;
  149. case DesktopMainEventOpenPassport: {
  150. LoaderStatus status = loader_start(desktop->loader, "Passport", NULL);
  151. if(status != LoaderStatusOk) {
  152. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  153. }
  154. break;
  155. }
  156. case DesktopMainEventOpenGameMenu: {
  157. LoaderStatus status = loader_start(
  158. desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("/apps/Games/snake_game.fap"));
  159. if(status != LoaderStatusOk) {
  160. FURI_LOG_E(TAG, "loader_start failed: %d", status);
  161. }
  162. break;
  163. }
  164. case DesktopLockedEventUpdate:
  165. desktop_view_locked_update(desktop->locked_view);
  166. consumed = true;
  167. break;
  168. default:
  169. break;
  170. }
  171. }
  172. return consumed;
  173. }
  174. void desktop_scene_main_on_exit(void* context) {
  175. Desktop* desktop = (Desktop*)context;
  176. animation_manager_set_new_idle_callback(desktop->animation_manager, NULL);
  177. animation_manager_set_check_callback(desktop->animation_manager, NULL);
  178. animation_manager_set_interact_callback(desktop->animation_manager, NULL);
  179. animation_manager_set_context(desktop->animation_manager, desktop);
  180. }