updater_scene_loadcfg.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "../updater_i.h"
  2. #include "updater_scene.h"
  3. #include <update_util/update_operation.h>
  4. #include <furi_hal.h>
  5. void updater_scene_loadcfg_apply_callback(GuiButtonType result, InputType type, void* context) {
  6. furi_assert(context);
  7. Updater* updater = context;
  8. if(type != InputTypeShort) {
  9. return;
  10. }
  11. if(result == GuiButtonTypeRight) {
  12. view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventStartUpdate);
  13. } else if(result == GuiButtonTypeLeft) {
  14. view_dispatcher_send_custom_event(
  15. updater->view_dispatcher, UpdaterCustomEventCancelUpdate);
  16. }
  17. }
  18. void updater_scene_loadcfg_on_enter(void* context) {
  19. Updater* updater = (Updater*)context;
  20. UpdaterManifestProcessingState* pending_upd = updater->pending_update =
  21. malloc(sizeof(UpdaterManifestProcessingState));
  22. pending_upd->manifest = update_manifest_alloc();
  23. if(update_manifest_init(pending_upd->manifest, furi_string_get_cstr(updater->startup_arg))) {
  24. widget_add_string_element(
  25. updater->widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, "Update");
  26. widget_add_text_box_element(
  27. updater->widget,
  28. 5,
  29. 20,
  30. 118,
  31. 32,
  32. AlignCenter,
  33. AlignCenter,
  34. furi_string_get_cstr(pending_upd->manifest->version),
  35. true);
  36. widget_add_button_element(
  37. updater->widget,
  38. GuiButtonTypeRight,
  39. "Install",
  40. updater_scene_loadcfg_apply_callback,
  41. updater);
  42. } else {
  43. widget_add_string_element(
  44. updater->widget, 64, 24, AlignCenter, AlignCenter, FontPrimary, "Invalid manifest");
  45. }
  46. widget_add_button_element(
  47. updater->widget,
  48. GuiButtonTypeLeft,
  49. "Cancel",
  50. updater_scene_loadcfg_apply_callback,
  51. updater);
  52. view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewWidget);
  53. }
  54. bool updater_scene_loadcfg_on_event(void* context, SceneManagerEvent event) {
  55. Updater* updater = (Updater*)context;
  56. bool consumed = false;
  57. if(event.type == SceneManagerEventTypeBack) {
  58. view_dispatcher_stop(updater->view_dispatcher);
  59. consumed = true;
  60. } else if(event.type == SceneManagerEventTypeCustom) {
  61. switch(event.event) {
  62. case UpdaterCustomEventStartUpdate:
  63. updater->preparation_result =
  64. update_operation_prepare(furi_string_get_cstr(updater->startup_arg));
  65. if(updater->preparation_result == UpdatePrepareResultOK) {
  66. furi_hal_power_reset();
  67. } else {
  68. #ifndef FURI_RAM_EXEC
  69. scene_manager_next_scene(updater->scene_manager, UpdaterSceneError);
  70. #endif
  71. }
  72. consumed = true;
  73. break;
  74. case UpdaterCustomEventCancelUpdate:
  75. view_dispatcher_stop(updater->view_dispatcher);
  76. consumed = true;
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. return consumed;
  83. }
  84. void updater_scene_loadcfg_on_exit(void* context) {
  85. Updater* updater = (Updater*)context;
  86. if(updater->pending_update) {
  87. update_manifest_free(updater->pending_update->manifest);
  88. furi_string_free(updater->pending_update->message);
  89. }
  90. widget_reset(updater->widget);
  91. free(updater->pending_update);
  92. }