scene_error.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "app_i.h"
  2. #include <furi.h>
  3. #include <notification/notification_messages.h>
  4. #include "custom_event.h"
  5. #include "video_game_module_tool_icons.h"
  6. static void
  7. scene_error_button_callback(GuiButtonType button_type, InputType input_type, void* context) {
  8. App* app = context;
  9. if(input_type == InputTypeShort && button_type == GuiButtonTypeLeft) {
  10. view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventRetryRequested);
  11. }
  12. }
  13. void scene_error_on_enter(void* context) {
  14. App* app = context;
  15. widget_add_icon_element(app->widget, 83, 22, &I_WarningDolphinFlip_45x42);
  16. widget_add_button_element(
  17. app->widget, GuiButtonTypeLeft, "Retry", scene_error_button_callback, app);
  18. widget_add_string_element(
  19. app->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Installation Failed!");
  20. const char* error_msg;
  21. if(app->flasher_error == FlasherErrorBadFile) {
  22. error_msg = "This file is\ncorrupted or\nunsupported";
  23. } else if(app->flasher_error == FlasherErrorDisconnect) {
  24. error_msg = "The module was\ndisconnected\nduring the update";
  25. } else if(app->flasher_error == FlasherErrorUnknown) {
  26. error_msg = "An unknown error\nhas occurred";
  27. } else {
  28. furi_crash();
  29. }
  30. widget_add_string_multiline_element(
  31. app->widget, 0, 28, AlignLeft, AlignCenter, FontSecondary, error_msg);
  32. view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
  33. notification_message(app->notification, &sequence_error);
  34. notification_message(app->notification, &sequence_set_red_255);
  35. }
  36. bool scene_error_on_event(void* context, SceneManagerEvent event) {
  37. App* app = context;
  38. bool consumed = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. if(event.event == CustomEventRetryRequested) {
  41. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SceneProbe);
  42. }
  43. consumed = true;
  44. } else if(event.type == SceneManagerEventTypeBack) {
  45. furi_string_reset(app->file_path);
  46. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SceneProbe);
  47. consumed = true;
  48. }
  49. return consumed;
  50. }
  51. void scene_error_on_exit(void* context) {
  52. App* app = context;
  53. widget_reset(app->widget);
  54. notification_message(app->notification, &sequence_reset_red);
  55. }