mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 11:28:36 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev
This commit is contained in:
@@ -17,6 +17,12 @@ typedef struct {
|
||||
const FlipperInternalApplicationFlag flags;
|
||||
} FlipperInternalApplication;
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
const Icon* icon;
|
||||
const char* path;
|
||||
} FlipperExternalApplication;
|
||||
|
||||
typedef void (*FlipperInternalOnStartHook)(void);
|
||||
|
||||
extern const char* FLIPPER_AUTORUN_APP_NAME;
|
||||
@@ -52,3 +58,9 @@ extern const FlipperInternalApplication FLIPPER_ARCHIVE;
|
||||
*/
|
||||
extern const FlipperInternalApplication FLIPPER_SETTINGS_APPS[];
|
||||
extern const size_t FLIPPER_SETTINGS_APPS_COUNT;
|
||||
|
||||
/* External Menu Apps list
|
||||
* Spawned by loader
|
||||
*/
|
||||
extern const FlipperExternalApplication FLIPPER_EXTERNAL_APPS[];
|
||||
extern const size_t FLIPPER_EXTERNAL_APPS_COUNT;
|
||||
|
||||
@@ -175,24 +175,23 @@ void cli_command_log_tx_callback(const uint8_t* buffer, size_t size, void* conte
|
||||
furi_stream_buffer_send(context, buffer, size, 0);
|
||||
}
|
||||
|
||||
void cli_command_log_level_set_from_string(FuriString* level) {
|
||||
if(furi_string_cmpi_str(level, "default") == 0) {
|
||||
furi_log_set_level(FuriLogLevelDefault);
|
||||
} else if(furi_string_cmpi_str(level, "none") == 0) {
|
||||
furi_log_set_level(FuriLogLevelNone);
|
||||
} else if(furi_string_cmpi_str(level, "error") == 0) {
|
||||
furi_log_set_level(FuriLogLevelError);
|
||||
} else if(furi_string_cmpi_str(level, "warn") == 0) {
|
||||
furi_log_set_level(FuriLogLevelWarn);
|
||||
} else if(furi_string_cmpi_str(level, "info") == 0) {
|
||||
furi_log_set_level(FuriLogLevelInfo);
|
||||
} else if(furi_string_cmpi_str(level, "debug") == 0) {
|
||||
furi_log_set_level(FuriLogLevelDebug);
|
||||
} else if(furi_string_cmpi_str(level, "trace") == 0) {
|
||||
furi_log_set_level(FuriLogLevelTrace);
|
||||
bool cli_command_log_level_set_from_string(FuriString* level) {
|
||||
FuriLogLevel log_level;
|
||||
if(furi_log_level_from_string(furi_string_get_cstr(level), &log_level)) {
|
||||
furi_log_set_level(log_level);
|
||||
return true;
|
||||
} else {
|
||||
printf("Unknown log level\r\n");
|
||||
printf("<log> — start logging using the current level from the system settings\r\n");
|
||||
printf("<log error> — only critical errors and other important messages\r\n");
|
||||
printf("<log warn> — non-critical errors and warnings including <log error>\r\n");
|
||||
printf("<log info> — non-critical information including <log warn>\r\n");
|
||||
printf("<log default> — the default system log level (equivalent to <log info>)\r\n");
|
||||
printf(
|
||||
"<log debug> — debug information including <log info> (may impact system performance)\r\n");
|
||||
printf(
|
||||
"<log trace> — system traces including <log debug> (may impact system performance)\r\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
||||
@@ -203,12 +202,20 @@ void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
||||
bool restore_log_level = false;
|
||||
|
||||
if(furi_string_size(args) > 0) {
|
||||
cli_command_log_level_set_from_string(args);
|
||||
if(!cli_command_log_level_set_from_string(args)) {
|
||||
furi_stream_buffer_free(ring);
|
||||
return;
|
||||
}
|
||||
restore_log_level = true;
|
||||
}
|
||||
|
||||
const char* current_level;
|
||||
furi_log_level_to_string(furi_log_get_level(), ¤t_level);
|
||||
printf("Current log level: %s\r\n", current_level);
|
||||
|
||||
furi_hal_console_set_tx_callback(cli_command_log_tx_callback, ring);
|
||||
|
||||
printf("Use <log ?> to list available log levels\r\n");
|
||||
printf("Press CTRL+C to stop...\r\n");
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
size_t ret = furi_stream_buffer_receive(ring, buffer, CLI_COMMAND_LOG_BUFFER_SIZE, 50);
|
||||
|
||||
@@ -245,6 +245,16 @@ static const FlipperInternalApplication* loader_find_application_by_name(const c
|
||||
return application;
|
||||
}
|
||||
|
||||
static const char* loader_find_external_application_by_name(const char* app_name) {
|
||||
for(size_t i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT; i++) {
|
||||
if(strcmp(FLIPPER_EXTERNAL_APPS[i].name, app_name) == 0) {
|
||||
return FLIPPER_EXTERNAL_APPS[i].path;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void loader_start_app_thread(Loader* loader, FlipperInternalApplicationFlag flags) {
|
||||
// setup heap trace
|
||||
FuriHalRtcHeapTrackMode mode = furi_hal_rtc_get_heap_track_mode();
|
||||
@@ -493,6 +503,14 @@ static LoaderStatus loader_do_start_by_name(
|
||||
break;
|
||||
}
|
||||
|
||||
// check External Applications
|
||||
{
|
||||
const char* path = loader_find_external_application_by_name(name);
|
||||
if(path) {
|
||||
name = path;
|
||||
}
|
||||
}
|
||||
|
||||
// check external apps
|
||||
{
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@@ -38,6 +38,11 @@ typedef struct {
|
||||
FuriString* fap_path;
|
||||
DialogsApp* dialogs;
|
||||
Storage* storage;
|
||||
Loader* loader;
|
||||
|
||||
Gui* gui;
|
||||
ViewHolder* view_holder;
|
||||
Loading* loading;
|
||||
} LoaderApplicationsApp;
|
||||
|
||||
static LoaderApplicationsApp* loader_applications_app_alloc() {
|
||||
@@ -45,15 +50,30 @@ static LoaderApplicationsApp* loader_applications_app_alloc() {
|
||||
app->fap_path = furi_string_alloc_set(EXT_PATH("apps"));
|
||||
app->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
app->storage = furi_record_open(RECORD_STORAGE);
|
||||
app->loader = furi_record_open(RECORD_LOADER);
|
||||
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->view_holder = view_holder_alloc();
|
||||
app->loading = loading_alloc();
|
||||
|
||||
view_holder_attach_to_gui(app->view_holder, app->gui);
|
||||
view_holder_set_view(app->view_holder, loading_get_view(app->loading));
|
||||
|
||||
return app;
|
||||
} //-V773
|
||||
|
||||
static void loader_applications_app_free(LoaderApplicationsApp* loader_applications_app) {
|
||||
furi_assert(loader_applications_app);
|
||||
static void loader_applications_app_free(LoaderApplicationsApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
view_holder_free(app->view_holder);
|
||||
loading_free(app->loading);
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
furi_record_close(RECORD_LOADER);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
furi_string_free(loader_applications_app->fap_path);
|
||||
free(loader_applications_app);
|
||||
furi_string_free(app->fap_path);
|
||||
free(app);
|
||||
}
|
||||
|
||||
static bool loader_applications_item_callback(
|
||||
@@ -96,47 +116,38 @@ static void loader_pubsub_callback(const void* message, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void loader_applications_start_app(const char* name) {
|
||||
// start loading animation
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
ViewHolder* view_holder = view_holder_alloc();
|
||||
Loading* loading = loading_alloc();
|
||||
|
||||
view_holder_attach_to_gui(view_holder, gui);
|
||||
view_holder_set_view(view_holder, loading_get_view(loading));
|
||||
view_holder_start(view_holder);
|
||||
static void loader_applications_start_app(LoaderApplicationsApp* app) {
|
||||
const char* name = furi_string_get_cstr(app->fap_path);
|
||||
|
||||
// load app
|
||||
FuriThreadId thread_id = furi_thread_get_current_id();
|
||||
Loader* loader = furi_record_open(RECORD_LOADER);
|
||||
FuriPubSubSubscription* subscription =
|
||||
furi_pubsub_subscribe(loader_get_pubsub(loader), loader_pubsub_callback, thread_id);
|
||||
furi_pubsub_subscribe(loader_get_pubsub(app->loader), loader_pubsub_callback, thread_id);
|
||||
|
||||
LoaderStatus status = loader_start_with_gui_error(loader, name, NULL);
|
||||
LoaderStatus status = loader_start_with_gui_error(app->loader, name, NULL);
|
||||
|
||||
if(status == LoaderStatusOk) {
|
||||
furi_thread_flags_wait(APPLICATION_STOP_EVENT, FuriFlagWaitAny, FuriWaitForever);
|
||||
}
|
||||
|
||||
furi_pubsub_unsubscribe(loader_get_pubsub(loader), subscription);
|
||||
furi_record_close(RECORD_LOADER);
|
||||
|
||||
// stop loading animation
|
||||
view_holder_stop(view_holder);
|
||||
view_holder_free(view_holder);
|
||||
loading_free(loading);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_pubsub_unsubscribe(loader_get_pubsub(app->loader), subscription);
|
||||
}
|
||||
|
||||
static int32_t loader_applications_thread(void* p) {
|
||||
LoaderApplications* loader_applications = p;
|
||||
LoaderApplicationsApp* loader_applications_app = loader_applications_app_alloc();
|
||||
LoaderApplicationsApp* app = loader_applications_app_alloc();
|
||||
|
||||
while(loader_applications_select_app(loader_applications_app)) {
|
||||
loader_applications_start_app(furi_string_get_cstr(loader_applications_app->fap_path));
|
||||
// start loading animation
|
||||
view_holder_start(app->view_holder);
|
||||
|
||||
while(loader_applications_select_app(app)) {
|
||||
loader_applications_start_app(app);
|
||||
}
|
||||
|
||||
loader_applications_app_free(loader_applications_app);
|
||||
// stop loading animation
|
||||
view_holder_stop(app->view_holder);
|
||||
|
||||
loader_applications_app_free(app);
|
||||
|
||||
if(loader_applications->closed_cb) {
|
||||
loader_applications->closed_cb(loader_applications->context);
|
||||
|
||||
@@ -56,12 +56,18 @@ static void loader_menu_start(const char* name) {
|
||||
furi_record_close(RECORD_LOADER);
|
||||
}
|
||||
|
||||
static void loader_menu_callback(void* context, uint32_t index) {
|
||||
static void loader_menu_apps_callback(void* context, uint32_t index) {
|
||||
UNUSED(context);
|
||||
const char* name_or_path = (const char*)index;
|
||||
loader_menu_start(name_or_path);
|
||||
}
|
||||
|
||||
static void loader_menu_external_apps_callback(void* context, uint32_t index) {
|
||||
UNUSED(context);
|
||||
const char* path = FLIPPER_EXTERNAL_APPS[index].path;
|
||||
loader_menu_start(path);
|
||||
}
|
||||
|
||||
static void loader_menu_applications_callback(void* context, uint32_t index) {
|
||||
UNUSED(index);
|
||||
UNUSED(context);
|
||||
@@ -92,20 +98,14 @@ static uint32_t loader_menu_exit(void* context) {
|
||||
}
|
||||
|
||||
static void loader_menu_build_menu(LoaderMenuApp* app, LoaderMenu* menu) {
|
||||
menu_add_item(
|
||||
app->primary_menu,
|
||||
LOADER_APPLICATIONS_NAME,
|
||||
&A_Plugins_14,
|
||||
0,
|
||||
loader_menu_applications_callback,
|
||||
(void*)menu);
|
||||
for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
||||
size_t i;
|
||||
for(i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
||||
menu_add_item(
|
||||
app->primary_menu,
|
||||
FLIPPER_APPS[i].name,
|
||||
FLIPPER_APPS[i].icon,
|
||||
(uint32_t)FLIPPER_APPS[i].name,
|
||||
loader_menu_callback,
|
||||
i,
|
||||
loader_menu_apps_callback,
|
||||
(void*)menu);
|
||||
}
|
||||
menu_add_item(
|
||||
|
||||
Reference in New Issue
Block a user