flip_library.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if(!app) {
  6. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  7. return;
  8. }
  9. // Free View(s)
  10. if(app->view_random_facts) {
  11. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactsRun);
  12. view_free(app->view_random_facts);
  13. }
  14. if(app->view_dictionary) {
  15. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryRun);
  16. view_free(app->view_dictionary);
  17. }
  18. // Free Submenu(s)
  19. if(app->submenu_main) {
  20. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSubmenuMain);
  21. submenu_free(app->submenu_main);
  22. }
  23. if(app->submenu_random_facts) {
  24. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFacts);
  25. submenu_free(app->submenu_random_facts);
  26. }
  27. // Free Widget(s)
  28. if(app->widget) {
  29. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewAbout);
  30. widget_free(app->widget);
  31. }
  32. if(app->widget_random_fact) {
  33. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactWidget);
  34. widget_free(app->widget_random_fact);
  35. }
  36. if(app->widget_dictionary) {
  37. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryWidget);
  38. widget_free(app->widget_dictionary);
  39. }
  40. // Free Variable Item List(s)
  41. if(app->variable_item_list_wifi) {
  42. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSettings);
  43. variable_item_list_free(app->variable_item_list_wifi);
  44. }
  45. // Free Text Input(s)
  46. if(app->uart_text_input_ssid) {
  47. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputSSID);
  48. text_input_free(app->uart_text_input_ssid);
  49. }
  50. if(app->uart_text_input_password) {
  51. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputPassword);
  52. text_input_free(app->uart_text_input_password);
  53. }
  54. if(app->uart_text_input_dictionary) {
  55. view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryTextInput);
  56. text_input_free(app->uart_text_input_dictionary);
  57. }
  58. // deinitalize flipper http
  59. flipper_http_deinit();
  60. // free the view dispatcher
  61. if(app->view_dispatcher) view_dispatcher_free(app->view_dispatcher);
  62. // close the gui
  63. furi_record_close(RECORD_GUI);
  64. if(app_instance) {
  65. // free the app instance
  66. free(app_instance);
  67. app_instance = NULL;
  68. }
  69. // free the app
  70. free(app);
  71. }