mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 13:28:36 -07:00
Add main apps from mainmenu editor
This commit is contained in:
@@ -3,6 +3,7 @@ ADD_SCENE(xtreme_app, interface, Interface)
|
|||||||
ADD_SCENE(xtreme_app, interface_graphics, InterfaceGraphics)
|
ADD_SCENE(xtreme_app, interface_graphics, InterfaceGraphics)
|
||||||
ADD_SCENE(xtreme_app, interface_mainmenu, InterfaceMainmenu)
|
ADD_SCENE(xtreme_app, interface_mainmenu, InterfaceMainmenu)
|
||||||
ADD_SCENE(xtreme_app, interface_mainmenu_add, InterfaceMainmenuAdd)
|
ADD_SCENE(xtreme_app, interface_mainmenu_add, InterfaceMainmenuAdd)
|
||||||
|
ADD_SCENE(xtreme_app, interface_mainmenu_add_main, InterfaceMainmenuAddMain)
|
||||||
ADD_SCENE(xtreme_app, interface_lockscreen, InterfaceLockscreen)
|
ADD_SCENE(xtreme_app, interface_lockscreen, InterfaceLockscreen)
|
||||||
ADD_SCENE(xtreme_app, interface_statusbar, InterfaceStatusbar)
|
ADD_SCENE(xtreme_app, interface_statusbar, InterfaceStatusbar)
|
||||||
ADD_SCENE(xtreme_app, interface_filebrowser, InterfaceFilebrowser)
|
ADD_SCENE(xtreme_app, interface_filebrowser, InterfaceFilebrowser)
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include "../xtreme_app.h"
|
#include "../xtreme_app.h"
|
||||||
|
|
||||||
enum FileBrowserResult {
|
enum SubmenuIndex {
|
||||||
FileBrowserResultOk,
|
SubmenuIndexMainApp,
|
||||||
|
SubmenuIndexExternalApp,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool xtreme_app_scene_interface_mainmenu_add_file_browser_callback(
|
static bool fap_selector_item_callback(
|
||||||
FuriString* file_path,
|
FuriString* file_path,
|
||||||
void* context,
|
void* context,
|
||||||
uint8_t** icon_ptr,
|
uint8_t** icon_ptr,
|
||||||
@@ -16,52 +17,81 @@ static bool xtreme_app_scene_interface_mainmenu_add_file_browser_callback(
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtreme_app_scene_interface_mainmenu_add_submenu_callback(void* context, uint32_t index) {
|
||||||
|
XtremeApp* app = context;
|
||||||
|
scene_manager_set_scene_state(app->scene_manager, XtremeAppSceneInterfaceMainmenuAdd, index);
|
||||||
|
|
||||||
|
switch(index) {
|
||||||
|
case SubmenuIndexMainApp:
|
||||||
|
scene_manager_next_scene(app->scene_manager, XtremeAppSceneInterfaceMainmenuAddMain);
|
||||||
|
break;
|
||||||
|
case SubmenuIndexExternalApp: {
|
||||||
|
const DialogsFileBrowserOptions browser_options = {
|
||||||
|
.extension = ".fap",
|
||||||
|
.icon = &I_unknown_10px,
|
||||||
|
.skip_assets = true,
|
||||||
|
.hide_ext = true,
|
||||||
|
.item_loader_callback = fap_selector_item_callback,
|
||||||
|
.item_loader_context = app,
|
||||||
|
.base_path = EXT_PATH("apps"),
|
||||||
|
};
|
||||||
|
FuriString* temp_path = furi_string_alloc_set_str(EXT_PATH("apps"));
|
||||||
|
if(dialog_file_browser_show(app->dialogs, temp_path, temp_path, &browser_options)) {
|
||||||
|
CharList_push_back(app->mainmenu_app_exes, strdup(furi_string_get_cstr(temp_path)));
|
||||||
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
|
flipper_application_load_name_and_icon(temp_path, storage, NULL, temp_path);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
CharList_push_back(app->mainmenu_app_labels, strdup(furi_string_get_cstr(temp_path)));
|
||||||
|
app->mainmenu_app_index = CharList_size(app->mainmenu_app_labels) - 1;
|
||||||
|
app->save_mainmenu_apps = true;
|
||||||
|
app->require_reboot = true;
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
app->scene_manager, XtremeAppSceneInterfaceMainmenu);
|
||||||
|
}
|
||||||
|
furi_string_free(temp_path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void xtreme_app_scene_interface_mainmenu_add_on_enter(void* context) {
|
void xtreme_app_scene_interface_mainmenu_add_on_enter(void* context) {
|
||||||
XtremeApp* app = context;
|
XtremeApp* app = context;
|
||||||
FuriString* string = furi_string_alloc_set_str(EXT_PATH("apps"));
|
Submenu* submenu = app->submenu;
|
||||||
|
|
||||||
const DialogsFileBrowserOptions browser_options = {
|
submenu_add_item(
|
||||||
.extension = ".fap",
|
submenu,
|
||||||
.skip_assets = true,
|
"Main App",
|
||||||
.hide_ext = true,
|
SubmenuIndexMainApp,
|
||||||
.item_loader_callback = xtreme_app_scene_interface_mainmenu_add_file_browser_callback,
|
xtreme_app_scene_interface_mainmenu_add_submenu_callback,
|
||||||
.item_loader_context = app,
|
app);
|
||||||
.base_path = EXT_PATH("apps"),
|
|
||||||
};
|
|
||||||
|
|
||||||
if(dialog_file_browser_show(app->dialogs, string, string, &browser_options)) {
|
submenu_add_item(
|
||||||
CharList_push_back(app->mainmenu_app_exes, strdup(furi_string_get_cstr(string)));
|
submenu,
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
"External App",
|
||||||
flipper_application_load_name_and_icon(string, storage, NULL, string);
|
SubmenuIndexExternalApp,
|
||||||
furi_record_close(RECORD_STORAGE);
|
xtreme_app_scene_interface_mainmenu_add_submenu_callback,
|
||||||
CharList_push_back(app->mainmenu_app_labels, strdup(furi_string_get_cstr(string)));
|
app);
|
||||||
app->save_mainmenu_apps = true;
|
|
||||||
app->require_reboot = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
furi_string_free(string);
|
submenu_set_header(submenu, "Add Menu App:");
|
||||||
|
|
||||||
view_dispatcher_send_custom_event(app->view_dispatcher, FileBrowserResultOk);
|
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewSubmenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool xtreme_app_scene_interface_mainmenu_add_on_event(void* context, SceneManagerEvent event) {
|
bool xtreme_app_scene_interface_mainmenu_add_on_event(void* context, SceneManagerEvent event) {
|
||||||
XtremeApp* app = context;
|
UNUSED(context);
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
consumed = true;
|
consumed = true;
|
||||||
switch(event.event) {
|
|
||||||
case FileBrowserResultOk:
|
|
||||||
scene_manager_previous_scene(app->scene_manager);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xtreme_app_scene_interface_mainmenu_add_on_exit(void* context) {
|
void xtreme_app_scene_interface_mainmenu_add_on_exit(void* context) {
|
||||||
UNUSED(context);
|
XtremeApp* app = context;
|
||||||
|
submenu_reset(app->submenu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include "../xtreme_app.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtreme_app_scene_interface_mainmenu_add_main_submenu_callback(void* context, uint32_t index) {
|
||||||
|
XtremeApp* app = context;
|
||||||
|
const char* name = (const char*)index;
|
||||||
|
|
||||||
|
CharList_push_back(app->mainmenu_app_exes, strdup(name));
|
||||||
|
CharList_push_back(app->mainmenu_app_labels, strdup(name));
|
||||||
|
app->mainmenu_app_index = CharList_size(app->mainmenu_app_labels) - 1;
|
||||||
|
app->save_mainmenu_apps = true;
|
||||||
|
app->require_reboot = true;
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
app->scene_manager, XtremeAppSceneInterfaceMainmenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void xtreme_app_scene_interface_mainmenu_add_main_on_enter(void* context) {
|
||||||
|
XtremeApp* app = context;
|
||||||
|
Submenu* submenu = app->submenu;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
FLIPPER_APPS[i].name,
|
||||||
|
(uint32_t)FLIPPER_APPS[i].name,
|
||||||
|
xtreme_app_scene_interface_mainmenu_add_main_submenu_callback,
|
||||||
|
app);
|
||||||
|
}
|
||||||
|
for(size_t i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT; i++) {
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
FLIPPER_EXTERNAL_APPS[i].name,
|
||||||
|
(uint32_t)FLIPPER_EXTERNAL_APPS[i].name,
|
||||||
|
xtreme_app_scene_interface_mainmenu_add_main_submenu_callback,
|
||||||
|
app);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewSubmenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool xtreme_app_scene_interface_mainmenu_add_main_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
UNUSED(context);
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void xtreme_app_scene_interface_mainmenu_add_main_on_exit(void* context) {
|
||||||
|
XtremeApp* app = context;
|
||||||
|
submenu_reset(app->submenu);
|
||||||
|
}
|
||||||
@@ -185,6 +185,10 @@ XtremeApp* xtreme_app_alloc() {
|
|||||||
XtremeAppViewVarItemList,
|
XtremeAppViewVarItemList,
|
||||||
variable_item_list_get_view(app->var_item_list));
|
variable_item_list_get_view(app->var_item_list));
|
||||||
|
|
||||||
|
app->submenu = submenu_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher, XtremeAppViewSubmenu, submenu_get_view(app->submenu));
|
||||||
|
|
||||||
app->text_input = text_input_alloc();
|
app->text_input = text_input_alloc();
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher, XtremeAppViewTextInput, text_input_get_view(app->text_input));
|
app->view_dispatcher, XtremeAppViewTextInput, text_input_get_view(app->text_input));
|
||||||
@@ -299,6 +303,8 @@ void xtreme_app_free(XtremeApp* app) {
|
|||||||
// Gui modules
|
// Gui modules
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewVarItemList);
|
||||||
variable_item_list_free(app->var_item_list);
|
variable_item_list_free(app->var_item_list);
|
||||||
|
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewSubmenu);
|
||||||
|
submenu_free(app->submenu);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput);
|
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput);
|
||||||
text_input_free(app->text_input);
|
text_input_free(app->text_input);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup);
|
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup);
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#include <gui/scene_manager.h>
|
#include <gui/scene_manager.h>
|
||||||
#include <dialogs/dialogs.h>
|
#include <dialogs/dialogs.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
|
#include <applications.h>
|
||||||
#include <gui/modules/variable_item_list.h>
|
#include <gui/modules/variable_item_list.h>
|
||||||
|
#include <gui/modules/submenu.h>
|
||||||
#include <gui/modules/text_input.h>
|
#include <gui/modules/text_input.h>
|
||||||
#include <gui/modules/popup.h>
|
#include <gui/modules/popup.h>
|
||||||
#include <lib/toolbox/value_index.h>
|
#include <lib/toolbox/value_index.h>
|
||||||
@@ -37,6 +39,7 @@ typedef struct {
|
|||||||
SceneManager* scene_manager;
|
SceneManager* scene_manager;
|
||||||
ViewDispatcher* view_dispatcher;
|
ViewDispatcher* view_dispatcher;
|
||||||
VariableItemList* var_item_list;
|
VariableItemList* var_item_list;
|
||||||
|
Submenu* submenu;
|
||||||
TextInput* text_input;
|
TextInput* text_input;
|
||||||
Popup* popup;
|
Popup* popup;
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
XtremeAppViewVarItemList,
|
XtremeAppViewVarItemList,
|
||||||
|
XtremeAppViewSubmenu,
|
||||||
XtremeAppViewTextInput,
|
XtremeAppViewTextInput,
|
||||||
XtremeAppViewPopup,
|
XtremeAppViewPopup,
|
||||||
} XtremeAppView;
|
} XtremeAppView;
|
||||||
|
|||||||
Reference in New Issue
Block a user