|
|
@@ -16,18 +16,20 @@ static uint32_t callback_to_app_category_list(void *context);
|
|
|
|
|
|
static bool flip_store_dl_app_fetch(DataLoaderModel *model)
|
|
|
{
|
|
|
- UNUSED(model);
|
|
|
- return flip_store_install_app(categories[flip_store_category_index]);
|
|
|
+ if (!model->fhttp)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "FlipperHTTP is NULL");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return flip_store_install_app(model->fhttp, categories[flip_store_category_index]);
|
|
|
}
|
|
|
static char *flip_store_dl_app_parse(DataLoaderModel *model)
|
|
|
{
|
|
|
- UNUSED(model);
|
|
|
- if (fhttp.state != IDLE)
|
|
|
+ if (!model->fhttp || model->fhttp->state != IDLE)
|
|
|
{
|
|
|
- return NULL;
|
|
|
+ FURI_LOG_E(TAG, "FlipperHTTP is NULL or not IDLE");
|
|
|
+ return "Failed to install app.";
|
|
|
}
|
|
|
- // free the resources
|
|
|
- flipper_http_deinit();
|
|
|
return "App installed successfully.";
|
|
|
}
|
|
|
static void flip_store_dl_app_switch_to_view(FlipStoreApp *app)
|
|
|
@@ -37,42 +39,36 @@ static void flip_store_dl_app_switch_to_view(FlipStoreApp *app)
|
|
|
//
|
|
|
static bool flip_store_fetch_app_list(DataLoaderModel *model)
|
|
|
{
|
|
|
- UNUSED(model);
|
|
|
- if (!app_instance)
|
|
|
+ if (!model->fhttp)
|
|
|
{
|
|
|
- FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
+ FURI_LOG_E(TAG, "FlipperHTTP is NULL");
|
|
|
return false;
|
|
|
}
|
|
|
- // initialize the http
|
|
|
- if (!flipper_http_init(flipper_http_rx_callback, app_instance))
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP.");
|
|
|
- return false;
|
|
|
- }
|
|
|
- fhttp.state = IDLE;
|
|
|
+ model->fhttp->state = IDLE;
|
|
|
flip_catalog_free();
|
|
|
snprintf(
|
|
|
- fhttp.file_path,
|
|
|
- sizeof(fhttp.file_path),
|
|
|
+ model->fhttp->file_path,
|
|
|
+ sizeof(model->fhttp->file_path),
|
|
|
STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/%s.json", categories[flip_store_category_index]);
|
|
|
- fhttp.save_received_data = true;
|
|
|
- fhttp.is_bytes_request = false;
|
|
|
+ model->fhttp->save_received_data = true;
|
|
|
+ model->fhttp->is_bytes_request = false;
|
|
|
char url[128];
|
|
|
snprintf(url, sizeof(url), "https://www.flipsocial.net/api/flipper/apps/%s/max/", categories[flip_store_category_index]);
|
|
|
- return flipper_http_get_request_with_headers(url, "{\"Content-Type\":\"application/json\"}");
|
|
|
+ return flipper_http_get_request_with_headers(model->fhttp, url, "{\"Content-Type\":\"application/json\"}");
|
|
|
}
|
|
|
-static bool set_appropriate_list(Submenu **submenu)
|
|
|
+static bool set_appropriate_list(FlipperHTTP *fhttp, Submenu **submenu, FlipStoreApp *app)
|
|
|
{
|
|
|
- if (!submenu)
|
|
|
+ if (!submenu || !fhttp || !app)
|
|
|
{
|
|
|
- FURI_LOG_E(TAG, "Submenu is NULL");
|
|
|
+ FURI_LOG_E(TAG, "Submenu, FlipperHTTP, or app is NULL");
|
|
|
return false;
|
|
|
}
|
|
|
- if (!easy_flipper_set_submenu(submenu, FlipStoreViewAppListCategory, categories[flip_store_category_index], callback_to_app_list, &app_instance->view_dispatcher))
|
|
|
+
|
|
|
+ if (!easy_flipper_set_submenu(submenu, FlipStoreViewAppListCategory, categories[flip_store_category_index], callback_to_app_list, &app->view_dispatcher))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
- if (flip_store_process_app_list() && submenu && flip_catalog)
|
|
|
+ if (flip_store_process_app_list(fhttp) && submenu && flip_catalog)
|
|
|
{
|
|
|
submenu_reset(*submenu);
|
|
|
// add each app name to submenu
|
|
|
@@ -80,14 +76,14 @@ static bool set_appropriate_list(Submenu **submenu)
|
|
|
{
|
|
|
if (strlen(flip_catalog[i].app_name) > 0)
|
|
|
{
|
|
|
- submenu_add_item(*submenu, flip_catalog[i].app_name, FlipStoreSubmenuIndexStartAppList + i, callback_submenu_choices, app_instance);
|
|
|
+ submenu_add_item(*submenu, flip_catalog[i].app_name, FlipStoreSubmenuIndexStartAppList + i, callback_submenu_choices, app);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipStoreViewAppListCategory);
|
|
|
+ view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppListCategory);
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
@@ -99,13 +95,12 @@ static bool set_appropriate_list(Submenu **submenu)
|
|
|
}
|
|
|
static char *flip_store_parse_app_list(DataLoaderModel *model)
|
|
|
{
|
|
|
- UNUSED(model);
|
|
|
- if (!app_instance)
|
|
|
+ if (!model->fhttp)
|
|
|
{
|
|
|
- FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
return "Failed to fetch app list.";
|
|
|
}
|
|
|
- return set_appropriate_list(&app_instance->submenu_app_list_category) ? "App list fetched successfully." : "Failed to fetch app list.";
|
|
|
+ FlipStoreApp *app = (FlipStoreApp *)model->parser_context;
|
|
|
+ return set_appropriate_list(model->fhttp, &app->submenu_app_list_category, app) ? "App list fetched successfully." : "Failed to fetch app list.";
|
|
|
}
|
|
|
static void flip_store_switch_to_app_list(FlipStoreApp *app)
|
|
|
{
|
|
|
@@ -114,18 +109,12 @@ static void flip_store_switch_to_app_list(FlipStoreApp *app)
|
|
|
//
|
|
|
static bool flip_store_fetch_firmware(DataLoaderModel *model)
|
|
|
{
|
|
|
- if (!app_instance)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
- return false;
|
|
|
- }
|
|
|
- // initialize the http
|
|
|
- if (!flipper_http_init(flipper_http_rx_callback, app_instance))
|
|
|
+ if (!model->fhttp)
|
|
|
{
|
|
|
- FURI_LOG_E(TAG, "Failed to initialize FlipperHTTP.");
|
|
|
+ FURI_LOG_E(TAG, "FlipperHTTP is NULL");
|
|
|
return false;
|
|
|
}
|
|
|
- fhttp.state = IDLE;
|
|
|
+ model->fhttp->state = IDLE;
|
|
|
if (model->request_index == 0)
|
|
|
{
|
|
|
firmware_free();
|
|
|
@@ -135,6 +124,7 @@ static bool flip_store_fetch_firmware(DataLoaderModel *model)
|
|
|
return false;
|
|
|
}
|
|
|
firmware_request_success = flip_store_get_firmware_file(
|
|
|
+ model->fhttp,
|
|
|
firmwares[selected_firmware_index].links[0],
|
|
|
firmwares[selected_firmware_index].name,
|
|
|
strrchr(firmwares[selected_firmware_index].links[0], '/') + 1);
|
|
|
@@ -143,6 +133,7 @@ static bool flip_store_fetch_firmware(DataLoaderModel *model)
|
|
|
else if (model->request_index == 1)
|
|
|
{
|
|
|
firmware_request_success_2 = flip_store_get_firmware_file(
|
|
|
+ model->fhttp,
|
|
|
firmwares[selected_firmware_index].links[1],
|
|
|
firmwares[selected_firmware_index].name,
|
|
|
strrchr(firmwares[selected_firmware_index].links[1], '/') + 1);
|
|
|
@@ -151,6 +142,7 @@ static bool flip_store_fetch_firmware(DataLoaderModel *model)
|
|
|
else if (model->request_index == 2)
|
|
|
{
|
|
|
firmware_request_success_3 = flip_store_get_firmware_file(
|
|
|
+ model->fhttp,
|
|
|
firmwares[selected_firmware_index].links[2],
|
|
|
firmwares[selected_firmware_index].name,
|
|
|
strrchr(firmwares[selected_firmware_index].links[2], '/') + 1);
|
|
|
@@ -160,8 +152,6 @@ static bool flip_store_fetch_firmware(DataLoaderModel *model)
|
|
|
}
|
|
|
static char *flip_store_parse_firmware(DataLoaderModel *model)
|
|
|
{
|
|
|
- // free the resources
|
|
|
- flipper_http_deinit();
|
|
|
if (model->request_index == 0)
|
|
|
{
|
|
|
if (firmware_request_success)
|
|
|
@@ -191,7 +181,7 @@ static void flip_store_switch_to_firmware_list(FlipStoreApp *app)
|
|
|
}
|
|
|
|
|
|
// Function to draw the message on the canvas with word wrapping
|
|
|
-void draw_description(Canvas *canvas, const char *description, int x, int y)
|
|
|
+static void draw_description(Canvas *canvas, const char *description, int x, int y)
|
|
|
{
|
|
|
if (description == NULL || strlen(description) == 0)
|
|
|
{
|
|
|
@@ -251,7 +241,7 @@ void draw_description(Canvas *canvas, const char *description, int x, int y)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void flip_store_view_draw_callback_app_list(Canvas *canvas, void *model)
|
|
|
+static void flip_store_view_draw_callback_app_list(Canvas *canvas, void *model)
|
|
|
{
|
|
|
UNUSED(model);
|
|
|
canvas_clear(canvas);
|
|
|
@@ -277,7 +267,7 @@ void flip_store_view_draw_callback_app_list(Canvas *canvas, void *model)
|
|
|
canvas_draw_str_aligned(canvas, 97, 54, AlignLeft, AlignTop, "Install");
|
|
|
}
|
|
|
|
|
|
-bool flip_store_input_callback(InputEvent *event, void *context)
|
|
|
+static bool flip_store_input_callback(InputEvent *event, void *context)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
@@ -313,7 +303,7 @@ bool flip_store_input_callback(InputEvent *event, void *context)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void flip_store_text_updated_ssid(void *context)
|
|
|
+static void flip_store_text_updated_ssid(void *context)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
@@ -346,16 +336,17 @@ void flip_store_text_updated_ssid(void *context)
|
|
|
save_settings(app->uart_text_input_buffer, pass);
|
|
|
|
|
|
// initialize the http
|
|
|
- if (flipper_http_init(flipper_http_rx_callback, app))
|
|
|
+ FlipperHTTP *fhttp = flipper_http_alloc();
|
|
|
+ if (fhttp)
|
|
|
{
|
|
|
// save the wifi if the device is connected
|
|
|
- if (!flipper_http_save_wifi(app->uart_text_input_buffer, pass))
|
|
|
+ if (!flipper_http_save_wifi(fhttp, app->uart_text_input_buffer, pass))
|
|
|
{
|
|
|
easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
|
|
|
}
|
|
|
|
|
|
// free the resources
|
|
|
- flipper_http_deinit();
|
|
|
+ flipper_http_free(fhttp);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -368,7 +359,7 @@ void flip_store_text_updated_ssid(void *context)
|
|
|
// switch to the settings view
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
|
|
|
}
|
|
|
-void flip_store_text_updated_pass(void *context)
|
|
|
+static void flip_store_text_updated_pass(void *context)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
@@ -402,16 +393,17 @@ void flip_store_text_updated_pass(void *context)
|
|
|
save_settings(ssid, app->uart_text_input_buffer);
|
|
|
|
|
|
// initialize the http
|
|
|
- if (flipper_http_init(flipper_http_rx_callback, app))
|
|
|
+ FlipperHTTP *fhttp = flipper_http_alloc();
|
|
|
+ if (fhttp)
|
|
|
{
|
|
|
// save the wifi if the device is connected
|
|
|
- if (!flipper_http_save_wifi(ssid, app->uart_text_input_buffer))
|
|
|
+ if (!flipper_http_save_wifi(fhttp, ssid, app->uart_text_input_buffer))
|
|
|
{
|
|
|
easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
|
|
|
}
|
|
|
|
|
|
// free the resources
|
|
|
- flipper_http_deinit();
|
|
|
+ flipper_http_free(fhttp);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -477,39 +469,7 @@ static uint32_t callback_to_wifi_settings(void *context)
|
|
|
return FlipStoreViewSettings;
|
|
|
}
|
|
|
|
|
|
-void dialog_delete_callback(DialogExResult result, void *context)
|
|
|
-{
|
|
|
- FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
- if (!app)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (result == DialogExResultLeft) // No
|
|
|
- {
|
|
|
- view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
|
|
|
- }
|
|
|
- else if (result == DialogExResultRight)
|
|
|
- {
|
|
|
- // delete the app then return to the app list
|
|
|
- if (!delete_app(flip_catalog[app_selected_index].app_id, categories[flip_store_category_index]))
|
|
|
- {
|
|
|
- // pop up a message
|
|
|
- easy_flipper_dialog("Error", "Issue deleting app.");
|
|
|
- furi_delay_ms(2000); // delay for 2 seconds
|
|
|
- view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // pop up a message
|
|
|
- easy_flipper_dialog("Success", "App deleted successfully.");
|
|
|
- furi_delay_ms(2000); // delay for 2 seconds
|
|
|
- view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void dialog_firmware_callback(DialogExResult result, void *context)
|
|
|
+static void dialog_firmware_callback(DialogExResult result, void *context)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
@@ -555,18 +515,13 @@ static bool alloc_about_view(FlipStoreApp *app)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static void free_about_view()
|
|
|
+static void free_about_view(FlipStoreApp *app)
|
|
|
{
|
|
|
- if (!app_instance)
|
|
|
+ if (app && app->widget_about != NULL)
|
|
|
{
|
|
|
- FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (app_instance->widget_about != NULL)
|
|
|
- {
|
|
|
- view_dispatcher_remove_view(app_instance->view_dispatcher, FlipStoreViewAbout);
|
|
|
- widget_free(app_instance->widget_about);
|
|
|
- app_instance->widget_about = NULL;
|
|
|
+ view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAbout);
|
|
|
+ widget_free(app->widget_about);
|
|
|
+ app->widget_about = NULL;
|
|
|
}
|
|
|
}
|
|
|
static bool alloc_text_input_view(void *context, char *title)
|
|
|
@@ -632,9 +587,8 @@ static bool alloc_text_input_view(void *context, char *title)
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-static void free_text_input_view(void *context)
|
|
|
+static void free_text_input_view(FlipStoreApp *app)
|
|
|
{
|
|
|
- FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
@@ -657,6 +611,7 @@ static void free_text_input_view(void *context)
|
|
|
app->uart_text_input_temp_buffer = NULL;
|
|
|
}
|
|
|
}
|
|
|
+static void settings_item_selected(void *context, uint32_t index);
|
|
|
static bool alloc_variable_item_list(void *context)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
@@ -695,28 +650,28 @@ static bool alloc_variable_item_list(void *context)
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-static void free_variable_item_list()
|
|
|
+static void free_variable_item_list(FlipStoreApp *app)
|
|
|
{
|
|
|
- if (!app_instance)
|
|
|
+ if (!app)
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
return;
|
|
|
}
|
|
|
- if (app_instance->variable_item_list)
|
|
|
+ if (app->variable_item_list)
|
|
|
{
|
|
|
- view_dispatcher_remove_view(app_instance->view_dispatcher, FlipStoreViewSettings);
|
|
|
- variable_item_list_free(app_instance->variable_item_list);
|
|
|
- app_instance->variable_item_list = NULL;
|
|
|
+ view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSettings);
|
|
|
+ variable_item_list_free(app->variable_item_list);
|
|
|
+ app->variable_item_list = NULL;
|
|
|
}
|
|
|
- if (app_instance->variable_item_ssid)
|
|
|
+ if (app->variable_item_ssid)
|
|
|
{
|
|
|
- free(app_instance->variable_item_ssid);
|
|
|
- app_instance->variable_item_ssid = NULL;
|
|
|
+ free(app->variable_item_ssid);
|
|
|
+ app->variable_item_ssid = NULL;
|
|
|
}
|
|
|
- if (app_instance->variable_item_pass)
|
|
|
+ if (app->variable_item_pass)
|
|
|
{
|
|
|
- free(app_instance->variable_item_pass);
|
|
|
- app_instance->variable_item_pass = NULL;
|
|
|
+ free(app->variable_item_pass);
|
|
|
+ app->variable_item_pass = NULL;
|
|
|
}
|
|
|
}
|
|
|
static bool alloc_dialog_firmware(void *context)
|
|
|
@@ -751,9 +706,8 @@ static bool alloc_dialog_firmware(void *context)
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-static void free_dialog_firmware(void *context)
|
|
|
+static void free_dialog_firmware(FlipStoreApp *app)
|
|
|
{
|
|
|
- FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
@@ -766,9 +720,8 @@ static void free_dialog_firmware(void *context)
|
|
|
app->dialog_firmware = NULL;
|
|
|
}
|
|
|
}
|
|
|
-static bool alloc_app_info_view(void *context)
|
|
|
+static bool alloc_app_info_view(FlipStoreApp *app)
|
|
|
{
|
|
|
- FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
@@ -794,9 +747,8 @@ static bool alloc_app_info_view(void *context)
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-static void free_app_info_view(void *context)
|
|
|
+static void free_app_info_view(FlipStoreApp *app)
|
|
|
{
|
|
|
- FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
@@ -809,28 +761,32 @@ static void free_app_info_view(void *context)
|
|
|
app->view_app_info = NULL;
|
|
|
}
|
|
|
}
|
|
|
-static void free_all_views(bool should_free_variable_item_list)
|
|
|
+static void free_all_views(FlipStoreApp *app, bool should_free_variable_item_list)
|
|
|
{
|
|
|
- free_about_view();
|
|
|
+ if (!app)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "FlipStoreApp is NULL");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ free_about_view(app);
|
|
|
flip_catalog_free();
|
|
|
if (should_free_variable_item_list)
|
|
|
{
|
|
|
- free_variable_item_list();
|
|
|
+ free_variable_item_list(app);
|
|
|
}
|
|
|
- if (app_instance->submenu_app_list_category)
|
|
|
+ if (app->submenu_app_list_category)
|
|
|
{
|
|
|
- view_dispatcher_remove_view(app_instance->view_dispatcher, FlipStoreViewAppListCategory);
|
|
|
- submenu_free(app_instance->submenu_app_list_category);
|
|
|
- app_instance->submenu_app_list_category = NULL;
|
|
|
+ view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListCategory);
|
|
|
+ submenu_free(app->submenu_app_list_category);
|
|
|
+ app->submenu_app_list_category = NULL;
|
|
|
}
|
|
|
- free_text_input_view(app_instance);
|
|
|
- free_dialog_firmware(app_instance);
|
|
|
- free_app_info_view(app_instance);
|
|
|
+ free_text_input_view(app);
|
|
|
+ free_dialog_firmware(app);
|
|
|
+ free_app_info_view(app);
|
|
|
}
|
|
|
uint32_t callback_exit_app(void *context)
|
|
|
{
|
|
|
UNUSED(context);
|
|
|
- free_all_views(true);
|
|
|
return VIEW_NONE; // Return VIEW_NONE to exit the app
|
|
|
}
|
|
|
|
|
|
@@ -846,7 +802,7 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
switch (index)
|
|
|
{
|
|
|
case FlipStoreSubmenuIndexAbout:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
if (!alloc_about_view(app))
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "Failed to set about view");
|
|
|
@@ -855,7 +811,7 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAbout);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexSettings:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
if (!alloc_variable_item_list(app))
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "Failed to allocate variable item list");
|
|
|
@@ -864,7 +820,7 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexOptions:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSubmenuOptions);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppList:
|
|
|
@@ -893,67 +849,67 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewFirmwares);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListBluetooth:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 0;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListGames:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 1;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListGPIO:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 2;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListInfrared:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 3;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListiButton:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 4;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListMedia:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 5;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListNFC:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 6;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListRFID:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 7;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListSubGHz:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 8;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListTools:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 9;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
break;
|
|
|
case FlipStoreSubmenuIndexAppListUSB:
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
flip_store_category_index = 10;
|
|
|
flip_store_app_does_exist = false;
|
|
|
flip_store_switch_to_app_list(app);
|
|
|
@@ -972,7 +928,7 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
selected_firmware_index = firmware_index;
|
|
|
|
|
|
// Switch to the firmware download view
|
|
|
- free_all_views(true);
|
|
|
+ free_all_views(app, true);
|
|
|
if (!alloc_dialog_firmware(app))
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "Failed to allocate dialog firmware");
|
|
|
@@ -1029,7 +985,7 @@ void callback_submenu_choices(void *context, uint32_t index)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void settings_item_selected(void *context, uint32_t index)
|
|
|
+static void settings_item_selected(void *context, uint32_t index)
|
|
|
{
|
|
|
FlipStoreApp *app = (FlipStoreApp *)context;
|
|
|
if (!app)
|
|
|
@@ -1043,7 +999,7 @@ void settings_item_selected(void *context, uint32_t index)
|
|
|
{
|
|
|
case 0: // Input SSID
|
|
|
// Text Input
|
|
|
- free_all_views(false);
|
|
|
+ free_all_views(app, false);
|
|
|
if (!alloc_text_input_view(app, "SSID"))
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "Failed to allocate text input view");
|
|
|
@@ -1058,7 +1014,7 @@ void settings_item_selected(void *context, uint32_t index)
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewTextInput);
|
|
|
break;
|
|
|
case 1: // Input Password
|
|
|
- free_all_views(false);
|
|
|
+ free_all_views(app, false);
|
|
|
if (!alloc_text_input_view(app, "Password"))
|
|
|
{
|
|
|
FURI_LOG_E(TAG, "Failed to allocate text input view");
|
|
|
@@ -1180,6 +1136,50 @@ static void flip_store_widget_set_text(char *message, Widget **widget)
|
|
|
// Add the formatted message to the widget
|
|
|
widget_add_text_scroll_element(*widget, 0, 0, 128, 64, formatted_message);
|
|
|
}
|
|
|
+static void flip_store_request_error(Canvas *canvas, FlipperHTTP *fhttp)
|
|
|
+{
|
|
|
+ if (!canvas)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Canvas is NULL");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!fhttp)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "FlipperHTTP is NULL");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (fhttp->last_response != NULL)
|
|
|
+ {
|
|
|
+ if (strstr(fhttp->last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
|
|
|
+ {
|
|
|
+ canvas_clear(canvas);
|
|
|
+ canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
|
|
|
+ canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
|
|
|
+ canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
|
|
|
+ }
|
|
|
+ else if (strstr(fhttp->last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
|
|
|
+ {
|
|
|
+ canvas_clear(canvas);
|
|
|
+ canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
|
|
|
+ canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
|
|
|
+ canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Received an error: %s", fhttp->last_response);
|
|
|
+ canvas_draw_str(canvas, 0, 42, "Unusual error...");
|
|
|
+ canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
|
|
|
+ canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ canvas_clear(canvas);
|
|
|
+ canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
|
|
|
+ canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
|
|
|
+ canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void flip_store_loader_draw_callback(Canvas *canvas, void *model)
|
|
|
{
|
|
|
@@ -1189,8 +1189,8 @@ void flip_store_loader_draw_callback(Canvas *canvas, void *model)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- SerialState http_state = fhttp.state;
|
|
|
DataLoaderModel *data_loader_model = (DataLoaderModel *)model;
|
|
|
+ SerialState http_state = data_loader_model->fhttp->state;
|
|
|
DataState data_state = data_loader_model->data_state;
|
|
|
char *title = data_loader_model->title;
|
|
|
|
|
|
@@ -1198,7 +1198,7 @@ void flip_store_loader_draw_callback(Canvas *canvas, void *model)
|
|
|
|
|
|
if (http_state == INACTIVE)
|
|
|
{
|
|
|
- canvas_draw_str(canvas, 0, 7, "WiFi Dev Board disconnected.");
|
|
|
+ canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
|
|
|
canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
|
|
|
canvas_draw_str(canvas, 0, 32, "If your board is connected,");
|
|
|
canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
|
|
|
@@ -1209,7 +1209,7 @@ void flip_store_loader_draw_callback(Canvas *canvas, void *model)
|
|
|
|
|
|
if (data_state == DataStateError || data_state == DataStateParseError)
|
|
|
{
|
|
|
- flip_store_request_error(canvas);
|
|
|
+ flip_store_request_error(canvas, data_loader_model->fhttp);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1259,7 +1259,14 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
View *view = app->view_loader;
|
|
|
|
|
|
DataState current_data_state;
|
|
|
- with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; }, false);
|
|
|
+ DataLoaderModel *loader_model = NULL;
|
|
|
+ with_view_model(view, DataLoaderModel * model, { current_data_state = model->data_state; loader_model = model; }, false);
|
|
|
+ if (!loader_model || !loader_model->fhttp)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Model or fhttp is NULL");
|
|
|
+ DEV_CRASH();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if (current_data_state == DataStateInitial)
|
|
|
{
|
|
|
@@ -1277,12 +1284,7 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
}
|
|
|
|
|
|
// Clear any previous responses
|
|
|
- if (fhttp.last_response != NULL)
|
|
|
- {
|
|
|
- free(fhttp.last_response);
|
|
|
- fhttp.last_response = NULL;
|
|
|
- }
|
|
|
- // strncpy(fhttp.last_response, "", 1);
|
|
|
+ strncpy(model->fhttp->last_response, "", 1);
|
|
|
bool request_status = fetch(model);
|
|
|
if (!request_status)
|
|
|
{
|
|
|
@@ -1293,21 +1295,21 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
}
|
|
|
else if (current_data_state == DataStateRequested || current_data_state == DataStateError)
|
|
|
{
|
|
|
- if (fhttp.state == IDLE && fhttp.last_response != NULL)
|
|
|
+ if (loader_model->fhttp->state == IDLE && loader_model->fhttp->last_response != NULL)
|
|
|
{
|
|
|
- if (strstr(fhttp.last_response, "[PONG]") != NULL)
|
|
|
+ if (strstr(loader_model->fhttp->last_response, "[PONG]") != NULL)
|
|
|
{
|
|
|
FURI_LOG_DEV(TAG, "PONG received.");
|
|
|
}
|
|
|
- else if (strncmp(fhttp.last_response, "[SUCCESS]", 9) == 0)
|
|
|
+ else if (strncmp(loader_model->fhttp->last_response, "[SUCCESS]", 9) == 0)
|
|
|
{
|
|
|
- FURI_LOG_DEV(TAG, "SUCCESS received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
|
|
|
+ FURI_LOG_DEV(TAG, "SUCCESS received. %s", loader_model->fhttp->last_response ? loader_model->fhttp->last_response : "NULL");
|
|
|
}
|
|
|
- else if (strncmp(fhttp.last_response, "[ERROR]", 9) == 0)
|
|
|
+ else if (strncmp(loader_model->fhttp->last_response, "[ERROR]", 9) == 0)
|
|
|
{
|
|
|
- FURI_LOG_DEV(TAG, "ERROR received. %s", fhttp.last_response ? fhttp.last_response : "NULL");
|
|
|
+ FURI_LOG_DEV(TAG, "ERROR received. %s", loader_model->fhttp->last_response ? loader_model->fhttp->last_response : "NULL");
|
|
|
}
|
|
|
- else if (strlen(fhttp.last_response) == 0)
|
|
|
+ else if (strlen(loader_model->fhttp->last_response) == 0)
|
|
|
{
|
|
|
// Still waiting on response
|
|
|
}
|
|
|
@@ -1316,21 +1318,21 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateReceived; }, true);
|
|
|
}
|
|
|
}
|
|
|
- else if (fhttp.state == SENDING || fhttp.state == RECEIVING)
|
|
|
+ else if (loader_model->fhttp->state == SENDING || loader_model->fhttp->state == RECEIVING)
|
|
|
{
|
|
|
// continue waiting
|
|
|
}
|
|
|
- else if (fhttp.state == INACTIVE)
|
|
|
+ else if (loader_model->fhttp->state == INACTIVE)
|
|
|
{
|
|
|
// inactive. try again
|
|
|
}
|
|
|
- else if (fhttp.state == ISSUE)
|
|
|
+ else if (loader_model->fhttp->state == ISSUE)
|
|
|
{
|
|
|
with_view_model(view, DataLoaderModel * model, { model->data_state = DataStateError; }, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", fhttp.state, fhttp.last_response ? fhttp.last_response : "NULL");
|
|
|
+ FURI_LOG_DEV(TAG, "Unexpected state: %d lastresp: %s", loader_model->fhttp->state, loader_model->fhttp->last_response ? loader_model->fhttp->last_response : "NULL");
|
|
|
DEV_CRASH();
|
|
|
}
|
|
|
}
|
|
|
@@ -1351,7 +1353,7 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
{
|
|
|
data_text = model->parser(model);
|
|
|
}
|
|
|
- FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", fhttp.last_response ? fhttp.last_response : "NULL", data_text ? data_text : "NULL");
|
|
|
+ FURI_LOG_DEV(TAG, "Parsed data: %s\r\ntext: %s", model->fhttp->last_response ? model->fhttp->last_response : "NULL", data_text ? data_text : "NULL");
|
|
|
model->data_text = data_text;
|
|
|
if (data_text == NULL)
|
|
|
{
|
|
|
@@ -1376,7 +1378,7 @@ static void flip_store_loader_process_callback(void *context)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- flip_store_widget_set_text(model->data_text != NULL ? model->data_text : "Empty result", &app->widget_result);
|
|
|
+ flip_store_widget_set_text(model->data_text != NULL ? model->data_text : "", &app->widget_result);
|
|
|
if (model->data_text != NULL)
|
|
|
{
|
|
|
free(model->data_text);
|
|
|
@@ -1480,8 +1482,14 @@ void flip_store_loader_free_model(View *view)
|
|
|
}
|
|
|
if (model->parser_context)
|
|
|
{
|
|
|
- free(model->parser_context);
|
|
|
- model->parser_context = NULL;
|
|
|
+ // do not free the context here, it is the app context
|
|
|
+ // free(model->parser_context);
|
|
|
+ // model->parser_context = NULL;
|
|
|
+ }
|
|
|
+ if (model->fhttp)
|
|
|
+ {
|
|
|
+ flipper_http_free(model->fhttp);
|
|
|
+ model->fhttp = NULL;
|
|
|
}
|
|
|
},
|
|
|
false);
|
|
|
@@ -1536,6 +1544,12 @@ void flip_store_generic_switch_to_view(FlipStoreApp *app, char *title, DataLoade
|
|
|
model->back_callback = back;
|
|
|
model->data_state = DataStateInitial;
|
|
|
model->data_text = NULL;
|
|
|
+ //
|
|
|
+ model->parser_context = app;
|
|
|
+ if (!model->fhttp)
|
|
|
+ {
|
|
|
+ model->fhttp = flipper_http_alloc();
|
|
|
+ }
|
|
|
},
|
|
|
true);
|
|
|
|