updater_scene_loadcfg.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "updater/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, string_get_cstr(updater->startup_arg))) {
  24. widget_add_string_element(
  25. updater->widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, "Update");
  26. widget_add_string_multiline_element(
  27. updater->widget,
  28. 64,
  29. 32,
  30. AlignCenter,
  31. AlignCenter,
  32. FontSecondary,
  33. string_get_cstr(pending_upd->manifest->version));
  34. widget_add_button_element(
  35. updater->widget,
  36. GuiButtonTypeRight,
  37. "Install",
  38. updater_scene_loadcfg_apply_callback,
  39. updater);
  40. } else {
  41. widget_add_string_element(
  42. updater->widget, 64, 24, AlignCenter, AlignCenter, FontPrimary, "Invalid manifest");
  43. }
  44. widget_add_button_element(
  45. updater->widget,
  46. GuiButtonTypeLeft,
  47. "Cancel",
  48. updater_scene_loadcfg_apply_callback,
  49. updater);
  50. view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewWidget);
  51. }
  52. bool updater_scene_loadcfg_on_event(void* context, SceneManagerEvent event) {
  53. Updater* updater = (Updater*)context;
  54. bool consumed = false;
  55. if(event.type == SceneManagerEventTypeBack) {
  56. view_dispatcher_stop(updater->view_dispatcher);
  57. consumed = true;
  58. } else if(event.type == SceneManagerEventTypeCustom) {
  59. switch(event.event) {
  60. case UpdaterCustomEventStartUpdate:
  61. updater->preparation_result =
  62. update_operation_prepare(string_get_cstr(updater->startup_arg));
  63. if(updater->preparation_result == UpdatePrepareResultOK) {
  64. furi_hal_power_reset();
  65. } else {
  66. #ifndef FURI_RAM_EXEC
  67. scene_manager_next_scene(updater->scene_manager, UpdaterSceneError);
  68. #endif
  69. }
  70. consumed = true;
  71. break;
  72. case UpdaterCustomEventCancelUpdate:
  73. view_dispatcher_stop(updater->view_dispatcher);
  74. consumed = true;
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. return consumed;
  81. }
  82. void updater_scene_loadcfg_on_exit(void* context) {
  83. Updater* updater = (Updater*)context;
  84. if(updater->pending_update) {
  85. update_manifest_free(updater->pending_update->manifest);
  86. string_clear(updater->pending_update->message);
  87. }
  88. widget_reset(updater->widget);
  89. free(updater->pending_update);
  90. }