flip_library_free.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef FLIP_LIBRARY_FREE_H
  2. #define FLIP_LIBRARY_FREE_H
  3. // Function to free the resources used by FlipLibraryApp
  4. static void flip_library_app_free(FlipLibraryApp *app)
  5. {
  6. if (!app)
  7. {
  8. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  9. return;
  10. }
  11. // disconnect wifi
  12. if (!flipper_http_disconnect_wifi())
  13. {
  14. FURI_LOG_E(TAG, "Failed to disconnect from wifi");
  15. }
  16. // Free View(s)
  17. if (app->view_random_facts)
  18. {
  19. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactsRun);
  20. view_free(app->view_random_facts);
  21. }
  22. if (app->view_dictionary)
  23. {
  24. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryRun);
  25. view_free(app->view_dictionary);
  26. }
  27. // Free Submenu(s)
  28. if (app->submenu_main)
  29. {
  30. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSubmenuMain);
  31. submenu_free(app->submenu_main);
  32. }
  33. if (app->submenu_random_facts)
  34. {
  35. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFacts);
  36. submenu_free(app->submenu_random_facts);
  37. }
  38. // Free Widget(s)
  39. if (app->widget)
  40. {
  41. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewAbout);
  42. widget_free(app->widget);
  43. }
  44. if (app->widget_random_fact)
  45. {
  46. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactWidget);
  47. widget_free(app->widget_random_fact);
  48. }
  49. if (app->widget_dictionary)
  50. {
  51. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryWidget);
  52. widget_free(app->widget_dictionary);
  53. }
  54. // Free Variable Item List(s)
  55. if (app->variable_item_list_wifi)
  56. {
  57. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSettings);
  58. variable_item_list_free(app->variable_item_list_wifi);
  59. }
  60. // Free Text Input(s)
  61. if (app->uart_text_input_ssid)
  62. {
  63. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputSSID);
  64. uart_text_input_free(app->uart_text_input_ssid);
  65. }
  66. if (app->uart_text_input_password)
  67. {
  68. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputPassword);
  69. uart_text_input_free(app->uart_text_input_password);
  70. }
  71. if (app->uart_text_input_dictionary)
  72. {
  73. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryTextInput);
  74. uart_text_input_free(app->uart_text_input_dictionary);
  75. }
  76. // deinitalize flipper http
  77. flipper_http_deinit();
  78. // free the view dispatcher
  79. if (app->view_dispatcher)
  80. view_dispatcher_free(app->view_dispatcher);
  81. // close the gui
  82. furi_record_close(RECORD_GUI);
  83. if (app_instance)
  84. {
  85. // free the app instance
  86. free(app_instance);
  87. app_instance = NULL;
  88. }
  89. // free the app
  90. free(app);
  91. }
  92. #endif // FLIP_LIBRARY_FREE_H