2023-05-04 03:48:13 +00:00
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <gui/view_dispatcher.h>
|
|
|
|
#include <gui/modules/menu.h>
|
|
|
|
#include <gui/modules/submenu.h>
|
|
|
|
#include <assets_icons.h>
|
|
|
|
#include <applications.h>
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
#include "loader.h"
|
2023-05-04 03:48:13 +00:00
|
|
|
#include "loader_menu.h"
|
|
|
|
|
|
|
|
#define TAG "LoaderMenu"
|
|
|
|
|
|
|
|
struct LoaderMenu {
|
|
|
|
FuriThread* thread;
|
2023-06-23 12:01:40 +00:00
|
|
|
void (*closed_cb)(void*);
|
|
|
|
void* context;
|
2023-05-04 03:48:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int32_t loader_menu_thread(void* p);
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
LoaderMenu* loader_menu_alloc(void (*closed_cb)(void*), void* context) {
|
2023-05-04 03:48:13 +00:00
|
|
|
LoaderMenu* loader_menu = malloc(sizeof(LoaderMenu));
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu->closed_cb = closed_cb;
|
|
|
|
loader_menu->context = context;
|
2023-05-04 03:48:13 +00:00
|
|
|
loader_menu->thread = furi_thread_alloc_ex(TAG, 1024, loader_menu_thread, loader_menu);
|
|
|
|
furi_thread_start(loader_menu->thread);
|
2023-06-23 12:01:40 +00:00
|
|
|
return loader_menu;
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
void loader_menu_free(LoaderMenu* loader_menu) {
|
2023-05-04 03:48:13 +00:00
|
|
|
furi_assert(loader_menu);
|
|
|
|
furi_thread_join(loader_menu->thread);
|
|
|
|
furi_thread_free(loader_menu->thread);
|
2023-06-23 12:01:40 +00:00
|
|
|
free(loader_menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
typedef enum {
|
|
|
|
LoaderMenuViewPrimary,
|
|
|
|
LoaderMenuViewSettings,
|
|
|
|
} LoaderMenuView;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Gui* gui;
|
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
|
Menu* primary_menu;
|
|
|
|
Submenu* settings_menu;
|
|
|
|
} LoaderMenuApp;
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static void loader_menu_start(const char* name) {
|
|
|
|
Loader* loader = furi_record_open(RECORD_LOADER);
|
|
|
|
loader_start_with_gui_error(loader, name, NULL);
|
|
|
|
furi_record_close(RECORD_LOADER);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-10 08:03:41 +00:00
|
|
|
static void loader_menu_apps_callback(void* context, uint32_t index) {
|
2023-06-23 12:01:40 +00:00
|
|
|
UNUSED(context);
|
2023-05-04 03:48:13 +00:00
|
|
|
const char* name = FLIPPER_APPS[index].name;
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu_start(name);
|
|
|
|
}
|
|
|
|
|
2023-07-10 08:03:41 +00:00
|
|
|
static void loader_menu_external_apps_callback(void* context, uint32_t index) {
|
|
|
|
UNUSED(context);
|
2023-07-13 12:02:59 +00:00
|
|
|
const char* path = FLIPPER_EXTERNAL_APPS[index].name;
|
2023-07-10 08:03:41 +00:00
|
|
|
loader_menu_start(path);
|
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static void loader_menu_applications_callback(void* context, uint32_t index) {
|
|
|
|
UNUSED(index);
|
|
|
|
UNUSED(context);
|
|
|
|
const char* name = LOADER_APPLICATIONS_NAME;
|
|
|
|
loader_menu_start(name);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void loader_menu_settings_menu_callback(void* context, uint32_t index) {
|
2023-06-23 12:01:40 +00:00
|
|
|
UNUSED(context);
|
2023-05-04 03:48:13 +00:00
|
|
|
const char* name = FLIPPER_SETTINGS_APPS[index].name;
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu_start(name);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void loader_menu_switch_to_settings(void* context, uint32_t index) {
|
|
|
|
UNUSED(index);
|
2023-06-23 12:01:40 +00:00
|
|
|
LoaderMenuApp* app = context;
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, LoaderMenuViewSettings);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t loader_menu_switch_to_primary(void* context) {
|
|
|
|
UNUSED(context);
|
|
|
|
return LoaderMenuViewPrimary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t loader_menu_exit(void* context) {
|
|
|
|
UNUSED(context);
|
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static void loader_menu_build_menu(LoaderMenuApp* app, LoaderMenu* menu) {
|
2023-05-04 03:48:13 +00:00
|
|
|
size_t i;
|
2023-07-10 08:03:41 +00:00
|
|
|
|
|
|
|
for(i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT; i++) {
|
|
|
|
menu_add_item(
|
|
|
|
app->primary_menu,
|
|
|
|
FLIPPER_EXTERNAL_APPS[i].name,
|
|
|
|
FLIPPER_EXTERNAL_APPS[i].icon,
|
|
|
|
i,
|
|
|
|
loader_menu_external_apps_callback,
|
|
|
|
(void*)menu);
|
|
|
|
}
|
|
|
|
|
2023-05-04 03:48:13 +00:00
|
|
|
for(i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
|
|
|
menu_add_item(
|
2023-06-23 12:01:40 +00:00
|
|
|
app->primary_menu,
|
2023-05-04 03:48:13 +00:00
|
|
|
FLIPPER_APPS[i].name,
|
|
|
|
FLIPPER_APPS[i].icon,
|
|
|
|
i,
|
2023-07-10 08:03:41 +00:00
|
|
|
loader_menu_apps_callback,
|
2023-06-23 12:01:40 +00:00
|
|
|
(void*)menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
menu_add_item(
|
2023-06-23 12:01:40 +00:00
|
|
|
app->primary_menu, "Settings", &A_Settings_14, i++, loader_menu_switch_to_settings, app);
|
|
|
|
menu_add_item(
|
|
|
|
app->primary_menu,
|
|
|
|
LOADER_APPLICATIONS_NAME,
|
|
|
|
&A_Plugins_14,
|
2023-05-04 03:48:13 +00:00
|
|
|
i++,
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu_applications_callback,
|
|
|
|
(void*)menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
};
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static void loader_menu_build_submenu(LoaderMenuApp* app, LoaderMenu* loader_menu) {
|
2023-05-04 03:48:13 +00:00
|
|
|
for(size_t i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) {
|
|
|
|
submenu_add_item(
|
2023-06-23 12:01:40 +00:00
|
|
|
app->settings_menu,
|
2023-05-04 03:48:13 +00:00
|
|
|
FLIPPER_SETTINGS_APPS[i].name,
|
|
|
|
i,
|
|
|
|
loader_menu_settings_menu_callback,
|
|
|
|
loader_menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static LoaderMenuApp* loader_menu_app_alloc(LoaderMenu* loader_menu) {
|
|
|
|
LoaderMenuApp* app = malloc(sizeof(LoaderMenuApp));
|
|
|
|
app->gui = furi_record_open(RECORD_GUI);
|
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
app->primary_menu = menu_alloc();
|
|
|
|
app->settings_menu = submenu_alloc();
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu_build_menu(app, loader_menu);
|
|
|
|
loader_menu_build_submenu(app, loader_menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
|
|
|
|
// Primary menu
|
2023-06-23 12:01:40 +00:00
|
|
|
View* primary_view = menu_get_view(app->primary_menu);
|
|
|
|
view_set_context(primary_view, app->primary_menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
view_set_previous_callback(primary_view, loader_menu_exit);
|
2023-06-23 12:01:40 +00:00
|
|
|
view_dispatcher_add_view(app->view_dispatcher, LoaderMenuViewPrimary, primary_view);
|
2023-05-04 03:48:13 +00:00
|
|
|
|
|
|
|
// Settings menu
|
2023-06-23 12:01:40 +00:00
|
|
|
View* settings_view = submenu_get_view(app->settings_menu);
|
|
|
|
view_set_context(settings_view, app->settings_menu);
|
2023-05-04 03:48:13 +00:00
|
|
|
view_set_previous_callback(settings_view, loader_menu_switch_to_primary);
|
2023-06-23 12:01:40 +00:00
|
|
|
view_dispatcher_add_view(app->view_dispatcher, LoaderMenuViewSettings, settings_view);
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, LoaderMenuViewPrimary);
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loader_menu_app_free(LoaderMenuApp* app) {
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, LoaderMenuViewPrimary);
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, LoaderMenuViewSettings);
|
|
|
|
view_dispatcher_free(app->view_dispatcher);
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
menu_free(app->primary_menu);
|
|
|
|
submenu_free(app->settings_menu);
|
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
|
free(app);
|
|
|
|
}
|
2023-05-04 03:48:13 +00:00
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
static int32_t loader_menu_thread(void* p) {
|
|
|
|
LoaderMenu* loader_menu = p;
|
|
|
|
furi_assert(loader_menu);
|
|
|
|
|
|
|
|
LoaderMenuApp* app = loader_menu_app_alloc(loader_menu);
|
|
|
|
|
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
|
|
view_dispatcher_run(app->view_dispatcher);
|
|
|
|
|
|
|
|
if(loader_menu->closed_cb) {
|
|
|
|
loader_menu->closed_cb(loader_menu->context);
|
2023-05-04 03:48:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 12:01:40 +00:00
|
|
|
loader_menu_app_free(app);
|
|
|
|
|
2023-05-04 03:48:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|