Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions applications/services/desktop/desktop_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#define MIN_PIN_SIZE 4
#define MAX_APP_LENGTH 128

#define FAP_LOADER_APP_NAME "Applications"

typedef struct {
InputKey data[MAX_PIN_SIZE];
uint8_t length;
Expand Down
49 changes: 19 additions & 30 deletions applications/services/desktop/scenes/desktop_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <dialogs/dialogs.h>
#include <fap_loader/fap_loader_app.h>

#define EXTERNAL_APPLICATION_NAME ("[External Application]")
#define EXTERNAL_APPLICATION_INDEX (FLIPPER_APPS_COUNT + 1)

static bool favorite_fap_selector_item_callback(
FuriString* file_path,
void* context,
Expand Down Expand Up @@ -44,6 +47,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(
Expand All @@ -53,21 +58,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, curr_favorite_app->name_or_path)) {
pre_select_item = i;
}
}

#ifdef APP_FAP_LOADER
submenu_add_item(
submenu,
EXTERNAL_APPLICATION_NAME,
EXTERNAL_APPLICATION_INDEX,
desktop_settings_scene_favorite_submenu_callback,
app);
if(curr_favorite_app->is_external) {
pre_select_item = EXTERNAL_APPLICATION_INDEX;
}
#endif

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.
Expand All @@ -82,23 +91,11 @@ 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);
}
} else {
if(event.event == EXTERNAL_APPLICATION_INDEX) {
const DialogsFileBrowserOptions browser_options = {
.extension = ".fap",
.icon = &I_unknown_10px,
Expand All @@ -109,34 +106,23 @@ 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);
}
} 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;
Expand Down