mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 13:18:35 -07:00
Main Menu: Unload when opening apps (#161)
* Detached close event * Consistency * Unload main menu when opening apps * Refactor LoaderMenu with ViewHolder * Show loading icon * Remember selected items after reloading menu * Consistency * Similar code structure to ofw * Load/unload custom app list with main menu * Fix momentum app for new mainmenu logic
This commit is contained in:
@@ -18,8 +18,6 @@ bool momentum_app_apply(MomentumApp* app) {
|
||||
Stream* stream = file_stream_alloc(storage);
|
||||
if(file_stream_open(stream, MAINMENU_APPS_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||
stream_write_format(stream, "MenuAppList Version %u\n", 1);
|
||||
CharList_it_t it;
|
||||
CharList_it(it, app->mainmenu_app_exes);
|
||||
for(size_t i = 0; i < CharList_size(app->mainmenu_app_exes); i++) {
|
||||
stream_write_format(stream, "%s\n", *CharList_get(app->mainmenu_app_exes, i));
|
||||
}
|
||||
@@ -161,6 +159,24 @@ static bool momentum_app_back_event_callback(void* context) {
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static void momentum_app_push_mainmenu_app(MomentumApp* app, FuriString* label, FuriString* exe) {
|
||||
CharList_push_back(app->mainmenu_app_exes, strdup(furi_string_get_cstr(exe)));
|
||||
// Display logic mimics applications/services/gui/modules/menu.c
|
||||
if(furi_string_equal(label, "Momentum")) {
|
||||
furi_string_set(label, "MNTM");
|
||||
} else if(furi_string_equal(label, "125 kHz RFID")) {
|
||||
furi_string_set(label, "RFID");
|
||||
} else if(furi_string_equal(label, "Sub-GHz")) {
|
||||
furi_string_set(label, "SubGHz");
|
||||
} else if(furi_string_start_with_str(label, "[")) {
|
||||
size_t trim = furi_string_search_str(label, "] ", 1);
|
||||
if(trim != FURI_STRING_FAILURE) {
|
||||
furi_string_right(label, trim + 2);
|
||||
}
|
||||
}
|
||||
CharList_push_back(app->mainmenu_app_labels, strdup(furi_string_get_cstr(label)));
|
||||
}
|
||||
|
||||
MomentumApp* momentum_app_alloc() {
|
||||
MomentumApp* app = malloc(sizeof(MomentumApp));
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
@@ -242,6 +258,7 @@ MomentumApp* momentum_app_alloc() {
|
||||
|
||||
CharList_init(app->mainmenu_app_labels);
|
||||
CharList_init(app->mainmenu_app_exes);
|
||||
// Loading logic mimics applications/services/loader/loader_menu.c
|
||||
Stream* stream = file_stream_alloc(storage);
|
||||
FuriString* line = furi_string_alloc();
|
||||
FuriString* label = furi_string_alloc();
|
||||
@@ -252,17 +269,15 @@ MomentumApp* momentum_app_alloc() {
|
||||
sscanf(furi_string_get_cstr(line), "MenuAppList Version %lu", &version) == 1 &&
|
||||
version <= 1) {
|
||||
while(stream_read_line(stream, line)) {
|
||||
// Loading logic mimics applications/services/loader/loader.c
|
||||
furi_string_replace_all(line, "\r", "");
|
||||
furi_string_replace_all(line, "\n", "");
|
||||
furi_string_trim(line);
|
||||
if(version == 0) {
|
||||
if(!furi_string_cmp(line, "RFID")) {
|
||||
if(furi_string_equal(line, "RFID")) {
|
||||
furi_string_set(line, "125 kHz RFID");
|
||||
} else if(!furi_string_cmp(line, "SubGHz")) {
|
||||
} else if(furi_string_equal(line, "SubGHz")) {
|
||||
furi_string_set(line, "Sub-GHz");
|
||||
}
|
||||
}
|
||||
if(storage_file_exists(storage, furi_string_get_cstr(line))) {
|
||||
if(furi_string_start_with(line, "/")) {
|
||||
if(!flipper_application_load_name_and_icon(line, storage, &unused_icon, label)) {
|
||||
furi_string_reset(label);
|
||||
}
|
||||
@@ -286,21 +301,19 @@ MomentumApp* momentum_app_alloc() {
|
||||
// Ignore unknown apps just like in main menu, prevents "ghost" apps when saving
|
||||
continue;
|
||||
}
|
||||
CharList_push_back(app->mainmenu_app_exes, strdup(furi_string_get_cstr(line)));
|
||||
// Display logic mimics applications/services/gui/modules/menu.c
|
||||
if(!furi_string_cmp(label, "Momentum")) {
|
||||
furi_string_set(label, "MNTM");
|
||||
} else if(!furi_string_cmp(label, "125 kHz RFID")) {
|
||||
furi_string_set(label, "RFID");
|
||||
} else if(!furi_string_cmp(label, "Sub-GHz")) {
|
||||
furi_string_set(label, "SubGHz");
|
||||
} else if(furi_string_start_with_str(label, "[")) {
|
||||
size_t trim = furi_string_search_str(label, "] ", 1);
|
||||
if(trim != FURI_STRING_FAILURE) {
|
||||
furi_string_right(label, trim + 2);
|
||||
}
|
||||
}
|
||||
CharList_push_back(app->mainmenu_app_labels, strdup(furi_string_get_cstr(label)));
|
||||
momentum_app_push_mainmenu_app(app, label, line);
|
||||
}
|
||||
} else {
|
||||
for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
||||
furi_string_set(label, FLIPPER_APPS[i].name);
|
||||
furi_string_set(line, FLIPPER_APPS[i].name);
|
||||
momentum_app_push_mainmenu_app(app, label, line);
|
||||
}
|
||||
// Until count - 1 because last app is hardcoded below
|
||||
for(size_t i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT - 1; i++) {
|
||||
furi_string_set(label, FLIPPER_EXTERNAL_APPS[i].name);
|
||||
furi_string_set(line, FLIPPER_EXTERNAL_APPS[i].name);
|
||||
momentum_app_push_mainmenu_app(app, label, line);
|
||||
}
|
||||
}
|
||||
free(unused_icon);
|
||||
|
||||
@@ -141,7 +141,6 @@ bool momentum_app_scene_interface_mainmenu_on_event(void* context, SceneManagerE
|
||||
/* fall through */
|
||||
case VarItemListIndexMoveApp: {
|
||||
app->save_mainmenu_apps = true;
|
||||
app->require_reboot = true;
|
||||
size_t count = CharList_size(app->mainmenu_app_labels);
|
||||
VariableItem* item = variable_item_list_get(app->var_item_list, VarItemListIndexApp);
|
||||
if(count) {
|
||||
|
||||
@@ -53,7 +53,6 @@ static void
|
||||
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, MomentumAppSceneInterfaceMainmenu);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ static void
|
||||
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, MomentumAppSceneInterfaceMainmenu);
|
||||
}
|
||||
|
||||
@@ -31,26 +31,9 @@ bool momentum_app_scene_interface_mainmenu_reset_on_event(void* context, SceneMa
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DialogExResultRight:
|
||||
bool reset = false;
|
||||
Stream* stream = file_stream_alloc(furi_record_open(RECORD_STORAGE));
|
||||
if(file_stream_open(stream, MAINMENU_APPS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
||||
stream_write_format(stream, "MenuAppList Version %u\n", 1);
|
||||
for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) {
|
||||
stream_write_format(stream, "%s\n", FLIPPER_APPS[i].name);
|
||||
}
|
||||
for(size_t i = 0; i < FLIPPER_EXTERNAL_APPS_COUNT - 1; i++) {
|
||||
stream_write_format(stream, "%s\n", FLIPPER_EXTERNAL_APPS[i].name);
|
||||
}
|
||||
reset = true;
|
||||
}
|
||||
file_stream_close(stream);
|
||||
stream_free(stream);
|
||||
storage_common_remove(furi_record_open(RECORD_STORAGE), MAINMENU_APPS_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
if(reset) {
|
||||
app->save_mainmenu_apps = false;
|
||||
app->require_reboot = true;
|
||||
momentum_app_apply(app);
|
||||
}
|
||||
app->save_mainmenu_apps = false;
|
||||
break;
|
||||
case DialogExResultLeft:
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
|
||||
Reference in New Issue
Block a user