Explorar el Código

parse 8 apps at a time

jblanked hace 1 año
padre
commit
c4dce28290
Se han modificado 4 ficheros con 41 adiciones y 19 borrados
  1. 23 3
      apps/flip_store_apps.c
  2. 1 1
      apps/flip_store_apps.h
  3. 15 13
      callback/flip_store_callback.c
  4. 2 2
      flipper_http/flipper_http.h

+ 23 - 3
apps/flip_store_apps.c

@@ -40,6 +40,11 @@ char *categories[] = {
 
 FlipStoreAppInfo *flip_catalog_alloc()
 {
+    if (memmgr_get_free_heap() < MAX_APP_COUNT * sizeof(FlipStoreAppInfo))
+    {
+        FURI_LOG_E(TAG, "Not enough memory to allocate flip_catalog.");
+        return NULL;
+    }
     FlipStoreAppInfo *app_catalog = malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
     if (!app_catalog)
     {
@@ -87,8 +92,14 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         FURI_LOG_E("Game", "Failed to allocate json_data string");
         return NULL;
     }
-
     furi_string_cat_str(json_data_str, "{\"json_data\":");
+    if (memmgr_get_free_heap() < furi_string_size(feed_data) + furi_string_size(json_data_str) + 2)
+    {
+        FURI_LOG_E(TAG, "Not enough memory to allocate json_data_str.");
+        furi_string_free(feed_data);
+        furi_string_free(json_data_str);
+        return false;
+    }
     furi_string_cat(json_data_str, feed_data);
     furi_string_free(feed_data);
     furi_string_cat_str(json_data_str, "}");
@@ -101,14 +112,14 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         FuriString *json_data_array = get_json_array_value_furi("json_data", i, json_data_str);
         if (!json_data_array)
         {
-            FURI_LOG_I(TAG, "No more apps to process, i = %d", i);
             break;
         }
 
-        FuriString *app_id = get_json_value_furi("alias", json_data_array); // app_id is stored in the "alias" field
+        FuriString *app_id = get_json_value_furi("alias", json_data_array);
         if (!app_id)
         {
             FURI_LOG_E(TAG, "Failed to get app_id.");
+            furi_string_free(json_data_array);
             break;
         }
         snprintf(flip_catalog[i].app_id, MAX_ID_LENGTH, "%s", furi_string_get_cstr(app_id));
@@ -118,6 +129,7 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         if (!current_version)
         {
             FURI_LOG_E(TAG, "Failed to get current_version.");
+            furi_string_free(json_data_array);
             break;
         }
 
@@ -125,6 +137,8 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         if (!app_name)
         {
             FURI_LOG_E(TAG, "Failed to get app_name.");
+            furi_string_free(json_data_array);
+            furi_string_free(current_version);
             break;
         }
         snprintf(flip_catalog[i].app_name, MAX_APP_NAME_LENGTH, "%s", furi_string_get_cstr(app_name));
@@ -134,6 +148,8 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         if (!app_description)
         {
             FURI_LOG_E(TAG, "Failed to get app_description.");
+            furi_string_free(json_data_array);
+            furi_string_free(current_version);
             break;
         }
         snprintf(flip_catalog[i].app_description, MAX_APP_DESCRIPTION_LENGTH, "%s", furi_string_get_cstr(app_description));
@@ -143,6 +159,8 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         if (!app_version)
         {
             FURI_LOG_E(TAG, "Failed to get app_version.");
+            furi_string_free(json_data_array);
+            furi_string_free(current_version);
             break;
         }
         snprintf(flip_catalog[i].app_version, MAX_APP_VERSION_LENGTH, "%s", furi_string_get_cstr(app_version));
@@ -152,6 +170,8 @@ bool flip_store_process_app_list(FlipperHTTP *fhttp)
         if (!_id)
         {
             FURI_LOG_E(TAG, "Failed to get _id.");
+            furi_string_free(json_data_array);
+            furi_string_free(current_version);
             break;
         }
         snprintf(flip_catalog[i].app_build_id, MAX_ID_LENGTH, "%s", furi_string_get_cstr(_id));

+ 1 - 1
apps/flip_store_apps.h

@@ -8,7 +8,7 @@
 // Define maximum limits
 #define MAX_APP_NAME_LENGTH 32
 #define MAX_ID_LENGTH 32
-#define MAX_APP_COUNT 100
+#define MAX_APP_COUNT 50
 #define MAX_APP_DESCRIPTION_LENGTH 100
 #define MAX_APP_VERSION_LENGTH 5
 

+ 15 - 13
callback/flip_store_callback.c

@@ -777,7 +777,8 @@ static bool set_appropriate_list(FlipperHTTP *fhttp, FlipStoreApp *app)
     return false;
 }
 
-static void fetch_appropiate_app_list(FlipStoreApp *app)
+// we'll have to loop 8 at a time due to memory constraints
+static void fetch_appropiate_app_list(FlipStoreApp *app, int iteration)
 {
     FlipperHTTP *fhttp = flipper_http_alloc();
     if (!fhttp)
@@ -796,7 +797,8 @@ static void fetch_appropiate_app_list(FlipStoreApp *app)
         fhttp->save_received_data = true;
         fhttp->is_bytes_request = false;
         char url[256];
-        snprintf(url, sizeof(url), "https://catalog.flipperzero.one/api/v0/0/application?limit=10&is_latest_release_version=true&offset=0&sort_by=updated_at&sort_order=-1&category_id=%s", category_ids[flip_store_category_index]);
+        // load 8 at a time
+        snprintf(url, sizeof(url), "https://catalog.flipperzero.one/api/v0/0/application?limit=8&is_latest_release_version=true&offset=%d&sort_by=updated_at&sort_order=-1&category_id=%s", iteration, category_ids[flip_store_category_index]);
         return flipper_http_get_request_with_headers(fhttp, url, "{\"Content-Type\":\"application/json\"}");
     }
     bool parse_app_list()
@@ -864,67 +866,67 @@ void callback_submenu_choices(void *context, uint32_t index)
         free_all_views(app, true);
         flip_store_category_index = 0;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListGames:
         free_all_views(app, true);
         flip_store_category_index = 1;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListGPIO:
         free_all_views(app, true);
         flip_store_category_index = 2;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListInfrared:
         free_all_views(app, true);
         flip_store_category_index = 3;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListiButton:
         free_all_views(app, true);
         flip_store_category_index = 4;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListMedia:
         free_all_views(app, true);
         flip_store_category_index = 5;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListNFC:
         free_all_views(app, true);
         flip_store_category_index = 6;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListRFID:
         free_all_views(app, true);
         flip_store_category_index = 7;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListSubGHz:
         free_all_views(app, true);
         flip_store_category_index = 8;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListTools:
         free_all_views(app, true);
         flip_store_category_index = 9;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     case FlipStoreSubmenuIndexAppListUSB:
         free_all_views(app, true);
         flip_store_category_index = 10;
         flip_store_app_does_exist = false;
-        fetch_appropiate_app_list(app);
+        fetch_appropiate_app_list(app, 0);
         break;
     default:
         // Check if the index is within the firmwares list range

+ 2 - 2
flipper_http/flipper_http.h

@@ -22,8 +22,8 @@
 #define TIMEOUT_DURATION_TICKS (5 * 1000) // 5 seconds
 #define BAUDRATE (115200)                 // UART baudrate
 #define RX_BUF_SIZE 2048                  // UART RX buffer size
-#define RX_LINE_BUFFER_SIZE 16000         // UART RX line buffer size (increase for large responses)
-#define MAX_FILE_SHOW 16000               // Maximum data from file to show
+#define RX_LINE_BUFFER_SIZE 2048          // UART RX line buffer size (increase for large responses)
+#define MAX_FILE_SHOW 12000               // Maximum data from file to show
 #define FILE_BUFFER_SIZE 512              // File buffer size
 
 // Forward declaration for callback