mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
[FL-2837][FL-3270] Loader refaptoring: second encounter (#2779)
* Core: rename internal FlipperApplication to FlipperInternalApplication * FAP Loader: move load_name_and_icon to flipper_application library * Loader menu: rework api * View holder: move to gui service * Loader: simple "loading" worker * Loader: applications dialog * Loader: fapping * Update f18 api * Apps: remove fap_loader * Libs, flipper application: store args, rename thread allocation * Loader: error handling * Apps: use loader error handling * Loader: documentation * FBT: accomodate loader * Loader: do not raise gui error if loader is locked * Archive: accomodate loader * Loader: fix loading message * Flipper: drop some old dolphin legacy * Loader: generalize error construction Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "elf/elf_file.h"
|
||||
#include <notification/notification_messages.h>
|
||||
#include "application_assets.h"
|
||||
#include <loader/firmware_api/firmware_api.h>
|
||||
|
||||
#include <m-list.h>
|
||||
|
||||
@@ -81,6 +82,12 @@ void flipper_application_free(FlipperApplication* app) {
|
||||
}
|
||||
|
||||
elf_file_free(app->elf);
|
||||
|
||||
if(app->ep_thread_args) {
|
||||
free(app->ep_thread_args);
|
||||
app->ep_thread_args = NULL;
|
||||
}
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
@@ -224,10 +231,19 @@ static int32_t flipper_application_thread(void* context) {
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
FuriThread* flipper_application_spawn(FlipperApplication* app, void* args) {
|
||||
FuriThread* flipper_application_alloc_thread(FlipperApplication* app, const char* args) {
|
||||
furi_check(app->thread == NULL);
|
||||
furi_check(!flipper_application_is_plugin(app));
|
||||
app->ep_thread_args = args;
|
||||
|
||||
if(app->ep_thread_args) {
|
||||
free(app->ep_thread_args);
|
||||
}
|
||||
|
||||
if(args) {
|
||||
app->ep_thread_args = strdup(args);
|
||||
} else {
|
||||
app->ep_thread_args = NULL;
|
||||
}
|
||||
|
||||
const FlipperApplicationManifest* manifest = flipper_application_get_manifest(app);
|
||||
app->thread = furi_thread_alloc_ex(
|
||||
@@ -289,4 +305,32 @@ const FlipperAppPluginDescriptor*
|
||||
lib_descriptor->ep_api_version);
|
||||
|
||||
return lib_descriptor;
|
||||
}
|
||||
|
||||
bool flipper_application_load_name_and_icon(
|
||||
FuriString* path,
|
||||
Storage* storage,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name) {
|
||||
FlipperApplication* app = flipper_application_alloc(storage, firmware_api_interface);
|
||||
|
||||
FlipperApplicationPreloadStatus preload_res =
|
||||
flipper_application_preload_manifest(app, furi_string_get_cstr(path));
|
||||
|
||||
bool load_success = false;
|
||||
|
||||
if(preload_res == FlipperApplicationPreloadStatusSuccess) {
|
||||
const FlipperApplicationManifest* manifest = flipper_application_get_manifest(app);
|
||||
if(manifest->has_icon) {
|
||||
memcpy(*icon_ptr, manifest->icon, FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
}
|
||||
furi_string_set(item_name, manifest->name);
|
||||
load_success = true;
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Failed to preload %s", furi_string_get_cstr(path));
|
||||
load_success = false;
|
||||
}
|
||||
|
||||
flipper_application_free(app);
|
||||
return load_success;
|
||||
}
|
||||
@@ -106,14 +106,14 @@ const FlipperApplicationManifest* flipper_application_get_manifest(FlipperApplic
|
||||
FlipperApplicationLoadStatus flipper_application_map_to_memory(FlipperApplication* app);
|
||||
|
||||
/**
|
||||
* @brief Create application thread at entry point address, using app name and
|
||||
* @brief Allocate application thread at entry point address, using app name and
|
||||
* stack size from metadata. Returned thread isn't started yet.
|
||||
* Can be only called once for application instance.
|
||||
* @param app Applicaiton pointer
|
||||
* @param args Object to pass to app's entry point
|
||||
* @param args Args to pass to app's entry point
|
||||
* @return Created thread
|
||||
*/
|
||||
FuriThread* flipper_application_spawn(FlipperApplication* app, void* args);
|
||||
FuriThread* flipper_application_alloc_thread(FlipperApplication* app, const char* args);
|
||||
|
||||
/**
|
||||
* @brief Check if application is a plugin (not a runnable standalone app)
|
||||
@@ -149,6 +149,21 @@ typedef const FlipperAppPluginDescriptor* (*FlipperApplicationPluginEntryPoint)(
|
||||
const FlipperAppPluginDescriptor*
|
||||
flipper_application_plugin_get_descriptor(FlipperApplication* app);
|
||||
|
||||
/**
|
||||
* @brief Load name and icon from FAP file.
|
||||
*
|
||||
* @param path Path to FAP file.
|
||||
* @param storage Storage instance.
|
||||
* @param icon_ptr Icon pointer.
|
||||
* @param item_name Application name.
|
||||
* @return true if icon and name were loaded successfully.
|
||||
*/
|
||||
bool flipper_application_load_name_and_icon(
|
||||
FuriString* path,
|
||||
Storage* storage,
|
||||
uint8_t** icon_ptr,
|
||||
FuriString* item_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user