Desktop favorites: Return none and add lock in dummy

This commit is contained in:
gid9798 2023-08-18 11:23:35 +03:00
parent f73f369952
commit b1b00d4fa7
3 changed files with 56 additions and 10 deletions

View File

@ -65,8 +65,8 @@ static bool one_shot_view_input(InputEvent* event, void* context) {
if(!consumed) {
if(event->key == InputKeyRight) {
/* Right button reserved for animation activation, so consume */
consumed = true;
if(event->type == InputTypeShort) {
consumed = true;
if(view->interact_callback) {
view->interact_callback(view->interact_callback_context);
}

View File

@ -61,11 +61,19 @@ static void
}
#endif
static inline bool desktop_scene_main_check_none(const char* str) {
return (str[1] == '\0' && str[0] == '?');
}
static void desktop_scene_main_open_app_or_profile(Desktop* desktop, FavoriteApp* application) {
bool load_ok = false;
if(strlen(application->name_or_path) > 0) {
if(loader_start(desktop->loader, application->name_or_path, NULL, NULL) ==
LoaderStatusOk) {
if(desktop_scene_main_check_none(application->name_or_path)) {
// skip loading
load_ok = true;
} else if(
loader_start(desktop->loader, application->name_or_path, NULL, NULL) ==
LoaderStatusOk) {
load_ok = true;
}
}
@ -76,7 +84,9 @@ static void desktop_scene_main_open_app_or_profile(Desktop* desktop, FavoriteApp
static void desktop_scene_main_start_favorite(Desktop* desktop, FavoriteApp* application) {
if(strlen(application->name_or_path) > 0) {
loader_start_with_gui_error(desktop->loader, application->name_or_path, NULL);
if(!desktop_scene_main_check_none(application->name_or_path)) {
loader_start_with_gui_error(desktop->loader, application->name_or_path, NULL);
}
} else {
loader_start(desktop->loader, LOADER_APPLICATIONS_NAME, NULL, NULL);
}
@ -207,8 +217,14 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
desktop, &desktop->settings.dummy_apps[DummyAppOk]);
break;
case DesktopDummyEventOpenUpLong:
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.dummy_apps[DummyAppUpLong]);
if(!desktop_scene_main_check_none(
desktop->settings.dummy_apps[DummyAppUpLong].name_or_path)) {
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.dummy_apps[DummyAppUpLong]);
} else {
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock(desktop);
}
break;
case DesktopDummyEventOpenDownLong:
desktop_scene_main_open_app_or_profile(

View File

@ -12,9 +12,15 @@
#define EXTERNAL_BROWSER_NAME ("Apps Menu (Default)")
#define PASSPORT_NAME ("Passport (Default)")
#define EXTERNAL_APPLICATION_INDEX (1)
#define NONE_APPLICATION_INDEX (1)
#define NONE_APPLICATION_NAME "None (disable)"
#define LOCK_APPLICATION_NAME "Lock Flipper"
#define EXTERNAL_APPLICATION_INDEX (2)
#define EXTERNAL_APPLICATION_NAME ("[Select App]")
#define MAIN_LIST_APPLICATION_OFFSET (3)
#define PRESELECTED_SPECIAL 0xffffffff
static const char* favorite_fap_get_app_name(size_t i) {
@ -63,6 +69,7 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
FavoriteApp* curr_favorite_app = NULL;
bool is_dummy_app = false;
bool default_passport = false;
bool lock_if_none = false;
if((favorite_id & SCENE_STATE_SET_DUMMY_APP) == 0) {
furi_assert(favorite_id < FavoriteAppNumber);
@ -76,6 +83,9 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
curr_favorite_app = &app->settings.dummy_apps[favorite_id];
is_dummy_app = true;
default_passport = true;
if(favorite_id == DummyAppUpLong) {
lock_if_none = true;
}
}
// Special case: Application browser
@ -86,6 +96,14 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
desktop_settings_scene_favorite_submenu_callback,
app);
// Special case: None (disable) or Lock Flipper
submenu_add_item(
submenu,
lock_if_none ? (LOCK_APPLICATION_NAME) : (NONE_APPLICATION_NAME),
NONE_APPLICATION_INDEX,
desktop_settings_scene_favorite_submenu_callback,
app);
// Special case: Specific application
submenu_add_item(
submenu,
@ -99,11 +117,15 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
const char* name = favorite_fap_get_app_name(i);
submenu_add_item(
submenu, name, i + 2, desktop_settings_scene_favorite_submenu_callback, app);
submenu,
name,
i + MAIN_LIST_APPLICATION_OFFSET,
desktop_settings_scene_favorite_submenu_callback,
app);
// Select favorite item in submenu
if(!strcmp(name, curr_favorite_app->name_or_path)) {
pre_select_item = i + 2;
pre_select_item = i + MAIN_LIST_APPLICATION_OFFSET;
}
}
}
@ -111,6 +133,10 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
if(pre_select_item == PRESELECTED_SPECIAL) {
if(curr_favorite_app->name_or_path[0] == '\0') {
pre_select_item = DEFAULT_INDEX;
} else if(
(curr_favorite_app->name_or_path[1] == '\0') &&
(curr_favorite_app->name_or_path[0] == '?')) {
pre_select_item = NONE_APPLICATION_INDEX;
} else {
pre_select_item = EXTERNAL_APPLICATION_INDEX;
}
@ -143,6 +169,10 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
if(event.event == DEFAULT_INDEX) {
curr_favorite_app->name_or_path[0] = '\0';
consumed = true;
} else if(event.event == NONE_APPLICATION_INDEX) {
curr_favorite_app->name_or_path[0] = '?';
curr_favorite_app->name_or_path[1] = '\0';
consumed = true;
} else if(event.event == EXTERNAL_APPLICATION_INDEX) {
const DialogsFileBrowserOptions browser_options = {
.extension = ".fap",
@ -168,7 +198,7 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
consumed = true;
}
} else {
size_t app_index = event.event - 2;
size_t app_index = event.event - MAIN_LIST_APPLICATION_OFFSET;
const char* name = favorite_fap_get_app_name(app_index);
if(name) strncpy(curr_favorite_app->name_or_path, name, MAX_APP_LENGTH);
consumed = true;