flip_store.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include <flip_store.h>
  2. #include <apps/flip_store_apps.h>
  3. FlipStoreApp *app_instance = NULL;
  4. // Function to free the resources used by FlipStoreApp
  5. void flip_store_app_free(FlipStoreApp *app)
  6. {
  7. if (!app)
  8. {
  9. FURI_LOG_E(TAG, "FlipStoreApp is NULL");
  10. return;
  11. }
  12. flip_catalog_free();
  13. // Free Widget(s)
  14. if (app->widget_result)
  15. {
  16. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewWidgetResult);
  17. widget_free(app->widget_result);
  18. }
  19. // Free View(s)
  20. if (app->view_loader)
  21. {
  22. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewLoader);
  23. flip_store_loader_free_model(app->view_loader);
  24. view_free(app->view_loader);
  25. }
  26. if (app->view_app_info)
  27. {
  28. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppInfo);
  29. view_free(app->view_app_info);
  30. }
  31. // Free Submenu(s)
  32. if (app->submenu_main)
  33. {
  34. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSubmenu);
  35. submenu_free(app->submenu_main);
  36. }
  37. if (app->submenu_options)
  38. {
  39. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSubmenuOptions);
  40. submenu_free(app->submenu_options);
  41. }
  42. if (app->submenu_app_list)
  43. {
  44. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppList);
  45. submenu_free(app->submenu_app_list);
  46. }
  47. if (app->submenu_firmwares)
  48. {
  49. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewFirmwares);
  50. submenu_free(app->submenu_firmwares);
  51. }
  52. // Free Variable Item List(s)
  53. if (app->variable_item_list)
  54. {
  55. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSettings);
  56. variable_item_list_free(app->variable_item_list);
  57. }
  58. // Free Text Input(s)
  59. if (app->uart_text_input_ssid)
  60. {
  61. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewTextInputSSID);
  62. uart_text_input_free(app->uart_text_input_ssid);
  63. }
  64. if (app->uart_text_input_pass)
  65. {
  66. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewTextInputPass);
  67. uart_text_input_free(app->uart_text_input_pass);
  68. }
  69. // Free popup
  70. if (app->popup)
  71. {
  72. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewPopup);
  73. popup_free(app->popup);
  74. }
  75. // Free dialog
  76. if (app->dialog_delete)
  77. {
  78. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppDelete);
  79. dialog_ex_free(app->dialog_delete);
  80. }
  81. if (app->dialog_firmware)
  82. {
  83. view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewFirmwareDialog);
  84. dialog_ex_free(app->dialog_firmware);
  85. }
  86. // free the view dispatcher
  87. view_dispatcher_free(app->view_dispatcher);
  88. // close the gui
  89. furi_record_close(RECORD_GUI);
  90. // free the app
  91. free(app);
  92. }
  93. void flip_store_request_error(Canvas *canvas)
  94. {
  95. if (fhttp.last_response != NULL)
  96. {
  97. if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
  98. {
  99. canvas_clear(canvas);
  100. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  101. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  102. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  103. }
  104. else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
  105. {
  106. canvas_clear(canvas);
  107. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  108. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  109. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  110. }
  111. else
  112. {
  113. FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
  114. canvas_draw_str(canvas, 0, 42, "Unusual error...");
  115. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  116. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  117. }
  118. }
  119. else
  120. {
  121. canvas_clear(canvas);
  122. canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
  123. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  124. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  125. }
  126. }