Просмотр исходного кода

finally fixing the issue. stopped poller when it's not on

zinongli 11 месяцев назад
Родитель
Сommit
f6eb53a431
2 измененных файлов с 13 добавлено и 6 удалено
  1. 0 1
      scenes/metroflip_scene_parse.c
  2. 13 5
      scenes/plugins/suica.c

+ 0 - 1
scenes/metroflip_scene_parse.c

@@ -57,7 +57,6 @@ void metroflip_scene_parse_on_exit(void* context) {
         // Get and run the plugin's on_exit function
         const MetroflipPlugin* plugin = plugin_manager_get_ep(app->plugin_manager, 0);
         plugin->plugin_on_exit(app);
-        FURI_LOG_I(TAG, "Parse scene exit");
 
         plugin_manager_free(app->plugin_manager);
         composite_api_resolver_free(app->resolver);

+ 13 - 5
scenes/plugins/suica.c

@@ -225,7 +225,6 @@ static void suica_parse(SuicaHistoryViewModel* my_model) {
         my_model->history.day = 0;
     }
     my_model->history.balance = ((uint16_t)current_block[11] << 8) | (uint16_t)current_block[10];
-    // FURI_LOG_I(TAG,"%02X", (uint8_t)current_block[0]);
     my_model->history.area_code = current_block[15];
     if((uint8_t)current_block[0] >= TERMINAL_TICKET_VENDING_MACHINE &&
        (uint8_t)current_block[0] <= TERMINAL_IN_CAR_SUPP_MACHINE) {
@@ -481,6 +480,7 @@ static void suica_on_enter(Metroflip* app) {
             ViewModelTypeLockFree,
             sizeof(SuicaHistoryViewModel));
     }
+
     view_set_input_callback(app->suica_context->view_history, suica_history_input_callback);
     view_set_previous_callback(app->suica_context->view_history, suica_navigation_raw_callback);
     view_set_enter_callback(app->suica_context->view_history, suica_view_history_enter_callback);
@@ -568,16 +568,24 @@ static bool suica_on_event(Metroflip* app, SceneManagerEvent event) {
 
 static void suica_on_exit(Metroflip* app) {
     widget_reset(app->widget);
+    with_view_model(
+        app->suica_context->view_history,
+        SuicaHistoryViewModel * model,
+        {
+            if(model->travel_history) { // Check if memory was allocated
+                free(model->travel_history);
+                model->travel_history = NULL; // Set pointer to NULL to prevent dangling references
+            }
+        },
+        false);
     view_free_model(app->suica_context->view_history);
-    view_free(app->suica_context->view_history);
     view_dispatcher_remove_view(app->view_dispatcher, MetroflipViewCanvas);
+    view_free(app->suica_context->view_history);
     free(app->suica_context);
-    metroflip_app_blink_stop(app);
-    if(app->poller) {
+    if(app->poller && !app->data_loaded) {
         nfc_poller_stop(app->poller);
         nfc_poller_free(app->poller);
     }
-    FURI_LOG_I(TAG, "Suica scene exit");
 }
 
 /* Actual implementation of app<>plugin interface */