Skip to content

Commit

Permalink
FlipStore - v0.7.2
Browse files Browse the repository at this point in the history
- Final memory allocation improvements
  • Loading branch information
jblanked committed Dec 14, 2024
1 parent f444161 commit 376da75
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 333 deletions.
117 changes: 3 additions & 114 deletions alloc/flip_store_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,116 +6,27 @@ FlipStoreApp *flip_store_app_alloc()

Gui *gui = furi_record_open(RECORD_GUI);

// Allocate the text input buffer
app->uart_text_input_buffer_size_ssid = 64;
app->uart_text_input_buffer_size_pass = 64;
if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass))
{
return NULL;
}

// Allocate ViewDispatcher
if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
{
return NULL;
}
view_dispatcher_set_custom_event_callback(app->view_dispatcher, flip_store_custom_event_callback);

// Main view
if (!easy_flipper_set_view(&app->view_loader, FlipStoreViewLoader, flip_store_loader_draw_callback, NULL, callback_to_submenu_options, &app->view_dispatcher, app))
{
return NULL;
}
flip_store_loader_init(app->view_loader);
if (!easy_flipper_set_widget(&app->widget_result, FlipStoreViewWidgetResult, "Error, try again.", callback_to_submenu_options, &app->view_dispatcher))
{
return NULL;
}

// Main view
if (!easy_flipper_set_view(&app->view_app_info, FlipStoreViewAppInfo, flip_store_view_draw_callback_app_list, flip_store_input_callback, callback_to_app_list, &app->view_dispatcher, app))
{
return NULL;
}

// Popup
if (!easy_flipper_set_popup(&app->popup, FlipStoreViewPopup, "Failed", 0, 0, "You are not connected to Wifi.\n\nIf you have the FlipperHTTP\nflash installed, then update\nyour WiFi credentials.", 0, 10, popup_callback, callback_to_submenu, &app->view_dispatcher, app))
{
FURI_LOG_E(TAG, "Failed to create popup");
}

// Dialog
if (!easy_flipper_set_dialog_ex(
&app->dialog_delete,
FlipStoreViewAppDelete,
"Delete App",
0,
0,
"Are you sure you want to delete this app?",
0,
10,
"No",
"Yes",
NULL,
dialog_delete_callback,
callback_to_app_list,
&app->view_dispatcher,
app))
{
return NULL;
}

if (!easy_flipper_set_dialog_ex(
&app->dialog_firmware,
FlipStoreViewFirmwareDialog,
"Download Firmware",
0,
0,
"Are you sure you want to\ndownload this firmware?",
0,
10,
"No",
"Yes",
NULL,
dialog_firmware_callback,
callback_to_firmware_list,
&app->view_dispatcher,
app))
{
return NULL;
}

// Text Input
if (!easy_flipper_set_uart_text_input(&app->uart_text_input_ssid, FlipStoreViewTextInputSSID, "Enter SSID", app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid, flip_store_text_updated_ssid, callback_to_submenu, &app->view_dispatcher, app))
{
return NULL;
}
if (!easy_flipper_set_uart_text_input(&app->uart_text_input_pass, FlipStoreViewTextInputPass, "Enter Password", app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass, flip_store_text_updated_pass, callback_to_submenu, &app->view_dispatcher, app))
{
return NULL;
}

// Variable Item List
if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipStoreViewSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
if (!easy_flipper_set_widget(&app->widget_result, FlipStoreViewWidgetResult, "Error, try again.", callback_to_submenu_options, &app->view_dispatcher))
{
return NULL;
}
app->variable_item_ssid = variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
app->variable_item_pass = variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);

// Submenu
if (!easy_flipper_set_submenu(&app->submenu_main, FlipStoreViewSubmenu, "FlipStore v0.7.1", callback_exit_app, &app->view_dispatcher))
if (!easy_flipper_set_submenu(&app->submenu_main, FlipStoreViewSubmenu, VERSION_TAG, callback_exit_app, &app->view_dispatcher))
{
return NULL;
}
Expand Down Expand Up @@ -153,28 +64,6 @@ FlipStoreApp *flip_store_app_alloc()
submenu_add_item(app->submenu_app_list, "Tools", FlipStoreSubmenuIndexAppListTools, callback_submenu_choices, app);
submenu_add_item(app->submenu_app_list, "USB", FlipStoreSubmenuIndexAppListUSB, callback_submenu_choices, app);
//
// dont add any items to the app list submenu of each category yet

// load settings
if (load_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid, app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass))
{
// Update variable items
if (app->variable_item_ssid)
variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
// do not display the password

// Copy items into their temp buffers with safety checks
if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
{
strncpy(app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid - 1);
app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
}
if (app->uart_text_input_buffer_pass && app->uart_text_input_temp_buffer_pass)
{
strncpy(app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass - 1);
app->uart_text_input_temp_buffer_pass[app->uart_text_input_buffer_size_pass - 1] = '\0';
}
}

// Switch to the main view
view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSubmenu);
Expand Down
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ App(
fap_description="Download apps via WiFi directly to your Flipper Zero",
fap_author="JBlanked",
fap_weburl="https://github.com/jblanked/FlipStore",
fap_version="0.7.1",
fap_version="0.7.2",
)
37 changes: 3 additions & 34 deletions apps/flip_store_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,16 @@ char *categories[] = {

FlipStoreAppInfo *flip_catalog_alloc()
{
FlipStoreAppInfo *app_catalog = (FlipStoreAppInfo *)malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
FlipStoreAppInfo *app_catalog = malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
if (!app_catalog)
{
FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
return NULL;
}
for (int i = 0; i < MAX_APP_COUNT; i++)
{
app_catalog[i].app_name = (char *)malloc(MAX_APP_NAME_LENGTH * sizeof(char));
if (!app_catalog[i].app_name)
{
FURI_LOG_E(TAG, "Failed to allocate memory for app_name.");
return NULL;
}
app_catalog[i].app_id = (char *)malloc(MAX_APP_NAME_LENGTH * sizeof(char));
if (!app_catalog[i].app_id)
{
FURI_LOG_E(TAG, "Failed to allocate memory for app_id.");
return NULL;
}
app_catalog[i].app_build_id = (char *)malloc(MAX_ID_LENGTH * sizeof(char));
if (!app_catalog[i].app_build_id)
{
FURI_LOG_E(TAG, "Failed to allocate memory for app_build_id.");
return NULL;
}
app_catalog[i].app_version = (char *)malloc(MAX_APP_VERSION_LENGTH * sizeof(char));
if (!app_catalog[i].app_version)
{
FURI_LOG_E(TAG, "Failed to allocate memory for app_version.");
return NULL;
}
app_catalog[i].app_description = (char *)malloc(MAX_APP_DESCRIPTION_LENGTH * sizeof(char));
if (!app_catalog[i].app_description)
{
FURI_LOG_E(TAG, "Failed to allocate memory for app_description.");
return NULL;
}
}
// No need for a loop since all memory is allocated in one block
return app_catalog;
}

void flip_catalog_free()
{
if (flip_catalog)
Expand Down
10 changes: 5 additions & 5 deletions apps/flip_store_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ extern char *categories[];

typedef struct
{
char *app_name;
char *app_id;
char *app_build_id;
char *app_version;
char *app_description;
char app_name[MAX_APP_NAME_LENGTH];
char app_id[MAX_APP_NAME_LENGTH];
char app_build_id[MAX_ID_LENGTH];
char app_version[MAX_APP_VERSION_LENGTH];
char app_description[MAX_APP_DESCRIPTION_LENGTH];
} FlipStoreAppInfo;

extern FlipStoreAppInfo *flip_catalog;
Expand Down
3 changes: 3 additions & 0 deletions assets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.7.2
- Final memory allocation improvements

## v0.7.1
- Improved memory allocation
- Fixed a crash when re-entering the same app list
Expand Down
Loading

0 comments on commit 376da75

Please sign in to comment.