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

switch to loading task, update readme, final edits

jblanked 1 год назад
Родитель
Сommit
fcfff7869e
4 измененных файлов с 71 добавлено и 47 удалено
  1. 1 1
      README.md
  2. 7 7
      assets/README.md
  3. 59 37
      callback/flip_store_callback.c
  4. 4 2
      github/flip_store_github.c

+ 1 - 1
README.md

@@ -1,5 +1,5 @@
 # FlipStore
-Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no longer need another device to install apps. FlipStore uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
+Download Flipper Zero apps directly to your Flipper Zero using WiFi. 
 
 ## Features
 - App Catalog

+ 7 - 7
assets/README.md

@@ -1,12 +1,12 @@
-# FlipStore
-Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no longer need another device to install apps. FlipStore uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
+Download Flipper Zero apps directly to your Flipper Zero using WiFi. 
 
-## Features 
+## Features
 - App Catalog
 - Install Apps
 - Delete Apps 
-- Install Developer Board Flashes
-- Install Custom Apps (coming soon)
+- Install WiFi Developer Board Firmware
+- Install Video Game Module Firmware
+- Install GitHub Repositories (Beta)
 - Install Official Firmware (coming soon)
 
 ## Installation
@@ -38,7 +38,7 @@ Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no long
 - UX Improvements
 
 **v0.8**
-- Download custom apps from a GitHub URL
+- Download GitHub repositories
 
 **1.0**
-- Download Official Firmware/Firmware Updates
+- Download Official Flipper Zero Firmware

+ 59 - 37
callback/flip_store_callback.c

@@ -400,55 +400,77 @@ static void flip_store_text_updated_author(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewTextInput);
 }
 
-static bool flip_store_fetch_github(DataLoaderModel *model)
+static bool flip_store_fetch_github(FlipperHTTP *fhttp)
 {
-    if (!model || !model->fhttp)
+    if (!fhttp)
     {
-        FURI_LOG_E(TAG, "Model/FlipperHTTP is NULL");
+        FURI_LOG_E(TAG, "FlipperHTTP is NULL");
         return false;
     }
-
-    if (model->request_index == 0)
+    char author[64];
+    char repo[64];
+    if (!load_char("Github-Author", author, sizeof(author)) || !load_char("Github-Repo", repo, sizeof(repo)))
     {
-        char author[64];
-        char repo[64];
-        if (!load_char("Github-Author", author, sizeof(author)) || !load_char("Github-Repo", repo, sizeof(repo)))
-        {
-            FURI_LOG_E(TAG, "Failed to load Github author or repo");
-            return false;
-        }
-
-        return flip_store_get_github_contents(model->fhttp, author, repo);
+        FURI_LOG_E(TAG, "Failed to load Github author or repo");
+        return false;
     }
-    return false; // return false for now
+    return flip_store_get_github_contents(fhttp, author, repo);
 }
 
-static char *flip_store_parse_github(DataLoaderModel *model)
+static bool flip_store_parse_github(FlipperHTTP *fhttp)
 {
-    if (model->request_index == 0)
+    if (!fhttp)
     {
-        char author[64];
-        char repo[64];
-        if (!load_char("Github-Author", author, sizeof(author)) || !load_char("Github-Repo", repo, sizeof(repo)))
-        {
-            FURI_LOG_E(TAG, "Failed to load Github author or repo");
-            return "Failed to load Github author or repo";
-        }
-        if (!flip_store_parse_github_contents(model->fhttp->file_path, author, repo))
-        {
-            return "Failed to parse Github contents";
-        }
-        if (!flip_store_install_all_github_files(model->fhttp, author, repo))
-        {
-            return "Failed to install all Github files";
-        }
-        return "Repository downloaded successfully";
+        FURI_LOG_E(TAG, "FlipperHTTP is NULL");
+        return false;
+    }
+    char author[64];
+    char repo[64];
+    if (!load_char("Github-Author", author, sizeof(author)) || !load_char("Github-Repo", repo, sizeof(repo)))
+    {
+        FURI_LOG_E(TAG, "Failed to load Github author or repo");
+        return false;
+    }
+    if (!flip_store_parse_github_contents(fhttp->file_path, author, repo))
+    {
+        return false;
     }
-    return "Failed to download repository.";
+    return flip_store_install_all_github_files(fhttp, author, repo);
 }
-static void flip_store_github_switch_to_view(FlipStoreApp *app)
+static bool github_success = false;
+static void flip_store_get_github_repository(FlipStoreApp *app)
 {
-    flip_store_generic_switch_to_view(app, "Downloading Repository..", flip_store_fetch_github, flip_store_parse_github, 2, callback_to_submenu_options, FlipStoreViewLoader);
+    FlipperHTTP *fhttp = flipper_http_alloc();
+    if (!fhttp)
+    {
+        FURI_LOG_E(TAG, "Failed to allocate FlipperHTTP");
+        return;
+    }
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipStoreApp is NULL");
+        return;
+    }
+    bool http_request()
+    {
+        github_success = flip_store_fetch_github(fhttp);
+        return github_success;
+    }
+    bool http_parse()
+    {
+        github_success = flip_store_parse_github(fhttp);
+        return github_success;
+    }
+    flipper_http_loading_task(fhttp, http_request, http_parse, FlipStoreViewSubmenuOptions, FlipStoreViewWidgetResult, &app->view_dispatcher);
+    flipper_http_free(fhttp);
+    if (github_success)
+    {
+        easy_flipper_dialog("Success", "Repository downloaded\nsuccessfully.");
+    }
+    else
+    {
+        easy_flipper_dialog("Failure", "Failed to download\nrepository.");
+    }
 }
 static void flip_store_text_updated_repo(void *context)
 {
@@ -468,7 +490,7 @@ static void flip_store_text_updated_repo(void *context)
     // save the setting
     save_char("Github-Repo", app->uart_text_input_buffer);
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSubmenuOptions);
-    flip_store_github_switch_to_view(app);
+    flip_store_get_github_repository(app);
 }
 static void free_category_submenu(FlipStoreApp *app)
 {

+ 4 - 2
github/flip_store_github.c

@@ -288,6 +288,7 @@ bool flip_store_install_all_github_files(FlipperHTTP *fhttp, const char *author,
         FURI_LOG_E(TAG, "Invalid arguments.");
         return false;
     }
+    fhttp->state = RECEIVING;
     // get the file count
     char file_count_dir[256]; // /ext/apps_data/flip_store/data/author/file_count.txt
     snprintf(file_count_dir, sizeof(file_count_dir), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/data/%s/file_count.txt", author);
@@ -339,8 +340,8 @@ bool flip_store_install_all_github_files(FlipperHTTP *fhttp, const char *author,
         bool parse()
         {
             // remove .txt from the filename
-            char current_file_path[256];
-            char new_file_path[256];
+            char current_file_path[512];
+            char new_file_path[512];
             snprintf(current_file_path, sizeof(current_file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/%s/%s/%s.txt", author, repo, furi_string_get_cstr(name));
             snprintf(new_file_path, sizeof(new_file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/%s/%s/%s", author, repo, furi_string_get_cstr(name));
             Storage *storage = furi_record_open(RECORD_STORAGE);
@@ -372,5 +373,6 @@ bool flip_store_install_all_github_files(FlipperHTTP *fhttp, const char *author,
         furi_string_free(name);
         furi_string_free(link);
     }
+    fhttp->state = IDLE;
     return true;
 }