Loader: forget menu position on main menu reentry, proper NULL arg passing. Gui: set current item for menu gui module. (#729)

This commit is contained in:
あく 2021-09-29 07:18:28 +03:00 committed by GitHub
parent 0126b3aba4
commit 8b6c466058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -204,7 +204,7 @@ CFLAGS += -DSRV_LOADER
SRV_GUI = 1 SRV_GUI = 1
# Loader autostart hook # Loader autostart hook
LOADER_AUTOSTART ?= "" LOADER_AUTOSTART ?= ""
ifneq ($(strip $(LOADER_AUTOSTART)),) ifneq ($(strip $(LOADER_AUTOSTART)), "")
CFLAGS += -DLOADER_AUTOSTART="\"$(LOADER_AUTOSTART)\"" CFLAGS += -DLOADER_AUTOSTART="\"$(LOADER_AUTOSTART)\""
endif endif
# Loader autostart hook END # Loader autostart hook END

View File

@ -160,6 +160,18 @@ void menu_clean(Menu* menu) {
}); });
} }
void menu_set_selected_item(Menu* menu, uint32_t index) {
with_view_model(
menu->view, (MenuModel * model) {
if(index >= MenuItemArray_size(model->items)) {
return false;
}
model->position = index;
return true;
});
}
static void menu_process_up(Menu* menu) { static void menu_process_up(Menu* menu) {
with_view_model( with_view_model(
menu->view, (MenuModel * model) { menu->view, (MenuModel * model) {

View File

@ -47,6 +47,12 @@ void menu_add_item(
*/ */
void menu_clean(Menu* menu); void menu_clean(Menu* menu);
/** Set current menu item
* @param submenu
* @param index
*/
void menu_set_selected_item(Menu* menu, uint32_t index);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -90,9 +90,11 @@ bool loader_start(Loader* instance, const char* name, const char* args) {
} }
instance->current_app = flipper_app; instance->current_app = flipper_app;
void* thread_args = NULL;
if(args) { if(args) {
string_set_str(instance->args, args); string_set_str(instance->args, args);
string_strim(instance->args); string_strim(instance->args);
thread_args = (void*)string_get_cstr(instance->args);
FURI_LOG_I(LOADER_LOG_TAG, "Start %s app with args: %s", name, args); FURI_LOG_I(LOADER_LOG_TAG, "Start %s app with args: %s", name, args);
} else { } else {
string_clean(instance->args); string_clean(instance->args);
@ -101,7 +103,7 @@ bool loader_start(Loader* instance, const char* name, const char* args) {
furi_thread_set_name(instance->thread, flipper_app->name); furi_thread_set_name(instance->thread, flipper_app->name);
furi_thread_set_stack_size(instance->thread, flipper_app->stack_size); furi_thread_set_stack_size(instance->thread, flipper_app->stack_size);
furi_thread_set_context(instance->thread, (void*)string_get_cstr(instance->args)); furi_thread_set_context(instance->thread, thread_args);
furi_thread_set_callback(instance->thread, flipper_app->app); furi_thread_set_callback(instance->thread, flipper_app->app);
return furi_thread_start(instance->thread); return furi_thread_start(instance->thread);
@ -352,6 +354,7 @@ int32_t loader_srv(void* p) {
while(1) { while(1) {
uint32_t flags = osThreadFlagsWait(LOADER_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever); uint32_t flags = osThreadFlagsWait(LOADER_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
if(flags & LOADER_THREAD_FLAG_SHOW_MENU) { if(flags & LOADER_THREAD_FLAG_SHOW_MENU) {
menu_set_selected_item(loader_instance->primary_menu, 0);
view_dispatcher_switch_to_view( view_dispatcher_switch_to_view(
loader_instance->view_dispatcher, LoaderMenuViewPrimary); loader_instance->view_dispatcher, LoaderMenuViewPrimary);
view_dispatcher_run(loader_instance->view_dispatcher); view_dispatcher_run(loader_instance->view_dispatcher);