From e8b5b32660c0b6195e78d3cfad0fe14a8e88b66a Mon Sep 17 00:00:00 2001 From: Yukai Li Date: Sun, 21 May 2023 17:59:52 -0600 Subject: [PATCH 1/5] desktop: Refactor favorites settings and allow app browser in selection --- .../services/desktop/desktop_settings.h | 2 + .../scenes/desktop_settings_scene_favorite.c | 84 ++++++++----------- 2 files changed, 37 insertions(+), 49 deletions(-) diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index 5d1b6126feb..e07bce0cf42 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -37,6 +37,8 @@ #define MAX_APP_LENGTH 128 #define FAP_LOADER_APP_NAME "Applications" +#define FAP_LOADER_APP_DISPLAY_NAME (FAP_LOADER_APP_NAME " Browser") +#define FAP_LOADER_APP_FAVORITE_INDEX FLIPPER_APPS_COUNT typedef struct { InputKey data[MAX_PIN_SIZE]; diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index 94c5ee9f049..09b394559dd 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -44,6 +44,8 @@ void desktop_settings_scene_favorite_on_enter(void* context) { uint32_t primary_favorite = scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite); uint32_t pre_select_item = 0; + FavoriteApp* curr_favorite_app = primary_favorite ? &app->settings.favorite_primary : + &app->settings.favorite_secondary; for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) { submenu_add_item( @@ -53,21 +55,25 @@ void desktop_settings_scene_favorite_on_enter(void* context) { desktop_settings_scene_favorite_submenu_callback, app); - if(primary_favorite) { // Select favorite item in submenu - if((app->settings.favorite_primary.is_external && - !strcmp(FLIPPER_APPS[i].name, FAP_LOADER_APP_NAME)) || - (!strcmp(FLIPPER_APPS[i].name, app->settings.favorite_primary.name_or_path))) { - pre_select_item = i; - } - } else { - if((app->settings.favorite_secondary.is_external && - !strcmp(FLIPPER_APPS[i].name, FAP_LOADER_APP_NAME)) || - (!strcmp(FLIPPER_APPS[i].name, app->settings.favorite_secondary.name_or_path))) { - pre_select_item = i; - } + // Select favorite item in submenu + if((curr_favorite_app->is_external && + !strcmp(FLIPPER_APPS[i].name, FAP_LOADER_APP_NAME)) || + (!strcmp(FLIPPER_APPS[i].name, curr_favorite_app->name_or_path))) { + pre_select_item = i; } } + submenu_add_item( + submenu, + FAP_LOADER_APP_DISPLAY_NAME, + FAP_LOADER_APP_FAVORITE_INDEX, + desktop_settings_scene_favorite_submenu_callback, + app); + if(!curr_favorite_app->is_external && + !strcmp(curr_favorite_app->name_or_path, FAP_LOADER_APP_NAME)) { + pre_select_item = FAP_LOADER_APP_FAVORITE_INDEX; + } + submenu_set_header( submenu, primary_favorite ? "Primary favorite app:" : "Secondary favorite app:"); submenu_set_selected_item(submenu, pre_select_item); // If set during loop, visual glitch. @@ -82,22 +88,17 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e uint32_t primary_favorite = scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite); + FavoriteApp* curr_favorite_app = primary_favorite ? &app->settings.favorite_primary : + &app->settings.favorite_secondary; if(event.type == SceneManagerEventTypeCustom) { - if(strcmp(FLIPPER_APPS[event.event].name, FAP_LOADER_APP_NAME) != 0) { - if(primary_favorite) { - app->settings.favorite_primary.is_external = false; - strncpy( - app->settings.favorite_primary.name_or_path, - FLIPPER_APPS[event.event].name, - MAX_APP_LENGTH); - } else { - app->settings.favorite_secondary.is_external = false; - strncpy( - app->settings.favorite_secondary.name_or_path, - FLIPPER_APPS[event.event].name, - MAX_APP_LENGTH); - } + if(event.event == FAP_LOADER_APP_FAVORITE_INDEX) { + curr_favorite_app->is_external = false; + strncpy(curr_favorite_app->name_or_path, FAP_LOADER_APP_NAME, MAX_APP_LENGTH); + } else if(strcmp(FLIPPER_APPS[event.event].name, FAP_LOADER_APP_NAME) != 0) { + curr_favorite_app->is_external = false; + strncpy( + curr_favorite_app->name_or_path, FLIPPER_APPS[event.event].name, MAX_APP_LENGTH); } else { const DialogsFileBrowserOptions browser_options = { .extension = ".fap", @@ -109,33 +110,18 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e .base_path = EXT_PATH("apps"), }; - if(primary_favorite) { // Select favorite fap in file browser - if(favorite_fap_selector_file_exists( - app->settings.favorite_primary.name_or_path)) { - furi_string_set_str(temp_path, app->settings.favorite_primary.name_or_path); - } - } else { - if(favorite_fap_selector_file_exists( - app->settings.favorite_secondary.name_or_path)) { - furi_string_set_str(temp_path, app->settings.favorite_secondary.name_or_path); - } + // Select favorite fap in file browser + if(favorite_fap_selector_file_exists(curr_favorite_app->name_or_path)) { + furi_string_set_str(temp_path, curr_favorite_app->name_or_path); } submenu_reset(app->submenu); if(dialog_file_browser_show(app->dialogs, temp_path, temp_path, &browser_options)) { - if(primary_favorite) { - app->settings.favorite_primary.is_external = true; - strncpy( - app->settings.favorite_primary.name_or_path, - furi_string_get_cstr(temp_path), - MAX_APP_LENGTH); - } else { - app->settings.favorite_secondary.is_external = true; - strncpy( - app->settings.favorite_secondary.name_or_path, - furi_string_get_cstr(temp_path), - MAX_APP_LENGTH); - } + curr_favorite_app->is_external = true; + strncpy( + curr_favorite_app->name_or_path, + furi_string_get_cstr(temp_path), + MAX_APP_LENGTH); } } scene_manager_previous_scene(app->scene_manager); From 53d4f845f029619422f5dc496dca1a6dd0bdc28b Mon Sep 17 00:00:00 2001 From: Yukai Li Date: Sun, 21 May 2023 18:18:35 -0600 Subject: [PATCH 2/5] desktop: Gate app browser entry add, just in case --- .../desktop_settings/scenes/desktop_settings_scene_favorite.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index 09b394559dd..3df95e57694 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -63,6 +63,7 @@ void desktop_settings_scene_favorite_on_enter(void* context) { } } +#ifdef APP_FAP_LOADER submenu_add_item( submenu, FAP_LOADER_APP_DISPLAY_NAME, @@ -73,6 +74,7 @@ void desktop_settings_scene_favorite_on_enter(void* context) { !strcmp(curr_favorite_app->name_or_path, FAP_LOADER_APP_NAME)) { pre_select_item = FAP_LOADER_APP_FAVORITE_INDEX; } +#endif submenu_set_header( submenu, primary_favorite ? "Primary favorite app:" : "Secondary favorite app:"); From c8edeb84d77218a5379bdfcd006c14898db29a60 Mon Sep 17 00:00:00 2001 From: Aleksandr Kutuzov Date: Fri, 26 May 2023 00:37:32 +0900 Subject: [PATCH 3/5] Desktop: simplify favorite application selection --- .../services/desktop/desktop_settings.h | 3 +-- .../scenes/desktop_settings_scene_favorite.c | 21 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index e07bce0cf42..b17989c2a08 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -37,8 +37,7 @@ #define MAX_APP_LENGTH 128 #define FAP_LOADER_APP_NAME "Applications" -#define FAP_LOADER_APP_DISPLAY_NAME (FAP_LOADER_APP_NAME " Browser") -#define FAP_LOADER_APP_FAVORITE_INDEX FLIPPER_APPS_COUNT +#define FAP_LOADER_APP_DISPLAY_NAME ("[External Application]") typedef struct { InputKey data[MAX_PIN_SIZE]; diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index 3df95e57694..6322b573fbf 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -5,6 +5,8 @@ #include #include +#define FAP_LOADER_APP_FAVORITE_INDEX (FLIPPER_APPS_COUNT + 1) + static bool favorite_fap_selector_item_callback( FuriString* file_path, void* context, @@ -56,9 +58,8 @@ void desktop_settings_scene_favorite_on_enter(void* context) { app); // Select favorite item in submenu - if((curr_favorite_app->is_external && - !strcmp(FLIPPER_APPS[i].name, FAP_LOADER_APP_NAME)) || - (!strcmp(FLIPPER_APPS[i].name, curr_favorite_app->name_or_path))) { + if(!curr_favorite_app->is_external && + !strcmp(FLIPPER_APPS[i].name, curr_favorite_app->name_or_path)) { pre_select_item = i; } } @@ -70,8 +71,7 @@ void desktop_settings_scene_favorite_on_enter(void* context) { FAP_LOADER_APP_FAVORITE_INDEX, desktop_settings_scene_favorite_submenu_callback, app); - if(!curr_favorite_app->is_external && - !strcmp(curr_favorite_app->name_or_path, FAP_LOADER_APP_NAME)) { + if(curr_favorite_app->is_external) { pre_select_item = FAP_LOADER_APP_FAVORITE_INDEX; } #endif @@ -95,13 +95,6 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e if(event.type == SceneManagerEventTypeCustom) { if(event.event == FAP_LOADER_APP_FAVORITE_INDEX) { - curr_favorite_app->is_external = false; - strncpy(curr_favorite_app->name_or_path, FAP_LOADER_APP_NAME, MAX_APP_LENGTH); - } else if(strcmp(FLIPPER_APPS[event.event].name, FAP_LOADER_APP_NAME) != 0) { - curr_favorite_app->is_external = false; - strncpy( - curr_favorite_app->name_or_path, FLIPPER_APPS[event.event].name, MAX_APP_LENGTH); - } else { const DialogsFileBrowserOptions browser_options = { .extension = ".fap", .icon = &I_unknown_10px, @@ -125,6 +118,10 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e furi_string_get_cstr(temp_path), MAX_APP_LENGTH); } + } else { + curr_favorite_app->is_external = false; + strncpy( + curr_favorite_app->name_or_path, FLIPPER_APPS[event.event].name, MAX_APP_LENGTH); } scene_manager_previous_scene(app->scene_manager); consumed = true; From 66829e5288921920241e3281c19c2bcdd82be8d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Kutuzov Date: Fri, 26 May 2023 00:55:57 +0900 Subject: [PATCH 4/5] Desktop: refactor favorite application opening routine and cleanup code --- .../services/desktop/desktop_settings.h | 3 -- .../desktop/scenes/desktop_scene_main.c | 49 +++++++------------ .../scenes/desktop_settings_scene_favorite.c | 11 +++-- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index b17989c2a08..7ab39094d16 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -36,9 +36,6 @@ #define MIN_PIN_SIZE 4 #define MAX_APP_LENGTH 128 -#define FAP_LOADER_APP_NAME "Applications" -#define FAP_LOADER_APP_DISPLAY_NAME ("[External Application]") - typedef struct { InputKey data[MAX_PIN_SIZE]; uint8_t length; diff --git a/applications/services/desktop/scenes/desktop_scene_main.c b/applications/services/desktop/scenes/desktop_scene_main.c index 053ac56f1e7..d19b5560f94 100644 --- a/applications/services/desktop/scenes/desktop_scene_main.c +++ b/applications/services/desktop/scenes/desktop_scene_main.c @@ -16,6 +16,8 @@ #define SNAKE_GAME_APP EXT_PATH("/apps/Games/snake_game.fap") #define CLOCK_APP EXT_PATH("/apps/Tools/clock.fap") +#define FAP_LOADER_APP_NAME "Applications" + static void desktop_scene_main_new_idle_animation_callback(void* context) { furi_assert(context); Desktop* desktop = context; @@ -77,6 +79,21 @@ static void desktop_scene_main_open_app_or_profile(Desktop* desktop, const char* } while(false); } +static void desktop_scene_main_start_favorite(Desktop* desktop, FavoriteApp* application) { + LoaderStatus status = LoaderStatusErrorInternal; + if(application->is_external) { + status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, application->name_or_path); + } else if(strlen(application->name_or_path) > 0) { + status = loader_start(desktop->loader, application->name_or_path, NULL); + } else { + status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, NULL); + } + + if(status != LoaderStatusOk) { + FURI_LOG_E(TAG, "loader_start failed: %d", status); + } +} + void desktop_scene_main_callback(DesktopEvent event, void* context) { Desktop* desktop = (Desktop*)context; if(desktop->in_transition) return; @@ -141,40 +158,12 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { case DesktopMainEventOpenFavoritePrimary: DESKTOP_SETTINGS_LOAD(&desktop->settings); - if(desktop->settings.favorite_primary.is_external) { - LoaderStatus status = loader_start( - desktop->loader, - FAP_LOADER_APP_NAME, - desktop->settings.favorite_primary.name_or_path); - if(status != LoaderStatusOk) { - FURI_LOG_E(TAG, "loader_start failed: %d", status); - } - } else { - LoaderStatus status = loader_start( - desktop->loader, desktop->settings.favorite_primary.name_or_path, NULL); - if(status != LoaderStatusOk) { - FURI_LOG_E(TAG, "loader_start failed: %d", status); - } - } + desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_primary); consumed = true; break; case DesktopMainEventOpenFavoriteSecondary: DESKTOP_SETTINGS_LOAD(&desktop->settings); - if(desktop->settings.favorite_secondary.is_external) { - LoaderStatus status = loader_start( - desktop->loader, - FAP_LOADER_APP_NAME, - desktop->settings.favorite_secondary.name_or_path); - if(status != LoaderStatusOk) { - FURI_LOG_E(TAG, "loader_start failed: %d", status); - } - } else { - LoaderStatus status = loader_start( - desktop->loader, desktop->settings.favorite_secondary.name_or_path, NULL); - if(status != LoaderStatusOk) { - FURI_LOG_E(TAG, "loader_start failed: %d", status); - } - } + desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_secondary); consumed = true; break; case DesktopAnimationEventCheckAnimation: diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index 6322b573fbf..d63d719839c 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -5,7 +5,8 @@ #include #include -#define FAP_LOADER_APP_FAVORITE_INDEX (FLIPPER_APPS_COUNT + 1) +#define EXTERNAL_APPLICATION_NAME ("[External Application]") +#define EXTERNAL_APPLICATION_INDEX (FLIPPER_APPS_COUNT + 1) static bool favorite_fap_selector_item_callback( FuriString* file_path, @@ -67,12 +68,12 @@ void desktop_settings_scene_favorite_on_enter(void* context) { #ifdef APP_FAP_LOADER submenu_add_item( submenu, - FAP_LOADER_APP_DISPLAY_NAME, - FAP_LOADER_APP_FAVORITE_INDEX, + EXTERNAL_APPLICATION_NAME, + EXTERNAL_APPLICATION_INDEX, desktop_settings_scene_favorite_submenu_callback, app); if(curr_favorite_app->is_external) { - pre_select_item = FAP_LOADER_APP_FAVORITE_INDEX; + pre_select_item = EXTERNAL_APPLICATION_INDEX; } #endif @@ -94,7 +95,7 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e &app->settings.favorite_secondary; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == FAP_LOADER_APP_FAVORITE_INDEX) { + if(event.event == EXTERNAL_APPLICATION_INDEX) { const DialogsFileBrowserOptions browser_options = { .extension = ".fap", .icon = &I_unknown_10px, From 6621d915154916ec4f96e0bf696fec5576d96e76 Mon Sep 17 00:00:00 2001 From: Aleksandr Kutuzov Date: Fri, 26 May 2023 01:11:44 +0900 Subject: [PATCH 5/5] Desktop: handle exit from external application selection --- .../scenes/desktop_settings_scene_favorite.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index d63d719839c..4b5c4792123 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -111,20 +111,24 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e furi_string_set_str(temp_path, curr_favorite_app->name_or_path); } - submenu_reset(app->submenu); if(dialog_file_browser_show(app->dialogs, temp_path, temp_path, &browser_options)) { + submenu_reset(app->submenu); // Prevent menu from being shown when we exiting scene curr_favorite_app->is_external = true; strncpy( curr_favorite_app->name_or_path, furi_string_get_cstr(temp_path), MAX_APP_LENGTH); + consumed = true; } } else { curr_favorite_app->is_external = false; strncpy( curr_favorite_app->name_or_path, FLIPPER_APPS[event.event].name, MAX_APP_LENGTH); + consumed = true; } - scene_manager_previous_scene(app->scene_manager); + if(consumed) { + scene_manager_previous_scene(app->scene_manager); + }; consumed = true; }