flip_library.c 2.7 KB

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