[FL-3479] Desktop: more favorites, configurable dummy mode (#2972)
* Desktop: more favorite app shortcuts * Making PVS happy * Desktop settings submenu fix Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
#include "../desktop_settings_app.h"
|
||||
#include "applications.h"
|
||||
#include "desktop_settings_scene.h"
|
||||
#include "desktop_settings_scene_i.h"
|
||||
#include <flipper_application/flipper_application.h>
|
||||
#include <storage/storage.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#define APPS_COUNT (FLIPPER_APPS_COUNT + FLIPPER_EXTERNAL_APPS_COUNT)
|
||||
|
||||
#define EXTERNAL_BROWSER_NAME ("Apps")
|
||||
#define EXTERNAL_BROWSER_INDEX (APPS_COUNT + 1)
|
||||
#define DEFAULT_INDEX (0)
|
||||
#define EXTERNAL_BROWSER_NAME ("Apps Menu (Default)")
|
||||
#define PASSPORT_NAME ("Passport (Default)")
|
||||
|
||||
#define EXTERNAL_APPLICATION_INDEX (1)
|
||||
#define EXTERNAL_APPLICATION_NAME ("[Select App]")
|
||||
#define EXTERNAL_APPLICATION_INDEX (APPS_COUNT + 2)
|
||||
|
||||
#define PRESELECTED_SPECIAL 0xffffffff
|
||||
|
||||
@@ -55,28 +57,32 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
|
||||
Submenu* submenu = app->submenu;
|
||||
submenu_reset(submenu);
|
||||
|
||||
uint32_t primary_favorite =
|
||||
uint32_t favorite_id =
|
||||
scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
uint32_t pre_select_item = PRESELECTED_SPECIAL;
|
||||
FavoriteApp* curr_favorite_app = primary_favorite ? &app->settings.favorite_primary :
|
||||
&app->settings.favorite_secondary;
|
||||
FavoriteApp* curr_favorite_app = NULL;
|
||||
bool is_dummy_app = false;
|
||||
bool default_passport = false;
|
||||
|
||||
for(size_t i = 0; i < APPS_COUNT; i++) {
|
||||
const char* name = favorite_fap_get_app_name(i);
|
||||
|
||||
submenu_add_item(submenu, name, i, 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;
|
||||
if((favorite_id & SCENE_STATE_SET_DUMMY_APP) == 0) {
|
||||
furi_assert(favorite_id < FavoriteAppNumber);
|
||||
curr_favorite_app = &app->settings.favorite_apps[favorite_id];
|
||||
if(favorite_id == FavoriteAppRightShort) {
|
||||
default_passport = true;
|
||||
}
|
||||
} else {
|
||||
favorite_id &= ~(SCENE_STATE_SET_DUMMY_APP);
|
||||
furi_assert(favorite_id < DummyAppNumber);
|
||||
curr_favorite_app = &app->settings.dummy_apps[favorite_id];
|
||||
is_dummy_app = true;
|
||||
default_passport = true;
|
||||
}
|
||||
|
||||
// Special case: Application browser
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
EXTERNAL_BROWSER_NAME,
|
||||
EXTERNAL_BROWSER_INDEX,
|
||||
default_passport ? (PASSPORT_NAME) : (EXTERNAL_BROWSER_NAME),
|
||||
DEFAULT_INDEX,
|
||||
desktop_settings_scene_favorite_submenu_callback,
|
||||
app);
|
||||
|
||||
@@ -88,16 +94,29 @@ void desktop_settings_scene_favorite_on_enter(void* context) {
|
||||
desktop_settings_scene_favorite_submenu_callback,
|
||||
app);
|
||||
|
||||
if(!is_dummy_app) {
|
||||
for(size_t i = 0; i < APPS_COUNT; i++) {
|
||||
const char* name = favorite_fap_get_app_name(i);
|
||||
|
||||
submenu_add_item(
|
||||
submenu, name, i + 2, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(pre_select_item == PRESELECTED_SPECIAL) {
|
||||
if(curr_favorite_app->name_or_path[0] == '\0') {
|
||||
pre_select_item = EXTERNAL_BROWSER_INDEX;
|
||||
pre_select_item = DEFAULT_INDEX;
|
||||
} else {
|
||||
pre_select_item = EXTERNAL_APPLICATION_INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
submenu_set_header(
|
||||
submenu, primary_favorite ? "Primary favorite app:" : "Secondary favorite app:");
|
||||
submenu_set_header(submenu, is_dummy_app ? ("Dummy Mode app:") : ("Favorite app:"));
|
||||
submenu_set_selected_item(submenu, pre_select_item); // If set during loop, visual glitch.
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewMenu);
|
||||
@@ -108,13 +127,20 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
|
||||
bool consumed = false;
|
||||
FuriString* temp_path = furi_string_alloc_set_str(EXT_PATH("apps"));
|
||||
|
||||
uint32_t primary_favorite =
|
||||
uint32_t favorite_id =
|
||||
scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
FavoriteApp* curr_favorite_app = primary_favorite ? &app->settings.favorite_primary :
|
||||
&app->settings.favorite_secondary;
|
||||
FavoriteApp* curr_favorite_app = NULL;
|
||||
if((favorite_id & SCENE_STATE_SET_DUMMY_APP) == 0) {
|
||||
furi_assert(favorite_id < FavoriteAppNumber);
|
||||
curr_favorite_app = &app->settings.favorite_apps[favorite_id];
|
||||
} else {
|
||||
favorite_id &= ~(SCENE_STATE_SET_DUMMY_APP);
|
||||
furi_assert(favorite_id < DummyAppNumber);
|
||||
curr_favorite_app = &app->settings.dummy_apps[favorite_id];
|
||||
}
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == EXTERNAL_BROWSER_INDEX) {
|
||||
if(event.event == DEFAULT_INDEX) {
|
||||
curr_favorite_app->name_or_path[0] = '\0';
|
||||
consumed = true;
|
||||
} else if(event.event == EXTERNAL_APPLICATION_INDEX) {
|
||||
@@ -142,7 +168,8 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e
|
||||
consumed = true;
|
||||
}
|
||||
} else {
|
||||
const char* name = favorite_fap_get_app_name(event.event);
|
||||
size_t app_index = event.event - 2;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,3 +5,6 @@
|
||||
|
||||
#define SCENE_STATE_PIN_ERROR_MISMATCH (0)
|
||||
#define SCENE_STATE_PIN_ERROR_WRONG (1)
|
||||
|
||||
#define SCENE_STATE_SET_FAVORITE_APP (0)
|
||||
#define SCENE_STATE_SET_DUMMY_APP (1 << 8)
|
||||
|
||||
@@ -3,15 +3,24 @@
|
||||
|
||||
#include "../desktop_settings_app.h"
|
||||
#include "desktop_settings_scene.h"
|
||||
#include "desktop_settings_scene_i.h"
|
||||
|
||||
#define SCENE_EVENT_SELECT_FAVORITE_PRIMARY 0
|
||||
#define SCENE_EVENT_SELECT_FAVORITE_SECONDARY 1
|
||||
#define SCENE_EVENT_SELECT_PIN_SETUP 2
|
||||
#define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 3
|
||||
#define SCENE_EVENT_SELECT_CLOCK_DISPLAY 4
|
||||
typedef enum {
|
||||
DesktopSettingsPinSetup = 0,
|
||||
DesktopSettingsAutoLockDelay,
|
||||
DesktopSettingsClockDisplay,
|
||||
DesktopSettingsFavoriteLeftShort,
|
||||
DesktopSettingsFavoriteLeftLong,
|
||||
DesktopSettingsFavoriteRightShort,
|
||||
DesktopSettingsFavoriteRightLong,
|
||||
DesktopSettingsDummyLeft,
|
||||
DesktopSettingsDummyRight,
|
||||
DesktopSettingsDummyDown,
|
||||
DesktopSettingsDummyOk,
|
||||
} DesktopSettingsEntry;
|
||||
|
||||
#define AUTO_LOCK_DELAY_COUNT 6
|
||||
const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
||||
static const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
||||
"OFF",
|
||||
"30s",
|
||||
"60s",
|
||||
@@ -19,8 +28,7 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
||||
"5min",
|
||||
"10min",
|
||||
};
|
||||
|
||||
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
|
||||
static const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
|
||||
{0, 30000, 60000, 120000, 300000, 600000};
|
||||
|
||||
#define CLOCK_ENABLE_COUNT 2
|
||||
@@ -59,10 +67,6 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
variable_item_list_add(variable_item_list, "Primary Favorite App", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Secondary Favorite App", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_add(variable_item_list, "PIN Setup", 1, NULL, NULL);
|
||||
|
||||
item = variable_item_list_add(
|
||||
@@ -72,8 +76,6 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
||||
desktop_settings_scene_start_auto_lock_delay_changed,
|
||||
app);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app);
|
||||
value_index = value_index_uint32(
|
||||
app->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
@@ -91,6 +93,19 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, clock_enable_text[value_index]);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Favorite App - Left Short", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Favorite App - Left Long", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Favorite App - Right Short", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Favorite App - Right Long", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Dummy Mode App - Left", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Dummy Mode App - Right", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Dummy Mode App - Down", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Dummy Mode App - Ok", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
|
||||
}
|
||||
|
||||
@@ -100,25 +115,72 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SCENE_EVENT_SELECT_FAVORITE_PRIMARY:
|
||||
scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 1);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
consumed = true;
|
||||
break;
|
||||
case SCENE_EVENT_SELECT_FAVORITE_SECONDARY:
|
||||
scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 0);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
consumed = true;
|
||||
break;
|
||||
case SCENE_EVENT_SELECT_PIN_SETUP:
|
||||
case DesktopSettingsPinSetup:
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinMenu);
|
||||
consumed = true;
|
||||
break;
|
||||
case SCENE_EVENT_SELECT_AUTO_LOCK_DELAY:
|
||||
case SCENE_EVENT_SELECT_CLOCK_DISPLAY:
|
||||
consumed = true;
|
||||
|
||||
case DesktopSettingsFavoriteLeftShort:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_FAVORITE_APP | FavoriteAppLeftShort);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsFavoriteLeftLong:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_FAVORITE_APP | FavoriteAppLeftLong);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsFavoriteRightShort:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_FAVORITE_APP | FavoriteAppRightShort);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsFavoriteRightLong:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_FAVORITE_APP | FavoriteAppRightLong);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
|
||||
case DesktopSettingsDummyLeft:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_DUMMY_APP | DummyAppLeft);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsDummyRight:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_DUMMY_APP | DummyAppRight);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsDummyDown:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_DUMMY_APP | DummyAppDown);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
case DesktopSettingsDummyOk:
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
DesktopSettingsAppSceneFavorite,
|
||||
SCENE_STATE_SET_DUMMY_APP | DummyAppOk);
|
||||
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user